From: syzbot <syzbot+8debf4b3f7c7391cd8eb@syzkaller.appspotmail.com>
To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Forwarded: [PATCH] hpfs: add array bounds validation in hpfs_bplus_lookup
Date: Fri, 16 Jan 2026 21:05:18 -0800 [thread overview]
Message-ID: <696b188e.a70a0220.34546f.00a5.GAE@google.com> (raw)
In-Reply-To: <696aa7da.a70a0220.31956c.001a.GAE@google.com>
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] hpfs: add array bounds validation in hpfs_bplus_lookup
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
When traversing a corrupted HPFS filesystem, the n_used_nodes field in
the btree header can contain a value larger than what fits in the
allocated buffer. This causes out-of-bounds array access when iterating
through btree->u.internal[] or btree->u.external[] arrays, leading to
a KASAN-detected use-after-free.
Validate that n_used_nodes does not exceed the maximum number of nodes
that can fit in the buffer before accessing the arrays.
Reported-by: syzbot+8debf4b3f7c7391cd8eb@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=8debf4b3f7c7391cd8eb
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
fs/hpfs/anode.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/fs/hpfs/anode.c b/fs/hpfs/anode.c
index a4f5321eafae..6e1b43f5c9cf 100644
--- a/fs/hpfs/anode.c
+++ b/fs/hpfs/anode.c
@@ -21,6 +22,31 @@ secno hpfs_bplus_lookup(struct super_block *s, struct inode *inode,
int c1, c2 = 0;
go_down:
if (hpfs_sb(s)->sb_chk) if (hpfs_stop_cycles(s, a, &c1, &c2, "hpfs_bplus_lookup")) return -1;
+
+ if (bp_internal(btree)) {
+ unsigned int max_internal_nodes;
+
+ max_internal_nodes = (bh->b_size - ((char *)btree->u.internal - (char *)bh->b_data))
+ / sizeof(btree->u.internal[0]);
+ if (btree->n_used_nodes > max_internal_nodes) {
+ hpfs_error(s, "btree->n_used_nodes = %u, but max for internal node is %u",
+ btree->n_used_nodes, max_internal_nodes);
+ brelse(bh);
+ return -1;
+ }
+ } else {
+ unsigned int max_external_nodes;
+
+ max_external_nodes = (bh->b_size - ((char *)btree->u.external - (char *)bh->b_data))
+ / sizeof(btree->u.external[0]);
+ if (btree->n_used_nodes > max_external_nodes) {
+ hpfs_error(s, "btree->n_used_nodes = %u, but max for external node is %u",
+ btree->n_used_nodes, max_external_nodes);
+ brelse(bh);
+ return -1;
+ }
+ }
+
if (bp_internal(btree)) {
for (i = 0; i < btree->n_used_nodes; i++)
if (le32_to_cpu(btree->u.internal[i].file_secno) > sec) {
--
2.43.0
next prev parent reply other threads:[~2026-01-17 5:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-16 21:04 [syzbot] [xfs?] KASAN: use-after-free Read in hpfs_bplus_lookup syzbot
2026-01-17 2:32 ` Forwarded: [PATCH] hpfs: add buffer bounds validation " syzbot
2026-01-17 3:45 ` syzbot
2026-01-17 4:38 ` Forwarded: [PATCH] hpfs: add debug logging to hpfs_bplus_lookup syzbot
2026-01-17 5:05 ` syzbot [this message]
2026-01-19 6:36 ` [syzbot] [xfs?] KASAN: use-after-free Read in hpfs_bplus_lookup Christoph Hellwig
2026-01-19 8:35 ` Aleksandr Nogikh
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=696b188e.a70a0220.34546f.00a5.GAE@google.com \
--to=syzbot+8debf4b3f7c7391cd8eb@syzkaller.appspotmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=syzkaller-bugs@googlegroups.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