From: "Cen Zhang (Microsoft Security FORGE Labs)" <cenzhang@linux.microsoft.com>
To: viro@zeniv.linux.org.uk, brauner@kernel.org
Cc: jack@suse.cz, jkoolstra@xs4all.nl, neil@brown.name,
sandeen@redhat.com, kees@kernel.org,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, AutonomousCodeSecurity@microsoft.com,
xmei5@asu.edu, tgopinath@linux.microsoft.com, kys@microsoft.com,
"Cen Zhang (Microsoft Security FORGE Labs)"
<cenzhang@linux.microsoft.com>
Subject: [PATCH] ufs: validate cylinder group free bitmap offset
Date: Tue, 1 Sep 2026 14:06:00 -0400 [thread overview]
Message-ID: <20260901180600.10394-1-cenzhang@linux.microsoft.com> (raw)
ufs_read_cylinder() copies cg_freeoff from the on-disk cylinder group
without checking that the free-fragment bitmap fits in the loaded
cylinder group buffers. A crafted image can place cg_freeoff past those
buffers so that allocation later indexes ubh->bh[] out of range.
UBSAN: array-index-out-of-bounds in fs/ufs/balloc.c:752:15
ubh_scanc() fs/ufs/balloc.c:752
ufs_bitmap_search() fs/ufs/balloc.c
ufs_alloccg_block() fs/ufs/balloc.c
ufs_alloc_fragments() fs/ufs/balloc.c
ufs_new_fragments() fs/ufs/balloc.c
Reject the cylinder group unless the full BITS_TO_BYTES(s_fpg)
free-fragment bitmap starting at c_freeoff fits in the bytes actually
loaded for that cylinder group.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: Xiang Mei (Microsoft) <xmei5@asu.edu>
Cc: AutonomousCodeSecurity@microsoft.com
Cc: stable@vger.kernel.org
Signed-off-by: Cen Zhang (Microsoft Security FORGE Labs) <cenzhang@linux.microsoft.com>
---
fs/ufs/cylinder.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/fs/ufs/cylinder.c b/fs/ufs/cylinder.c
index a2813270c303..fec6c9dfb055 100644
--- a/fs/ufs/cylinder.c
+++ b/fs/ufs/cylinder.c
@@ -33,6 +33,8 @@ static bool ufs_read_cylinder(struct super_block *sb,
struct ufs_sb_private_info * uspi;
struct ufs_cg_private_info * ucpi;
struct ufs_cylinder_group * ucg;
+ u64 cg_bytes, free_bitmap_bytes;
+ const char *err;
unsigned i, j;
UFSD("ENTER, cgno %u, bitmap_nr %u\n", cgno, bitmap_nr);
@@ -48,8 +50,10 @@ static bool ufs_read_cylinder(struct super_block *sb,
UCPI_UBH(ucpi)->bh[0] = sbi->s_ucg[cgno];
for (i = 1; i < UCPI_UBH(ucpi)->count; i++) {
UCPI_UBH(ucpi)->bh[i] = sb_bread(sb, UCPI_UBH(ucpi)->fragment + i);
- if (!UCPI_UBH(ucpi)->bh[i])
+ if (!UCPI_UBH(ucpi)->bh[i]) {
+ err = "can't read cylinder group block %u";
goto failed;
+ }
}
sbi->s_cgno[bitmap_nr] = cgno;
@@ -68,6 +72,16 @@ static bool ufs_read_cylinder(struct super_block *sb,
ucpi->c_clustersumoff = fs32_to_cpu(sb, ucg->cg_u.cg_44.cg_clustersumoff);
ucpi->c_clusteroff = fs32_to_cpu(sb, ucg->cg_u.cg_44.cg_clusteroff);
ucpi->c_nclusterblks = fs32_to_cpu(sb, ucg->cg_u.cg_44.cg_nclusterblks);
+
+ cg_bytes = UCPI_UBH(ucpi)->count * sb->s_blocksize;
+ free_bitmap_bytes = BITS_TO_BYTES((u64)uspi->s_fpg);
+ /* The full free bitmap must fit in the loaded CG buffer. */
+ if (!free_bitmap_bytes ||
+ (u64)ucpi->c_freeoff + free_bitmap_bytes > cg_bytes) {
+ err = "cylinder group %u has invalid free bitmap";
+ goto failed;
+ }
+
UFSD("EXIT\n");
return true;
@@ -75,7 +89,7 @@ static bool ufs_read_cylinder(struct super_block *sb,
for (j = 1; j < i; j++)
brelse(UCPI_UBH(ucpi)->bh[j]);
sbi->s_cgno[bitmap_nr] = UFS_CGNO_EMPTY;
- ufs_error (sb, "ufs_read_cylinder", "can't read cylinder group block %u", cgno);
+ ufs_error(sb, "ufs_read_cylinder", err, cgno);
return false;
}
base-commit: 786262be6048deab760f68c8acc2c85607165894
--
2.55.0
next reply other threads:[~2026-09-01 18:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 18:06 Cen Zhang (Microsoft Security FORGE Labs) [this message]
2026-09-02 5:53 ` Greg KH
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=20260901180600.10394-1-cenzhang@linux.microsoft.com \
--to=cenzhang@linux.microsoft.com \
--cc=AutonomousCodeSecurity@microsoft.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=jkoolstra@xs4all.nl \
--cc=kees@kernel.org \
--cc=kys@microsoft.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=neil@brown.name \
--cc=sandeen@redhat.com \
--cc=stable@vger.kernel.org \
--cc=tgopinath@linux.microsoft.com \
--cc=viro@zeniv.linux.org.uk \
--cc=xmei5@asu.edu \
/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®