From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=162.62.58.216 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796272534; b=f5FaX07O1gxugyoAELuG4/8KGEOz86WdPiVpz7C40G09857q7fpmK2qHECmizBnzN0IZ mKXhg+iWJA3VJiZUYCaE4BoO4+uGivV4XKvZ5/dZsE1lAzG89XNVDAFlQ/zkE7jl5RbdV 965t9w3O3QoWTpMCs76rcpYmvchXjtR6Q54VO7s+Iq/mfnoL+Pq2CAAC/FkM8Bk0Ahv5S fmEF68mQ1JEZ8TRA4QFUTsUpX/UKcLPN53FVXFtAuGVhCiwFgVCP29mcVYmKv4PJ0RBSj ET/+TdcJgRX/0z/WjsZILw5+cKdWK4/eMHJZ7PxpWxrZr7QLlu9D09eIyvscRjccTJQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796272534; h=DMARC-Filter:DKIM-Signature:Received:X-QQ-mid:Message-ID: X-QQ-XMAILINFO:X-QQ-XMRINFO:From:To:Cc:Subject:Date:X-OQ-MSGID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=tRgs5HsJ/d7Un6arFQQPbXp3KfG4C6Rk6Mmxv1QFBcg=; b=dw9B6cyNEjfPr+kiiGu2QoqmzV3YOno8ht9o4/FD3zue4fTwHOWSySG+DykpTKXvDBlv QXvc9q7PePZj7LFYnxwbIp8c+3MHbKhY6S8xRow9M7Y4AyhNT9T20h4Y3Fu4eHw0OZkQ2 3ZSWExRY7gevWz9xQX0WVPY9mDMr2cKLeY5RLFWdhJJaCrVUAEMIa57L3JyBikwKzmgZa xhA6ZjgJKhQxIAhbsIiUVfw/7cQq33GU6xVDLUJu8lYHBnwE6wvZwIVYCLImLyuBg/0yB PnCNFLnkYy3Gjx2cEv0+S81WWNRrRNmAy6KligbWHjvXOCohXocmIssyFQYK65WqmPw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=qq.com; spf=pass smtp.mailfrom=qq.com; dkim=pass header.d=qq.com header.i=@qq.com header.a=rsa-sha256 header.s=s201512 header.b=Gl4suUhQ; arc=none smtp.remote-ip=162.62.58.216 Received: from out162-62-58-216.mail.qq.com (out162-62-58-216.mail.qq.com [162.62.58.216]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8ACB7606A322 for ; Thu, 3 Dec 2026 04:35:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8ACB7606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=qq.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qq.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.a=rsa-sha256 header.s=s201512 header.b=Gl4suUhQ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1796272528; bh=tRgs5HsJ/d7Un6arFQQPbXp3KfG4C6Rk6Mmxv1QFBcg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Gl4suUhQtPJtXuvVipE1qP3oaXHHgiaOzmMo1j98i0D7jnCwaV1TzLTx5cCe70ebD AiOM1vXH8ud5yvMv0Oett+XCM9Bu+7cwWKMrBwt7Hnc/4T7bReTupt/UMif8S+GLtN q2xxDWkRBuPFw25r613DOlwUeRcC8mfAhVVyEzqE= Received: from shuai-VMware-Virtual-Platform.. ([39.165.245.102]) by newxmesmtplogicsvrsza73-0.qq.com (NewEsmtp) with SMTP id 8DA3B8D8; Thu, 03 Dec 2026 12:35:26 +0800 X-QQ-mid: xmsmtpt1796272526tj0f2yda5 Message-ID: X-QQ-XMAILINFO: NxF5De9alh3HU8uQt57ON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4wAsZUNtoO/guT5S6VqMH/vQcPvQeezlMlemCPTGAGl6b64UnC lsUh9+RpAlLlQSu+0= X-QQ-XMRINFO: OWPUhxQsoeAVwkVaQIEGSKwwgKCxK/fD5g== 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 X-OQ-MSGID: <20261203043525.231440-1-847807867@qq.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <6ac3be67.34119e79.2f92f3.0035.GAE@google.com> References: <6ac3be67.34119e79.2f92f3.0035.GAE@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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