]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
ntfs: fix NULL dereference in ntfs_index_walk_down()
authorDaeMyung Kang <charsyam@gmail.com>
Sun, 26 Apr 2026 04:02:31 +0000 (13:02 +0900)
committerNamjae Jeon <linkinjeon@kernel.org>
Mon, 27 Apr 2026 13:29:04 +0000 (22:29 +0900)
commitb5198fcdc195fa531adff7bbfbe40dd27c8d0e89
tree16b87138cb339a36b3ccfa8ab95b19af0a5d7294
parent897d54018cc9aa97fd1529ca08a53b429d05a566
ntfs: fix NULL dereference in ntfs_index_walk_down()

ntfs_index_walk_down() allocates ictx->ib when descending from the root
into an index allocation block. If that allocation fails, the old code
still passes the NULL buffer to ntfs_ib_read(), which can write through
it via ntfs_inode_attr_pread().

Allocate the index block into a temporary pointer and return -ENOMEM
before changing the index context on allocation failure. Also propagate
ERR_PTR() through ntfs_index_next() and ntfs_readdir() so walk-down
allocation or index block read failures are not mistaken for normal
index iteration inside the filesystem.

ntfs_readdir() keeps the existing userspace-visible behavior of
suppressing readdir errors after marking end_in_iterate; this change only
prevents the walk-down failure path from dereferencing NULL internally.

The failure was reproduced with failslab fail-nth injection on getdents64;
the original module hits a NULL pointer dereference in memcpy_orig through
ntfs_ib_read(), while the patched module reaches the same
ntfs_index_walk_down() allocation failure without crashing.

Fixes: 0a8ac0c1fa0b ("ntfs: update directory operations")
Signed-off-by: DaeMyung Kang <charsyam@gmail.com>
Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
fs/ntfs/dir.c
fs/ntfs/index.c