From: Shuai Liu <847807867@qq.com>
To: shaggy@kernel.org
Cc: jfs-discussion@lists.sourceforge.net,
linux-kernel@vger.kernel.org,
syzbot+a2748ba908c108e7e525@syzkaller.appspotmail.com,
yogeshgaur.83@gmail.com, Shuai Liu <847807867@qq.com>
Subject: [PATCH] jfs: fix out-of-bounds write in jfs_readdir() with multibyte names
Date: Thu, 3 Dec 2026 12:35:25 +0800 [thread overview]
Message-ID: <tencent_B79ADDB1A5FD58D6E4639B9A7185C4EE2609@qq.com> (raw)
In-Reply-To: <6ac3be67.34119e79.2f92f3.0035.GAE@google.com>
jfs_readdir() converts each on-disk UTF-16 name into a struct jfs_dirent
in a PAGE_SIZE buffer and only fills the next entry when it believes it
fits:
if (((long) jfs_dirent + d->namlen + 1) >
((long)dirent_buf + PAGE_SIZE)) {
The check undercounts twice. The name is written at jfs_dirent->name,
past the 14-byte header, not at jfs_dirent. And d->namlen counts UTF-16
units, while jfs_strfromUCS_le() lets codepage->uni2char() emit up to
NLS_MAX_CHARSET_SIZE bytes per unit; with iocharset=utf8 a non-ASCII
unit takes two or three bytes. An entry that passes the check can thus
be written past the end of the buffer, which KASAN reports as a
slab-out-of-bounds write in utf32_to_utf8():
BUG: KASAN: slab-out-of-bounds in utf32_to_utf8+0x24d/0x3d0 fs/nls/nls_base.c:111
Write of size 1 at addr ffff888039ad7000 by task syz-executor304/5946
utf32_to_utf8+0x24d/0x3d0 fs/nls/nls_base.c:111
uni2char+0x35/0xa0 fs/nls/nls_utf8.c:21
jfs_strfromUCS_le+0xd2/0x3d0 fs/jfs/jfs_unicode.c:31
jfs_readdir+0x16fd/0x33f0 fs/jfs/jfs_dtree.c:2984
The buggy address is located 0 bytes to the right of
allocated 4096-byte region
Check against the worst case instead: the name starts at
jfs_dirent->name and each unit can take NLS_MAX_CHARSET_SIZE bytes.
The largest entry is 255 * NLS_MAX_CHARSET_SIZE +
sizeof(struct jfs_dirent) bytes, so an empty buffer always takes at
least one entry and readdir keeps making progress.
Two fixes for this bug were posted
(https://lore.kernel.org/all/20261006072656.11800-1-kartikey406@gmail.com/
and
https://lore.kernel.org/all/20261006124112.1703-1-yogeshgaur.83@gmail.com/)
but received no maintainer response in over two months and the bug is
still reproducing. The buffer-fit check follows Yogesh's patch, which
anchors the bound at jfs_dirent->name.
Verified with the syzbot C reproducer under QEMU with KASAN: the
unpatched kernel reports slab-out-of-bounds in utf32_to_utf8 via
jfs_readdir(), the patched kernel runs the same reproducer cleanly
(two runs, no KASAN/Oops/WARNING).
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: syzbot+a2748ba908c108e7e525@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=a2748ba908c108e7e525
Suggested-by: Yogesh Gaur <yogeshgaur.83@gmail.com>
Signed-off-by: Shuai Liu <847807867@qq.com>
---
fs/jfs/jfs_dtree.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/jfs/jfs_dtree.c b/fs/jfs/jfs_dtree.c
index 8ce6e4458cc25..7de2faf33ff99 100644
--- a/fs/jfs/jfs_dtree.c
+++ b/fs/jfs/jfs_dtree.c
@@ -2910,9 +2910,9 @@ int jfs_readdir(struct file *file, struct dir_context *ctx)
d = (struct ldtentry *) & p->slot[stbl[i]];
- if (((long) jfs_dirent + d->namlen + 1) >
- ((long)dirent_buf + PAGE_SIZE)) {
- /* DBCS codepages could overrun dirent_buf */
+ if ((long)jfs_dirent->name +
+ d->namlen * NLS_MAX_CHARSET_SIZE + 1 >
+ (long)dirent_buf + PAGE_SIZE) {
index = i;
overflow = 1;
break;
--
2.43.0
prev parent reply other threads:[~2026-12-03 4:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-05 15:12 [syzbot] KASAN: slab-out-of-bounds Write in utf32_to_utf8 syzbot
2026-10-06 5:53 ` Forwarded: [PATCH] jfs: fix slab-out-of-bounds write in jfs_readdir() with multibyte names syzbot
2026-10-07 15:42 ` Forwarded: KASAN: slab-out-of-bounds Write in utf32_to_utf8 syzbot
2026-10-07 18:06 ` syzbot
2026-12-03 4:35 ` Shuai Liu [this message]
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=tencent_B79ADDB1A5FD58D6E4639B9A7185C4EE2609@qq.com \
--to=847807867@qq.com \
--cc=jfs-discussion@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=shaggy@kernel.org \
--cc=syzbot+a2748ba908c108e7e525@syzkaller.appspotmail.com \
--cc=yogeshgaur.83@gmail.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
all inboxes | Powered by JetHome®