[PATCH] fs/ntfs3: reject undersized log replay buffers
From: Shawn Shao
Date: Tue Dec 01 2026 - 09:18:42 EST
Hello,
During $LogFile replay, do_action() derives the read buffer length for an
ATTR_ALLOC operation from the redo payload or the logged cluster range. A
crafted UpdateNonresidentValue record can make both the redo length and
bytes_per_index zero while the cluster range equals the cluster offset. The
computed length is then zero; kmalloc(0) returns ZERO_SIZE_PTR, which passes
the NULL check, and the following four-byte probe of buffer_le faults at
address 0x10 during a read-write mount.
The patch rejects underflowing or unrepresentable fallback lengths and
addition/alignment overflow. It also rejects an ATTR_ALLOC buffer smaller
than the four-byte value read by the existing probe, marking the volume
dirty and skipping that replay action through the existing dirty_vol path.
The reproducer uses a crafted NTFS image and mounts it with the in-tree
ntfs3 driver. Two independent non-KASAN baseline runs fault at the
ZERO_SIZE_PTR load. A redo_len=8 control and an unmodified image
mount without fault. The fixed-kernel positive image is also included in
the verification; the malformed action is rejected and the kernel does not
fault.
The issue requires a crafted filesystem image and a read-write mount. The
mount operation requires CAP_SYS_ADMIN; I do not claim an unprivileged
user-namespace trigger, information disclosure, memory corruption, or
privilege escalation. The demonstrated impact is a kernel denial of
service when a privileged service mounts an attacker-controlled NTFS image.
HEAD commit: 7cd8495c0f16275c4f9abe1cef09a7b5fcd6d046
git tree: 194227446ae61b4971eea1b7bed06856fe3cc477
source version: v7.3-23903-g7cd8495c0f162 (Linux 7.4.0-rc4)
compiler: gcc 11.4.0, GNU ld 2.38
The Gist contains the image-log builder and verifier, mount PoC, kernel
configuration, baseline/control/fixed console output, patch, and full build
and QEMU instructions:
https://gist.githubusercontent.com/shaos26/59408b516b6301d431564110ee2b2711/raw/9127b8fb0a888b9ddf50f7facd40bc5cb71ac368/poc.c
https://gist.githubusercontent.com/shaos26/59408b516b6301d431564110ee2b2711/raw/9127b8fb0a888b9ddf50f7facd40bc5cb71ac368/craft_log.py
https://gist.githubusercontent.com/shaos26/59408b516b6301d431564110ee2b2711/raw/9127b8fb0a888b9ddf50f7facd40bc5cb71ac368/verify_log.py
https://gist.githubusercontent.com/shaos26/59408b516b6301d431564110ee2b2711/raw/9127b8fb0a888b9ddf50f7facd40bc5cb71ac368/kernel-config.txt
https://gist.githubusercontent.com/shaos26/59408b516b6301d431564110ee2b2711/raw/9127b8fb0a888b9ddf50f7facd40bc5cb71ac368/console-output.txt
https://gist.githubusercontent.com/shaos26/59408b516b6301d431564110ee2b2711/raw/9127b8fb0a888b9ddf50f7facd40bc5cb71ac368/fix.patch
https://gist.githubusercontent.com/shaos26/59408b516b6301d431564110ee2b2711/raw/9127b8fb0a888b9ddf50f7facd40bc5cb71ac368/repro.md
Fixes: b46acd6a6a62 ("fs/ntfs3: Add NTFS journal")
Signed-off-by: Shawn Shao <shawnq1@xxxxxxx>
Thanks,
Shawn Shao
---
fs/ntfs3/fslog.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c
index bb8d40bb58696..69ad03b40ade8 100644
--- a/fs/ntfs3/fslog.c
+++ b/fs/ntfs3/fslog.c
@@ -3262,12 +3262,22 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
bytes = t32;
}
- if (!bytes)
+ if (!bytes) {
+ if (lco < cbo || lco - cbo > U32_MAX)
+ goto dirty_vol;
bytes = lco - cbo;
+ }
+ if (bytes > U32_MAX - roff)
+ goto dirty_vol;
bytes += roff;
- if (attr->type == ATTR_ALLOC)
- bytes = (bytes + 511) & ~511; // align
+ if (attr->type == ATTR_ALLOC) {
+ if (bytes > U32_MAX - 511)
+ goto dirty_vol;
+ bytes = (bytes + 511) & ~511;
+ if (bytes < sizeof(u32))
+ goto dirty_vol;
+ }
buffer_le = kmalloc(bytes, GFP_NOFS);
if (!buffer_le)
--
2.43.0