From: Joas Antonio dos Santos via B4 Relay <devnull+joasantonio108.gmail.com@kernel.org>
To: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>,
joasantonio108@gmail.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] ntfs3: reject on-disk c_unit values that cause shift overflow
Date: Sun, 08 Nov 2026 18:07:13 +0000 [thread overview]
Message-ID: <20261108-ntfs3-cunit-fix-v1-1-fb8d02b3f8a2@gmail.com> (raw)
From: Joas Antonio dos Santos <joasantonio108@gmail.com>
The c_unit field of non-resident NTFS attributes controls frame size
via shift expressions like 1u << c_unit throughout attrib.c. This
field is read directly from the on-disk MFT record without bounds
validation for extended (compressed/sparse) attributes.
When c_unit >= 32, the expression 1u << c_unit is undefined behavior
for 32-bit integers. On x86, the shift count is masked to 5 bits,
producing wrong frame alignment (e.g., c_unit=32 yields 1u << 0 = 1
instead of 2^32). On strict-alignment architectures this may trap.
The affected expressions in attrib.c include:
- 1u << attr_b->nres.c_unit (lines 1168, 1732)
- align <<= attr_b->nres.c_unit (line 501)
- sbi->cluster_size << attr_b->nres.c_unit (lines 2089, 2401, 2617)
Add a bounds check in mi_enum_attr() to reject attributes with
c_unit > 31, which covers all downstream users. The existing
validation in frecord.c (checking c_unit == NTFS_LZNT_CUNIT) only
covers explicit compression read/write paths, not the attrib.c
block mapping, truncate, fallocate, and punch_hole paths.
A crafted NTFS image with c_unit=32 triggers the UB on mount when
any compressed file is accessed.
Found by LLM-assisted manual code review.
Fixes: be71b5cba2e6 ("fs/ntfs3: Add attrib operations")
Signed-off-by: Joas Antonio dos Santos <joasantonio108@gmail.com>
---
fs/ntfs3/record.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c
index d7785f9e8..5344958ef 100644
--- a/fs/ntfs3/record.c
+++ b/fs/ntfs3/record.c
@@ -366,6 +366,9 @@ struct ATTRIB *mi_enum_attr(struct ntfs_inode *ni, struct mft_inode *mi,
if (tot_size > alloc_size)
goto out;
+
+ if (attr->nres.c_unit > 31)
+ goto out;
} else {
if (attr->nres.c_unit)
goto out;
---
base-commit: 05441d697f7f9a927264f4058cbbc6a03dfcac9d
change-id: 20261108-ntfs3-cunit-fix-f1c127013b75
Best regards,
--
Joas Antonio dos Santos <joasantonio108@gmail.com>
reply other threads:[~2026-11-08 18:07 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=20261108-ntfs3-cunit-fix-v1-1-fb8d02b3f8a2@gmail.com \
--to=devnull+joasantonio108.gmail.com@kernel.org \
--cc=almaz.alexandrovich@paragon-software.com \
--cc=joasantonio108@gmail.com \
--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®