[PATCH] fs/ntfs3: check fnd_push() return value
From: shaos
Date: Sat Nov 28 2026 - 03:28:56 EST
Hello,
indx_get_entry_to_replace() ignores the return value of fnd_push().
fnd_push() returns -EINVAL when the search path reaches the capacity of
fnd->nodes, without taking ownership of the node passed to it.
A crafted NTFS index can make the replacement search follow a self-
referential VCN. Once the path is full, each iteration allocates another
index node, fails to add it to fnd, and leaks it. The unlink operation
then spins in the loop while kmalloc-4k usage grows continuously.
The existing NULL check for hdr_first_de() does not handle this case. A
related check in indx_find() from commit 1732053c8a6b ("fs: ntfs3: check
return value of indx_find to avoid infinite loop") covers a different
traversal. The unlink path through indx_get_entry_to_replace() still
ignores the fnd_push() result.
The reproducer requires a privileged writable mount of a crafted NTFS
image. It demonstrates a CPU-consuming hang and a continuously growing
kernel memory leak; it does not demonstrate privilege escalation.
Tested source revision:
HEAD commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
git tree: fe970b05333fb8e41da21e9e289f652abcc7cba7
source version: Linux 7.4.0-rc4
compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0,
GNU ld 2.38
console output:
https://gist.githubusercontent.com/shaos26/6527bc7b947fae21f2ff589d7725c451/raw/d7f2cde89b263e212053d7913002432466d8db34/console-output.txt
kernel config:
https://gist.githubusercontent.com/shaos26/6527bc7b947fae21f2ff589d7725c451/raw/c81a372534f86268589d2efee757cb035d5ba38a/kernel-config.txt
reproducer:
https://gist.githubusercontent.com/shaos26/6527bc7b947fae21f2ff589d7725c451/raw/cdb9e24d2f6aeac681926cef142f1634eb6fef2d/poc.c
image setup helper:
https://gist.githubusercontent.com/shaos26/6527bc7b947fae21f2ff589d7725c451/raw/0e7a810823bb17c6a2dda9e9fda5563fb3c30183/setup.c
index image mutator:
https://gist.githubusercontent.com/shaos26/6527bc7b947fae21f2ff589d7725c451/raw/fbe29e409a7507eecae2c7270558c81b3b0da6b6/ntfs_selfvcn_patch.py
patched-kernel config:
https://gist.githubusercontent.com/shaos26/6527bc7b947fae21f2ff589d7725c451/raw/d204ab19c4a8824c83293b94741f80cc0fa52b0a/patched-kernel-config.txt
Create an NTFS image, compile setup.c, and boot it as /init in a minimal
initramfs with the image attached as /dev/vda:
truncate -s 256M ntfs.img
mkntfs -F -Q ntfs.img
gcc -O2 -Wall -Wextra -static -o setup setup.c
mkdir -p setup-root
cp setup setup-root/init
chmod 0755 setup-root/init
(cd setup-root && find . -print0 | cpio --null -o -H newc) |
gzip -9 > setup-initramfs.cpio.gz
qemu-system-x86_64 -m 2G -smp 2 \
-kernel <linux-tree>/arch/x86/boot/bzImage \
-initrd setup-initramfs.cpio.gz \
-drive file=ntfs.img,format=raw,if=virtio \
-append 'console=ttyS0 rdinit=/init panic=-1 loglevel=6' \
-nographic -monitor none -no-reboot
The setup helper creates /tree/file_0 through /tree/file_599 and powers
off. Copy the resulting image and make the self-VCN mutation:
cp ntfs.img trigger.img
python3 ntfs_selfvcn_patch.py trigger.img --patch \
--out trigger.img --target-file target.txt
Build poc.c statically, place it at /init in a new initramfs, and place
target.txt at /target in that archive:
gcc -O2 -Wall -Wextra -static -o poc poc.c
mkdir -p poc-root
cp poc poc-root/init
cp target.txt poc-root/target
chmod 0755 poc-root/init
(cd poc-root && find . -print0 | cpio --null -o -H newc) |
gzip -9 > poc-initramfs.cpio.gz
Boot the mutated trigger image as /dev/vda with:
qemu-system-x86_64 -m 2G -smp 2 \
-kernel <linux-tree>/arch/x86/boot/bzImage \
-initrd poc-initramfs.cpio.gz \
-drive file=trigger.img,format=raw,if=virtio \
-append 'console=ttyS0 rdinit=/init panic=-1 loglevel=6' \
-nographic -monitor none -no-reboot
Two vulnerable runs remained in the unlink loop after SIGKILL. In one
run, kmalloc-4k grew by 270800 objects after one second and by 356140
after the signal. With this patch, unlink returned -EINVAL in 36 ms,
the target remained present, and kmalloc-4k grew by 24 objects. The
sibling and partial-VCN controls completed normally.
Check the fnd_push() result and release the current node if the search
path cannot accept it. fnd_clear() then releases nodes already on the
path:
Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")
Signed-off-by: shaos <shawnq1@xxxxxxx>
---
fs/ntfs3/index.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c
index c06b367604487..151b71d4ddd94 100644
--- a/fs/ntfs3/index.c
+++ b/fs/ntfs3/index.c
@@ -2303,7 +2303,11 @@ static int indx_get_entry_to_replace(struct ntfs_index *indx,
goto out;
e = hdr_first_de(&n->index->ihdr);
- fnd_push(fnd, n, e);
+ err = fnd_push(fnd, n, e);
+ if (err) {
+ put_indx_node(n);
+ goto out;
+ }
if (!e) {
err = -EINVAL;
goto out;
--
2.34.1
Thanks,
shaos