From: David Lee <david.lee@trailofbits.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: David Lee <david.lee@trailofbits.com>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
Kees Cook <kees@kernel.org>,
linux-fsdevel@vger.kernel.org,
Dominik 'Disconnect3d' Czarnota
<dominik.czarnota@trailofbits.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH] ufs: reject oversized cylinder group metadata
Date: Fri, 17 Jul 2026 10:40:32 +0000 [thread overview]
Message-ID: <20260717104033.38574-1-david.lee@trailofbits.com> (raw)
The on-disk cylinder group size becomes the fragment count used by
ufs_read_cylinder(). A size larger than one filesystem block makes that
count exceed UFS_MAXFRAG and drives buffer-head stores beyond the fixed
eight-entry array in struct ufs_cg_private_info.
Reject zero-sized cylinder groups and sizes larger than the validated
filesystem block size while reading the superblock. Since a filesystem
block contains at most UFS_MAXFRAG fragments, every later cylinder cache
count is then bounded by its buffer-head array.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Assisted-by: Codex:gpt-5.5
Signed-off-by: David Lee <david.lee@trailofbits.com>
---
fs/ufs/super.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/ufs/super.c b/fs/ufs/super.c
index c4831a8b9b3f..fa2effdec7b0 100644
--- a/fs/ufs/super.c
+++ b/fs/ufs/super.c
@@ -1140,6 +1140,11 @@ static int ufs_fill_super(struct super_block *sb, struct fs_context *fc)
uspi->s_cssize = fs32_to_cpu(sb, usb1->fs_cssize);
uspi->s_cgsize = fs32_to_cpu(sb, usb1->fs_cgsize);
+ if (uspi->s_cgsize == 0 || uspi->s_cgsize > uspi->s_bsize) {
+ pr_err("%s(): invalid cylinder group size %u\n",
+ __func__, uspi->s_cgsize);
+ goto failed;
+ }
uspi->s_ntrak = fs32_to_cpu(sb, usb1->fs_ntrak);
uspi->s_nsect = fs32_to_cpu(sb, usb1->fs_nsect);
uspi->s_spc = fs32_to_cpu(sb, usb1->fs_spc);
--
2.43.0
reply other threads:[~2026-07-17 10:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260717104033.38574-1-david.lee@trailofbits.com \
--to=david.lee@trailofbits.com \
--cc=brauner@kernel.org \
--cc=dominik.czarnota@trailofbits.com \
--cc=jack@suse.cz \
--cc=kees@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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