Skip to content

Commit

Permalink
reiserfs: Check the return value from __getblk()
Browse files Browse the repository at this point in the history
[ Upstream commit ba38980 ]

__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.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Link: https://lore.kernel.org/lkml/CAFcO6XOacq3hscbXevPQP7sXRoYFz34ZdKPYjmd6k5sZuhGFDw@mail.gmail.com/
Tested-by: butt3rflyh4ck <butterflyhuangxx@gmail.com>
Fixes: 1da177e ("Linux-2.6.12-rc2") # probably introduced in 2002
Acked-by: Edward Shishkin <edward.shishkin@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Matthew Wilcox authored and gregkh committed Sep 13, 2023
1 parent 0c7e6ff commit 9720f89
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion fs/reiserfs/journal.c
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit 9720f89

Please sign in to comment.