Re: [syzbot] [bfs?] general protection fault in bfs_get_block (3)

From: Edward Adam Davis
Date: Sun Nov 03 2024 - 00:43:00 EST


add a check for new bh

#syz test

diff --git a/fs/bfs/file.c b/fs/bfs/file.c
index fa66a09e496a..10287a1a5846 100644
--- a/fs/bfs/file.c
+++ b/fs/bfs/file.c
@@ -40,6 +40,11 @@ static int bfs_move_block(unsigned long from, unsigned long to,
if (!bh)
return -EIO;
new = sb_getblk(sb, to);
+ if (!new) {
+ bforget(bh);
+ return -ENOMEM;
+ }
+
memcpy(new->b_data, bh->b_data, bh->b_size);
mark_buffer_dirty(new);
bforget(bh);