From: kovalev@altlinux.org
To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
aivazian.tigran@gmail.com, stable@vger.kernel.org
Cc: lvc-patches@linuxtesting.org, dutyrok@altlinux.org,
kovalev@altlinux.org,
syzbot+d98fd19acd08b36ff422@syzkaller.appspotmail.com
Subject: [PATCH v3 1/2] bfs: prevent null pointer dereference in bfs_move_block()
Date: Thu, 22 Aug 2024 19:12:18 +0300 [thread overview]
Message-ID: <20240822161219.459054-2-kovalev@altlinux.org> (raw)
In-Reply-To: <20240822161219.459054-1-kovalev@altlinux.org>
From: Vasiliy Kovalev <kovalev@altlinux.org>
Detect a failed sb_getblk() call (before copying data)
so that null pointer dereferences should not happen any more.
We also decrement (brelse) the bh counter in this case.
Found when launching the reproducer generated by Syzkaller:
KASAN: null-ptr-deref in range [0x0000000000000028-0x000000000000002f]
Comm: mark_buffer_dir Tainted: G W 6.1.105-un-def-alt1.kasan #1
RIP: 0010:bfs_get_block+0x35b/0xdf0 (fs/bfs/file.c:42) [bfs]
Call Trace:
<TASK>
__die_body.cold (arch/x86/kernel/dumpstack.c:478)
die_addr (arch/x86/kernel/dumpstack.c:462)
exc_general_protection (arch/x86/kernel/traps.c:787)
asm_exc_general_protection (./arch/x86/include/asm/idtentry.h:564)
__getblk_gfp (fs/buffer.c:1335)
bfs_get_block (fs/bfs/file.c:42) bfs
bfs_get_block (fs/bfs/file.c:56) bfs
bfs_get_block (fs/bfs/file.c:125) bfs
bfs_write_begin (fs/bfs/file.c:66) bfs
__block_write_begin_int (fs/buffer.c:1991)
bfs_write_begin (fs/bfs/file.c:66) bfs
invalidate_bh_lrus_cpu (fs/buffer.c:1955)
fault_in_readable (mm/gup.c:1898)
PageHeadHuge (mm/hugetlb.c:2123)
bfs_write_begin (fs/bfs/file.c:66) bfs
block_write_begin (fs/buffer.c:2103)
bfs_write_begin (fs/bfs/file.c:178) bfs
generic_perform_write (mm/filemap.c:3817)
generic_file_readonly_mmap (mm/filemap.c:3781)
new_inode (fs/inode.c:2126)
generic_write_checks (fs/read_write.c:1687)
__generic_file_write_iter (mm/filemap.c:3946)
generic_file_write_iter (./include/linux/fs.h:763 mm/filemap.c:3978)
vfs_write (./include/linux/fs.h:2265 fs/read_write.c:491)
kernel_write (fs/read_write.c:565)
__fget_files (fs/file.c:918)
ksys_write (fs/read_write.c:638)
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: syzbot+d98fd19acd08b36ff422@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?extid=d98fd19acd08b36ff422
Link: https://syzkaller.appspot.com/text?tag=ReproC&x=16515ba3e80000
Cc: stable@vger.kernel.org
Signed-off-by: Vasiliy Kovalev <kovalev@altlinux.org>
---
fs/bfs/file.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/bfs/file.c b/fs/bfs/file.c
index 57ae5ee6deec12..23773e62994024 100644
--- a/fs/bfs/file.c
+++ b/fs/bfs/file.c
@@ -39,6 +39,10 @@ static int bfs_move_block(unsigned long from, unsigned long to,
if (!bh)
return -EIO;
new = sb_getblk(sb, to);
+ if (!new) {
+ brelse(bh);
+ return -EIO;
+ }
memcpy(new->b_data, bh->b_data, bh->b_size);
mark_buffer_dirty(new);
bforget(bh);
--
2.33.8
next prev parent reply other threads:[~2024-08-22 16:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-22 16:12 [PATCH v3 0/2] bfs: fix null-ptr-deref and possible warning in bfs_move_block() func kovalev
2024-08-22 16:12 ` kovalev [this message]
2024-08-22 16:12 ` [PATCH v3 2/2] bfs: ensure buffer is marked uptodate before marking it dirty kovalev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240822161219.459054-2-kovalev@altlinux.org \
--to=kovalev@altlinux.org \
--cc=aivazian.tigran@gmail.com \
--cc=dutyrok@altlinux.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lvc-patches@linuxtesting.org \
--cc=stable@vger.kernel.org \
--cc=syzbot+d98fd19acd08b36ff422@syzkaller.appspotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox