Skip to contentSkip to conversation

reiserfs: Check the return value from __getblk()

PATCH Applied Matthew Wilcox (Oracle) 3 participants 6 messages Jun 5, 2023 – Jul 5, 2023 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 reiserfs: Check the return value from __getblk()

__getblk() can return a NULL pointer if we run out of memory or if we try to access beyond the end of the device; check it and handle it appropriately.

---
 fs/reiserfs/journal.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/reiserfs/journal.c +3 -1
index 4d11d60f493c..dd58e0dca5e5 100644
@@ -2326,7 +2326,7 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev,
 	int i, j;
 
 	bh = __getblk(dev, block, bufsize);
-	if (buffer_uptodate(bh))
+	if (!bh || buffer_uptodate(bh))
 		return (bh);
 
 	if (block + BUFNR > max_block) {
@@ -2336,6 +2336,8 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev,
 	j = 1;
 	for (i = 1; i < blocks; i++) {
 		bh = __getblk(dev, block + i, bufsize);
+		if (!bh)
+			break;
 		if (buffer_uptodate(bh)) {
 			brelse(bh);
 			break;
Signature · 1 line
2.39.2
Acked-by on v1 1/1
#1 lore raw
Quoted 26 lines · Matthew Wilcox (Oracle)

__getblk() can return a NULL pointer if we run out of memory or if we try to access beyond the end of the device; check it and handle it appropriately.

---
  fs/reiserfs/journal.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
fs/reiserfs/journal.c +1 -1
index 4d11d60f493c..dd58e0dca5e5 100644
@@ -2326,7 +2326,7 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev,
  	int i, j;
 
  	bh = __getblk(dev, block, bufsize);
-	if (buffer_uptodate(bh))
+	if (!bh || buffer_uptodate(bh))
  		return (bh);
 
  	if (block + BUFNR > max_block) {

fs/reiserfs/journal.c static struct buffer_head *reiserfs_breada(struct block_device *dev, · line 2343

Quoted 8 lines
fs/reiserfs/journal.c +2 -0
@@ -2336,6 +2336,8 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev,
  	j = 1;
  	for (i = 1; i < blocks; i++) {
  		bh = __getblk(dev, block + i, bufsize);
+		if (!bh)
+			break;
  		if (buffer_uptodate(bh)) {
  			brelse(bh);
  			break;
#2 lore raw
In reply to Matthew Wilcox (Oracle)

I was expecting Jan to pick this one up, but it's not in his pull request that just got merged. Looking at patches to reiserfs over the last few cycles, patches go in a few different ways; there doesn't seem to be a defined path. Anyone want to take this one?

Quoted 37 lines · Matthew Wilcox (Oracle)

__getblk() can return a NULL pointer if we run out of memory or if we try to access beyond the end of the device; check it and handle it appropriately.

---
 fs/reiserfs/journal.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/reiserfs/journal.c +3 -1
index 4d11d60f493c..dd58e0dca5e5 100644
@@ -2326,7 +2326,7 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev,
 	int i, j;
 
 	bh = __getblk(dev, block, bufsize);
-	if (buffer_uptodate(bh))
+	if (!bh || buffer_uptodate(bh))
 		return (bh);
 
 	if (block + BUFNR > max_block) {
@@ -2336,6 +2336,8 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev,
 	j = 1;
 	for (i = 1; i < blocks; i++) {
 		bh = __getblk(dev, block + i, bufsize);
+		if (!bh)
+			break;
 		if (buffer_uptodate(bh)) {
 			brelse(bh);
 			break;
Signature · 1 line
2.39.2
maintainer Applied
#3 lore raw

From: Matthew Wilcox <[email protected]>

Quoted 5 lines · Matthew Wilcox

__getblk() can return a NULL pointer if we run out of memory or if we try to access beyond the end of the device; check it and handle it appropriately.

[...]

Willy's original commit with message id <[email protected]> didn't show up on lore. Might be because reiserfs-devel isn't a list tracked by lore; not sure. So I grabbed this from somewhere else.

In any case, I picked this up now.

---

Applied to the vfs.misc branch of the vfs/vfs.git tree. Patches in the vfs.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.misc

[1/1] reiserfs: Check the return value from __getblk()

      commit: https://git.kernel.org/vfs/vfs/c/958c5fee0047
author Acked-by Edward Shishkin
#4 lore raw
Quoted 18 lines · Christian Brauner

From: Matthew Wilcox <[email protected]>

Quoted 5 lines · Matthew Wilcox

__getblk() can return a NULL pointer if we run out of memory or if we try to access beyond the end of the device; check it and handle it appropriately.

[...]

Willy's original commit with message id <[email protected]> didn't show up on lore. Might be because reiserfs-devel isn't a list tracked by lore; not sure. So I grabbed this from somewhere else.

In any case, I picked this up now.

---

Quoted 8 lines

Applied to the vfs.misc branch of the vfs/vfs.git tree. Patches in the vfs.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

was added in a response to the original, FYI

#5 lore raw
Quoted 25 lines · Matthew Wilcox
Quoted 24 lines · Christian Brauner

From: Matthew Wilcox <[email protected]>

Quoted 5 lines · Matthew Wilcox

__getblk() can return a NULL pointer if we run out of memory or if we try to access beyond the end of the device; check it and handle it appropriately.

[...]

Willy's original commit with message id <[email protected]> didn't show up on lore. Might be because reiserfs-devel isn't a list tracked by lore; not sure. So I grabbed this from somewhere else.

In any case, I picked this up now.

---

Applied to the vfs.misc branch of the vfs/vfs.git tree. Patches in the vfs.misc branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

Quoted 6 lines
Quoted 2 lines

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

was added in a response to the original, FYI

Thank you! I've updated the patch trailer accordingly.