From: Guikun Yang <yangguikun19@qq.com>
To: Christian Brauner <brauner@kernel.org>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] ufs: bound the cluster summary index in ufs_clusteracct()
Date: Wed, 18 Nov 2026 16:00:00 +0800 [thread overview]
Message-ID: <tencent_ABAAD2B7E6C8BB138AE97AD4BF0F49145F06@qq.com> (raw)
In-Reply-To: <patch-ufs-contigsumsize-20261118@qq.com>
Resending with the Signed-off-by line added; the diff is unchanged.
fs_contigsumsize is read from the on-disk superblock into
uspi->s_contigsumsize with no validation, and c_clustersumoff is read
from each cylinder-group header with no validation. In
ufs_clusteracct() the two combine into a derived array index:
i = back + forw + 1;
if (i > uspi->s_contigsumsize)
i = uspi->s_contigsumsize;
fs32_add(sb, ubh_get_addr(UCPI_UBH(ucpi),
ucpi->c_clustersumoff + (i << 2)), cnt);
The clamp itself uses the attacker-controlled value as its bound.
ubh_get_addr() expands to ubh->bh[begin >> s_fshift], so a crafted
pair indexes bh[UFS_MAXFRAG] past the end of the 136-byte
ufs_cg_private_info allocation:
UBSAN: array-index-out-of-bounds in fs/ufs/balloc.c:892
index 15 is out of range for type 'buffer_head *[8]'
KASAN: slab-out-of-bounds Read of size 8
0 bytes to the right of 136-byte region
Kernel panic - not syncing
Reproduced 3/3 with a crafted 44bsd image (clustersumoff = 440,
fs_contigsumsize = 0x20000, giving i = 1880 and begin = 7960, so
begin >> s_fshift = 15). A negative image differing only in the
fs_contigsumsize byte (0x20000 -> 0) writes 4096 bytes cleanly.
Both 7.3 and mainline are affected; syzbot has no report for this.
This is distinct from the earlier "five unvalidated cylinder-group
offsets" report: that fix bounds the offsets against s_cgsize and the
reproducer set fs_contigsumsize to 0, disabling cluster accounting.
Here all five offsets are in range, cgsize passes the bound added by
the fs_cgsize fix, and the overflow comes from the (i << 2) derived
index with a large s_contigsumsize.
In a valid FFS layout the cluster summary array sits immediately
before the cluster bitmap, so c_clustersumoff + 4*(i+1) must fit below
c_clusteroff. Check that invariant before the update and skip the
accounting otherwise.
Reported-by: Guikun Yang <yangguikun19@qq.com>
Signed-off-by: Guikun Yang <yangguikun19@qq.com>
---
fs/ufs/balloc.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/ufs/balloc.c b/fs/ufs/balloc.c
index 628edfde3..3858699db 100644
--- a/fs/ufs/balloc.c
+++ b/fs/ufs/balloc.c
@@ -889,6 +889,9 @@ static void ufs_clusteracct(struct super_block * sb,
i = back + forw + 1;
if (i > uspi->s_contigsumsize)
i = uspi->s_contigsumsize;
+ if (ucpi->c_clusteroff < (i + 1) * sizeof(__fs32) ||
+ ucpi->c_clusteroff - (i + 1) * sizeof(__fs32) < ucpi->c_clustersumoff)
+ return;
fs32_add(sb, (__fs32*)ubh_get_addr(UCPI_UBH(ucpi), ucpi->c_clustersumoff + (i << 2)), cnt);
if (back > 0)
fs32_sub(sb, (__fs32*)ubh_get_addr(UCPI_UBH(ucpi), ucpi->c_clustersumoff + (back << 2)), cnt);
--
2.53.0.windows.1
parent reply other threads:[~2026-11-18 7:44 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <patch-ufs-contigsumsize-20261118@qq.com>]
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_ABAAD2B7E6C8BB138AE97AD4BF0F49145F06@qq.com \
--to=yangguikun19@qq.com \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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®