summaryrefslogtreecommitdiff
path: root/fs/ntfs3
AgeCommit message (Collapse)Author
12 daysMerge tag 'vfs-7.4-rc3.fixes' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs Pull vfs fixes from Christian Brauner: - libfs: Make readdir on tmpfs walk the offset tree in offset order instead of d_children to avoid skipping entries or relisting the whole directory It's faster too. Listing a million entries takes 114ms instead of 146ms, and 113ms instead of 470ms with four processes listing in parallel - iomap: Finish the ->iomap_next() conversion that started in v7.3 The nilfs2 and fuse ext_map iomap code added this merge window is converted so now we can remove the ->iomap_begin()/->iomap_end() fallback. We waited until the new iomap users from other trees were in mainline otherwise this would have been very messy - errseq: Retry with the current value when the cmpxchg() in errseq_check_and_advance() fails to avoid an old value coming back later hiding the errors - aio: Hold an extra count for exit_aio() itself so it can't return before the last free_ioctx_reqs() callback has called complete() - pidfd: Fail the namespace ioctls with EREMOTE unless the target is visible in the caller's pid namespace like PIDFD_GET_INFO does - eventpoll: Wake the next waiter when a woken waiter returns early because of a fatal signal to avoid sleeping forever - backing-file: Pass RWF_NOAPPEND on to synchronous writes to the backing file - initrd: Flush the deferred fput() of the ramdisk file before mounting root - iov_iter: Take an unsigned long segment count in import_iovec() The upper 32 bits of the count passed to readv(), writev() and friends were dropped before the UIO_MAXIOV check - splice: Advance the pipe tail before checking for a full bvec array in splice_to_socket(). The last buffer was counted again, so MSG_MORE was set although the pipe was empty and small TCP transfers waited for the cork timeout - vfs: - Reject negative offsets for SEEK_DATA and SEEK_HOLE in default_llseek() and use must_set_pos() for its whence handling - Only clear tv_nsec in timestamp_truncate() when clamping changed the seconds. Timestamps whose seconds were exactly at a filesystem time limit lost their subsecond part - Don't leak the kernel-internal STATX_ATTR_CHANGE_MONOTONIC in stx_attributes_mask - Clamp the FIONREAD result to the int range so a file with 4 GiB left isn't reported as empty - Fix the SEEK_CUR f_lock check - selftests: Fix the statmount and mount_setattr tests on 32-bit and s390, build the fchmodat2 and openat2 tests without sanitizers when the toolchain lacks the runtimes and fix a clang warning in the mount-notify test - docs: Fix a docutils warning in porting.rst * tag 'vfs-7.4-rc3.fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: (28 commits) fs: fix the SEEK_CUR f_lock condition splice, net: avoid MSG_MORE when the bvec array fills aio: don't let exit_aio() return before complete() is done fs: porting.rst: use literal string to avoid warning selftests/fs/mount-notify: fix the indentation in the fsmount test selftests: probe for sanitizer support in fchmodat2 and openat2 selftests/mount_setattr: build with a 64-bit off_t selftests/statmount: fix format warnings on 32-bit and s390 fs: use must_set_pos() in default_llseek() fs: reject negative offsets for SEEK_DATA and SEEK_HOLE in default_llseek() pidfd: restrict task access ioctls to the caller's pid namespace fs: clamp FIONREAD result to int range eventpoll: wake the next waiter when a woken waiter is killed statx: don't leak STATX_ATTR_CHANGE_MONOTONIC in stx_attributes_mask vfs: preserve subsecond timestamps at filesystem time limits iov_iter: take an unsigned long segment count in import_iovec() lib/tests: errseq: add a concurrent check_and_advance test errseq: don't let errseq_check_and_advance() hide later errors backing-file: pass RWF_NOAPPEND to synchronous writes initrd: flush deferred fput() before mounting root ...
2026-11-05treewide: refresh kmalloc_obj() conversionsKees Cook
Refresh the tree with run of the existing Coccinelle rules in scripts/coccinelle/api/kmalloc_objs.cocci, now that they also convert arrays of multi-byte integers. The conversions break down as: 435 kzalloc_objs() 169 kmalloc_objs() 52 kvzalloc_objs() 47 kzalloc_obj() 42 kvmalloc_objs() 8 kmalloc_obj() 2 kzalloc_flex() 2 kvmalloc_flex() and 37 existing kmalloc_obj() family calls drop a redundant GFP_KERNEL. Build tested with allmodconfig on x86_64 with GCC 16.2.0, and, together with the devm_kmalloc_obj() conversion that follows, on x86_64, arm64, i386, arm, riscv, s390, m68k, mips, parisc, sparc, loongarch, arc, xtensa, and openrisc with GCC 16.2.0 with no new warnings. Signed-off-by: Kees Cook <kees+treewide@kernel.org>
2026-11-05iomap: pass iomap_iter_next_fn directly instead of struct iomap_opsJoanne Koong
Now that all filesystems implement ->iomap_next() and the legacy ->iomap_begin()/->iomap_end() fallback is gone, struct iomap_ops only wraps a single iomap_next function pointer. Drop the struct entirely and pass the iomap_iter_next_fn directly to iomap_iter() and all the iomap/dax entry points. Filesystems pass their iomap_iter_next_fn callback directly instead of an ops struct. Several iomap_iter_next_fn callbacks become non-static and gain header declarations since callers now reference them directly. The iomap_iter tracepoint's ops field is renamed to next to match. These tracepoints are explicitly not stable ABI (see the note in iomap/trace.h). No functional change intended other than the tracepoint field rename noted above. Acked-by: Jan Kara <jack@suse.cz> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Joanne Koong <joannelkoong@gmail.com> Link: https://patch.msgid.link/20261027215326.2693300-5-joannelkoong@gmail.com Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-10-29Merge tag 'ntfs3_for_7.4' of ↵Linus Torvalds
https://github.com/Paragon-Software-Group/linux-ntfs3 Pull ntfs3 updates from Konstantin Komarov: "The bulk of this cycle is hardening against corrupted or maliciously crafted volumes. Most of these fixes come from fuzzing and KASAN reports. The main areas are: - $LogFile replay, where several unchecked on-disk sizes could make mount write past the MFT record buffer - MFT record and index parsing - extended attributes, where a bad $EA entry could leak up to 64K of kernel heap to userspace through getxattr() Reading a damaged compressed file could also return uninitialized page cache contents to userspace; that is fixed too. A few fixes affect healthy volumes as well: a heap overflow in fallocate(INSERT_RANGE) on small files, a use-after-free when a WOF-compressed file is opened for writing during a concurrent read, a lock-order deadlock in readdir, and stale disk data showing up in newly allocated clusters of compressed files. On the feature side there are new tracepoints covering mount, log replay, lookup, directory index, allocation, iomap and file I/O. There is also a new 'ugm' mount option (on by default): with ugm=0, newly created files don't get the WSL uid/gid/mode extended attributes, which Windows doesn't use. The rest is smaller correctness fixes and cleanups" * tag 'ntfs3_for_7.4' of https://github.com/Paragon-Software-Group/linux-ntfs3: (52 commits) ntfs3: add file I/O tracepoints ntfs3: add iomap tracepoints ntfs3: add allocation tracepoints ntfs3: add directory index tracepoints ntfs3: add create inode tracepoint ntfs3: add namei tracepoints ntfs3: add mount and log replay tracepoints fs/ntfs3: validate the EA value length in ntfs_read_ea() fs/ntfs3: handle partial allocation in attr_data_get_block_locked() ntfs3: fix mapping pairs bounds check for alignment fs/ntfs3: bound DeleteAttribute asize against rec->used in do_action ntfs3: release ni_lock before dir_emit in ntfs_readdir to fix deadlocks fs/ntfs3: bound CreateAttribute asize against record_size in do_action fs/ntfs3: do not mark frame pages uptodate on read error fs/ntfs3: prevent positive E_NTFS_NONRESIDENT from reaching writeback error handling fs/ntfs3: fix ntfs_fnd leak when compare function is missing fs/ntfs3: fix stale attr_b in attr_allocate_frame() fs/ntfs3: reject unaligned hole punching on compressed files fs/ntfs3: take ni_lock() once in ntfs_readdir() fs/ntfs3: reserve a compression unit in maxbytes_sparse ...
2026-10-28ntfs3: add file I/O tracepointsBaolin Liu
Add ntfs3 tracepoints for file I/O operations. This adds trace events for ntfs_file_read_iter() and ntfs_file_write_iter() to help observe file read and write activity. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-28ntfs3: add iomap tracepointsBaolin Liu
Add ntfs3 tracepoints for iomap operations. This adds trace events for ntfs_iomap_begin() and ntfs_iomap_end() to help observe iomap mapping activity. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-28ntfs3: add allocation tracepointsBaolin Liu
Add ntfs3 tracepoints for allocation operations. This adds trace events for attr_allocate_clusters(), attr_set_size_ex(), and attr_data_get_block() to help observe cluster allocation, size changes, and block mapping activity. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-28ntfs3: add directory index tracepointsBaolin Liu
Add ntfs3 tracepoints for directory index operations. This adds trace events for dir_search_u(), indx_find(), indx_insert_entry(), and indx_delete_entry() to help observe directory index lookup, insert, and delete activity. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-28ntfs3: add create inode tracepointBaolin Liu
Add an ntfs3 tracepoint for inode creation. This adds a trace event for ntfs_create_inode() to help observe inode creation activity. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-28ntfs3: add namei tracepointsBaolin Liu
Add ntfs3 tracepoints for namei operations. This adds trace events for ntfs_lookup() and ntfs_rename() to help observe directory lookup and rename activity. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-28ntfs3: add mount and log replay tracepointsBaolin Liu
Add ntfs3 tracepoints for mount and log replay paths. This adds trace events for ntfs_fill_super(), ntfs_init_from_boot(), and log_replay() to help observe mount setup, boot sector parsing, and $LogFile replay results. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-28fs/ntfs3: validate the EA value length in ntfs_read_ea()Yuejie Shi
ntfs_read_ea() checks the $EA list for consistency, but it only recomputes the packed size of an entry when the entry's own size field is zero: for (off = 0; off < size; off += ea_size) { const struct EA_FULL *ef = Add2Ptr(ea_p, off); u32 bytes = size - off; ... if (ef->size) { ea_size = le32_to_cpu(ef->size); if (ea_size > bytes) goto out1; continue; /* <- elength never checked */ } ... ea_size = ALIGN(struct_size(ef, name, 1 + ef->name_len + le16_to_cpu(ef->elength)), 4); if (ea_size > bytes) goto out1; } ef->size is non-zero for every entry except the last one, and it is what ntfs3 itself writes (ntfs_set_ea() stores exactly that aligned packed size), so in practice elength is not validated at all. find_ea() then uses unpacked_ea_size(), which also prefers ea->size when it is set, so it agrees and hands the entry back. ntfs_get_ea() copies elength bytes with no further bound of its own: len = le16_to_cpu(ea->elength); ... if (len > size) { /* size is the *caller's* buffer */ err = -ERANGE; ... } memcpy(buffer, ea->name + ea->name_len + 1, len); so a caller that supplies a large enough buffer receives up to 64 KiB of whatever follows the small $EA allocation -- straight to userspace via getxattr(2). Compute the packed size unconditionally and require it to fit in the entry. Hoist the "bytes < offsetof(struct EA_FULL, name)" test above the ef->size branch as well: name_len and elength were being read there without it, which is itself a small over-read of the kmalloc'd buffer when fewer than 8 bytes are left. The old "bytes < sizeof(ef->size)" test is subsumed by it. # mkntfs image; create /mnt/ntfs/poc with user.ntfs6 set, then rewrite # that EA_FULL's elength from 0xf to 0xff00 on the raw device mount -t ntfs3 -o ro /dev/vda /mnt/ntfs getxattr("/mnt/ntfs/poc", "user.ntfs6", buf, 128 * 1024); BUG: KASAN: slab-out-of-bounds in ntfs_get_ea+0x294/0x3e0 Read of size 65280 at addr ffff0000cca53acf by task xattr_probe/142 __asan_memcpy+0x3c/0xa0 ntfs_get_ea+0x294/0x3e0 ntfs_getxattr+0x284/0x318 __vfs_getxattr+0x104/0x160 vfs_getxattr+0x1b4/0x1e0 do_getxattr+0xcc/0x230 path_getxattrat+0x184/0x270 __arm64_sys_getxattr+0x64/0x80 Allocated by task 142: __kmalloc_noprof+0x294/0x668 ntfs_read_ea+0x1e4/0x420 ntfs_get_ea+0x2c8/0x3e0 The buggy address belongs to the object at ffff0000cca53a80 which belongs to the cache kmalloc-96 of size 96 The object being over-read is the one ntfs_read_ea() just allocated, and it is 96 bytes. Entries written by ntfs3 and by Windows set size to the aligned packed size, so the new test does not reject anything a working filesystem produces. Fixes: be71b5cba2e6 ("fs/ntfs3: Add attrib operations") Cc: stable@vger.kernel.org Signed-off-by: Yuejie Shi <syjcnss@gmail.com> [almaz.alexandrovich@paragon-software.com: applied as-is, logic is the same but the code is cleaner] Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-28fs/ntfs3: handle partial allocation in attr_data_get_block_locked()Slawomir Stepien
When allocating clusters for a sparse or compressed attribute in attr_data_get_block_locked(), the requested virtual cluster number (vcn0) is aligned down to a frame boundary (vcn). The function then attempts to allocate a full frame of clusters. If the disk is nearly full and highly fragmented, attr_allocate_clusters() might only manage to allocate a small fragment and return success with a partial allocation length. If this partial allocation is so small that it does not even reach the originally requested vcn0 (i.e., end <= vcn0), vcn0 remains unallocated (a sparse hole). When the code subsequently calls run_lookup_entry() for vcn0, it finds the original SPARSE_LCN entry, which triggers a WARN_ON(1). Fix this by adding a check to verify if the partial allocation reached vcn0. If it did not (vcn0 >= end), treat this as an -ENOSPC failure and jump to the undo1 label. This safely rolls back the partial allocation, restores the original size, and repacks the runs, leaving the inode in a consistent state before returning the error to the caller. WARNING: fs/ntfs3/attrib.c:1236 at attr_data_get_block_locked+0x1980/0x25d0 fs/ntfs3/attrib.c:1236 RIP: 0010:attr_data_get_block_locked+0x1980/0x25d0 fs/ntfs3/attrib.c:1236 Call Trace: <TASK> attr_data_get_block+0x1f1/0x2a0 fs/ntfs3/attrib.c:979 ntfs_fallocate+0xd3d/0xf70 fs/ntfs3/file.c:670 vfs_fallocate+0x663/0x7f0 fs/open.c:338 ksys_fallocate fs/open.c:362 [inline] __do_sys_fallocate fs/open.c:367 [inline] __se_sys_fallocate fs/open.c:365 [inline] __x64_sys_fallocate+0xbf/0x110 fs/open.c:365 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x174/0x580 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK> Fixes: 099ef9ab9203 ("fs/ntfs3: implement iomap-based file operations") Assisted-by: Gemini:gemini-3.1-pro-preview Gemini:gemini-3-flash-preview syzbot Reported-by: syzbot+7be6ad5cb228286af3e3@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=7be6ad5cb228286af3e3 Link: https://syzkaller.appspot.com/ai_job?id=3c9dee6e-001d-4972-8bf6-f6c960708246 Signed-off-by: Slawomir Stepien <sst@poczta.fm> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-28ntfs3: fix mapping pairs bounds check for alignmentHongling Zeng
In the UpdateMappingPairs action, the expansion check compares the unaligned new attribute size with the available record space. The new size is aligned to an 8-byte boundary before the mapping pairs are updated, so the check can underestimate the required space by up to seven bytes. Use the aligned size in the expansion check to ensure that the subsequent update cannot exceed the available record space. Fixes: b46acd6a6a62 ("fs/ntfs3: Add NTFS journal") Cc: stable@vger.kernel.org Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-28fs/ntfs3: bound DeleteAttribute asize against rec->used in do_actionHyeontae Lee
In do_action()'s DeleteAttribute case (fslog.c:3316), attr is Add2Ptr(rec, roff) with roff taken from the on-disk lrh->record_off, and asize = le32_to_cpu(attr->size) is read straight out of the MFT record: asize = le32_to_cpu(attr->size); used = le32_to_cpu(rec->used); if (!check_if_attr(rec, lrh)) goto dirty_vol; ... memmove(attr, Add2Ptr(attr, asize), used - asize - roff); check_if_attr() (fslog.c:2869) walks the attribute chain from rec->attr_off and returns o == ro. Its loop breaks on ATTR_END, so ro may legitimately equal the offset of the ATTR_END marker; that is exactly how CreateAttribute appends to a record. But check_file_record()'s walk (fslog.c:2831) also stops at ATTR_END, so check_attr() never inspects the bytes there. When roff is the ATTR_END offset, those never-validated bytes are what gets read as attr->size, and used - asize - roff underflows. The read itself is also unbounded: roff is a u16 and attr->size is dereferenced at fslog.c:3317, before check_if_attr() has constrained roff at all, so it can be up to ~64K past a record_size-sized object. Commit 0ca0485e4b2e ("fs/ntfs3: validate rec->used in journal-replay file record check") added at fslog.c:2844 if (used < PtrOffset(rec, attr) + sizeof(attr->type)) return false; and its changelog names this very memmove. It bounds rec->used against the ATTR_END offset; it does not bound asize. With record_size 0x400, attr_off 0x38, a valid three-attribute chain ending in ATTR_END at 0x158 and used 0x160, a record whose four bytes at 0x15c read 0x100 gives used - asize - roff = 0x160 - 0x100 - 0x158 = 0xffffff08 i.e. a ~4 GiB memmove whose source and destination both run off the end of rec, a kmalloc(sbi->record_size) object (record.c:105). The equivalent non-replay path already refuses this. mi_remove_attr() performs the same removal and starts with (record.c:548): if (aoff + asize > used) return false; Apply the same bound, spelled as a subtraction to match the neighbouring cases, and move the attr->size read after check_if_attr() so that the header is known to lie inside the record before it is dereferenced. Requiring roff + SIZEOF_RESIDENT <= used rejects the ATTR_END offset without rejecting any real attribute: for an attribute the walk validated, roff + asize <= off(ATTR_END) <= used - 4, and any attribute a DeleteAttribute record can legitimately name carries a full resident header, so roff + SIZEOF_RESIDENT <= roff + asize <= used - 4. check_attr() itself imposes no lower bound on asize, so a crafted sub-header asize can still pass the first test; the second test then bounds it and the memmove stays inside the record. Reproduced by mounting a crafted image on v7.2-rc5, which already contains 0ca0485e4b2e, under KASAN. The image is an ordinary mkfs.ntfs volume with four bytes of one MFT record changed and a crafted $LogFile: BUG: KASAN: slab-out-of-bounds in do_action.isra.0+0x3211/0x83c0 Read of size 4294967048 at addr ffff888002423258 by task mount/66 CPU: 1 UID: 0 PID: 66 Comm: mount Not tainted 7.2.0-rc5 #3 Call Trace: kasan_report+0xce/0x100 kasan_check_range+0x105/0x1b0 __asan_memmove+0x23/0x60 do_action.isra.0+0x3211/0x83c0 log_replay+0x920a/0xd300 ntfs_loadlog_and_replay+0x3ef/0x510 ntfs_fill_super+0x1d23/0x4550 get_tree_bdev_flags+0x2ef/0x550 vfs_get_tree+0x82/0x2f0 fc_mount+0x10/0x1b0 path_mount+0x517/0x1df0 __x64_sys_mount+0x20b/0x270 do_syscall_64+0xf9/0x540 entry_SYSCALL_64_after_hwframe+0x77/0x7f Allocated by task 66: __kasan_kmalloc+0x8f/0xa0 __kmalloc_noprof+0x1b4/0x460 mi_init+0x81/0x110 mi_get+0x6a/0x220 do_action.isra.0+0x1dbf/0x83c0 log_replay+0x920a/0xd300 ntfs_loadlog_and_replay+0x3ef/0x510 ntfs_fill_super+0x1d23/0x4550 The buggy address belongs to the object at ffff888002423000 which belongs to the cache kmalloc-1k of size 1024 The buggy address is located 600 bytes inside of allocated 1024-byte region [ffff888002423000, ffff888002423400) KASAN reports the source side because __asan_memmove() (mm/kasan/shadow.c:94) validates src before dest and returns without copying. Both ends are out of bounds, and on a kernel built without KASAN the copy is performed. rec->used is also left at used - asize by fslog.c:3323 before the memmove, so the record stays inconsistent even when the copy is suppressed; the same mount goes on to report "ino=1a, mi_enum_attr" and marks the volume dirty. Fixes: b46acd6a6a62 ("fs/ntfs3: Add NTFS journal") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5 Signed-off-by: Hyeontae Lee <wonju345@naver.com> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-28ntfs3: release ni_lock before dir_emit in ntfs_readdir to fix deadlocksYun Zhou
ntfs_readdir() holds ni_lock while calling ntfs_read_hdr(), which calls dir_emit() to copy directory entries to userspace. If the user buffer triggers a page fault, the fault handler may need mmap_lock or mapping->invalidate_lock, creating lock-order inversions with paths that acquire those locks before ni_lock (e.g. ntfs_fallocate, mmap). Fix by releasing ni_lock before calling ntfs_read_hdr(): - For non-root index nodes, indx_read_ra() returns data in a kmalloc'd buffer (node->index) that remains valid after ni_unlock. - For the root index header, the data lives in the main MFT record whose lifetime is bound to the inode. i_rwsem shared prevents concurrent directory modifications, so it is safe to access after ni_unlock. Reported-by: syzbot+7736960b837908f3a81d@syzkaller.appspotmail.com Reported-by: syzbot+262a71e9d2faf8747085@syzkaller.appspotmail.com Reported-by: syzbot+cfc6e8106bec1c524f7d@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=7736960b837908f3a81d Closes: https://syzkaller.appspot.com/bug?extid=262a71e9d2faf8747085 Closes: https://syzkaller.appspot.com/bug?extid=cfc6e8106bec1c524f7d Fixes: d62cf685d12e ("fs/ntfs3: hold ni_lock across readdir metadata walk") Signed-off-by: Yun Zhou <yun.zhou@windriver.com> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-28fs/ntfs3: bound CreateAttribute asize against record_size in do_actionHyeontae Lee
In do_action()'s CreateAttribute case (fslog.c:3286), attr2 points into the on-disk log record and asize = le32_to_cpu(attr2->size) is therefore attacker-controlled on mount. The guard bounds asize only against the log record itself, Add2Ptr(attr2, asize) > Add2Ptr(lrh, rec_len) where rec_len is the client data length, and separately bounds dlen against the MFT record. Nothing bounds asize against record_size, but all three writes that follow are into rec, a kmalloc(sbi->record_size) buffer allocated by mi_init() (record.c:105): memmove(Add2Ptr(attr, asize), attr, used - roff); memcpy(attr, attr2, asize); rec->used = cpu_to_le32(used + asize); With record_size 0x400, roff 0x38, used 0x160 and asize 0x800 the memcpy writes 2048 bytes at rec + 0x38, 0x438 bytes past the allocation, and rec->used is left at 0x960. dlen is 0x18 here, so the existing dlen check passes: dlen bounds nothing about the size of the copy. The equivalent non-replay path already refuses this. mi_insert_attr() performs the same insert and starts with (record.c:488): if (used + asize > sbi->record_size) return NULL; Apply the same bound, spelled as a subtraction to match the neighbouring clause. used <= record_size holds here because check_file_record() validates it (fslog.c:2826) and is called on this record at fslog.c:3172; roff <= used - 4 follows from check_if_attr() together with the ATTR_END check at fslog.c:2844, so bounding used + asize bounds both copies. The sibling WriteEndOfFileRecordSegment case does the equivalent check against record_size at fslog.c:3277. Reproduced by mounting a crafted image on v7.2-rc5 under KASAN: BUG: KASAN: slab-out-of-bounds in do_action.isra.0+0x41f6/0x83a0 Write of size 2048 at addr ffff888005c74838 by task mount/69 CPU: 0 UID: 0 PID: 69 Comm: mount Not tainted 7.2.0-rc5-00300-g8ba098e6b6ff #2 Call Trace: kasan_report+0xce/0x100 kasan_check_range+0x105/0x1b0 __asan_memcpy+0x3c/0x60 do_action.isra.0+0x41f6/0x83a0 log_replay+0x920a/0xd300 ntfs_loadlog_and_replay+0x3ef/0x510 ntfs_fill_super+0x1d23/0x4550 get_tree_bdev_flags+0x2ef/0x550 vfs_get_tree+0x82/0x2f0 fc_mount+0x10/0x1b0 path_mount+0x517/0x1df0 __x64_sys_mount+0x20b/0x270 do_syscall_64+0xf9/0x540 entry_SYSCALL_64_after_hwframe+0x77/0x7f Allocated by task 69: __kasan_kmalloc+0x8f/0xa0 __kmalloc_noprof+0x1b4/0x460 mi_init+0x81/0x110 mi_get+0x6a/0x220 do_action.isra.0+0x1db4/0x83a0 log_replay+0x920a/0xd300 ntfs_loadlog_and_replay+0x3ef/0x510 ntfs_fill_super+0x1d23/0x4550 The buggy address belongs to the object at ffff888005c74800 which belongs to the cache kmalloc-1k of size 1024 The buggy address is located 56 bytes inside of allocated 1024-byte region [ffff888005c74800, ffff888005c74c00) Fixes: b46acd6a6a62 ("fs/ntfs3: Add NTFS journal") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5 Signed-off-by: Hyeontae Lee <wonju345@naver.com> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-19Merge tag 'vfs-7.4-rc1.idmap' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs Pull vfs idmap constification from Christian Brauner: "This makes struct mnt_idmap const throughout the tree. A mount's idmapping is immutable. The only thing modified after alloc_mnt_idmap() is the reference count and that is hidden behind mnt_idmap_get() and mnt_idmap_put(). Everything else only reads from it. That is the same model struct cred uses and the idmapping is sensitive enough to deserve it. The conversion goes bottom up through the vfs{g,u}id and fs{g,u}id helpers, the privilege checks, acl, xattr and quota and then every inode operation that takes an idmap, so ->permission(), ->getattr(), ->setattr(), ->create(), ->mkdir(), ->mknod(), ->symlink(), ->rename(), ->tmpfile(), ->get_acl(), ->set_acl() and ->fileattr_set() with their implementations in every filesystem, plus the LSM hooks. struct vfsmount, struct mount_kattr and struct kstatmount store a const pointer and nop_mnt_idmap and invalid_mnt_idmap live in rodata, so anything that tries to modify them faults instead of silently corrupting the initial idmapping" * tag 'vfs-7.4-rc1.idmap' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: (27 commits) fs: make nop_mnt_idmap and invalid_mnt_idmap const fs: port mnt_idmap() and file_mnt_idmap() to const mnt_idmap fs: port vfs_*() helpers to const mnt_idmap fs: port ->setattr() to pass const mnt_idmap fs: port ->getattr() to pass const mnt_idmap fs: port ->create() to pass const mnt_idmap fs: port ->symlink() to pass const mnt_idmap fs: port ->mkdir() to pass const mnt_idmap fs: port ->rename() to pass const mnt_idmap fs: port ->mknod() to pass const mnt_idmap fs: port ->tmpfile() to pass const mnt_idmap fs: port ->get_acl() to pass const mnt_idmap fs: port ->set_acl() to pass const mnt_idmap fs: port ->fileattr_set() to pass const mnt_idmap fs: port xattr to const mnt_idmap fs: port ->permission() to pass const mnt_idmap fs: port acl to const mnt_idmap fs: port inode_init_owner() to const mnt_idmap fs: port inode_owner_or_capable() to const mnt_idmap fs: port privilege checking helpers to const mnt_idmap ...
2026-10-14ntfs3: free replaced mount options after a grace periodChristian Brauner
ntfs_fs_reconfigure() replaces the old mount options with new mount options in sbi->options. The old mount options land in fs_context and are freed as soon as remount returns. With a pathwalk held up in ntfs_nls_to_utf16() between loading sbi->options and dereferencing it while a remount replaces them: BUG: KASAN: slab-use-after-free in ntfs_nls_to_utf16+0x7ae/0x7c0 Read of size 8 at addr ff110001044fd448 by task walker/98 Call Trace: <TASK> ntfs_nls_to_utf16+0x7ae/0x7c0 ntfs_d_hash+0x22b/0x500 link_path_walk+0x11ad/0x1d30 path_lookupat+0x63/0xb00 filename_lookup+0x1f1/0x5b0 vfs_statx+0xd7/0x3b0 [...] Allocated by task 95: __kmalloc_node_track_caller_noprof+0x2a2/0x730 kmemdup_noprof+0x25/0x50 ntfs_fill_super+0x1e5/0x4550 [...] Freed by task 97: kfree+0x1db/0x5b0 put_fs_context+0x13c/0x7d0 path_mount+0x54a/0x2130 __x64_sys_mount+0x20c/0x270 That info is needed in rcu lookup in the dentry hash and dentry compary methods for ntfs3 and causes a UAF today. Delay freeing with an rcu grace period. ntfs_nls_to_utf16() reads ->nls and ->ads once under rcu_read_lock() so the hooks pair with the release in ntfs_fs_reconfigure(). That also covers callers outside of rcu pathwalk such as ntfs_lookup(). They don't hold rcu_read_lock() themselves and wouldn't be protected by the grace period otherwise. Remount refuses to change the iocharset so ->nls stays valid after rcu_read_unlock(). Fixes: a3a956c78efa ("fs/ntfs3: Add option "nocase"") Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261009-work-fixes-rcu-v1-8-7446d2d335e6@kernel.org Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-10-14ntfs3: free the sbi after a grace periodChristian Brauner
If the "nocase" mount option ntfs3 uses custom hash and dentry compare functions. Both access ntfs3 superblock private information in rcu pathwalk. ntfs_put_super() and ntfs3_kill_sb() drop the info without any rcu delay. A lookup that's still inside the filesystem when the last reference to the mount is dropped causes a UAF. With a pathwalk held up in ntfs_d_hash() while the last reference to the mount goes away: BUG: KASAN: slab-use-after-free in ntfs_nls_to_utf16+0x752/0x940 Read of size 8 at addr ff1100010453c850 by task walker/99 Call Trace: <TASK> ntfs_nls_to_utf16+0x752/0x940 ntfs_d_hash+0x22b/0x500 link_path_walk+0x11ad/0x1d30 path_lookupat+0x63/0xb00 filename_lookup+0x1f1/0x5b0 vfs_statx+0xd7/0x3b0 [...] Allocated by task 95: __kmalloc_cache_noprof+0x249/0x560 ntfs_init_fs_context+0x2db/0x5a0 alloc_fs_context+0x52e/0xc70 [...] Freed by task 98: kfree+0x1db/0x5b0 deactivate_locked_super+0x9c/0xf0 cleanup_mnt+0x9f/0x130 task_work_run+0x131/0x250 The bug is currently masked by the grace period in namespace_unlock() for umount(2). Keep the necessary information until the filesystem private info is freed and free it with an rcu delay. ntfs3_free_sbi() now runs from an rcu callback and drops the upcase table via ntfs_put_shared(). So switch s_shared_lock over to spin_lock_bh(). Otherwise the callback can deadlock against a task holding the lock on the same cpu. Fixes: a3a956c78efa ("fs/ntfs3: Add option "nocase"") Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20261009-work-fixes-rcu-v1-7-7446d2d335e6@kernel.org Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-10-13fs/ntfs3: do not mark frame pages uptodate on read errorWeiming Shi
ni_read_frame() ends with a loop that marks every page of a compressed frame uptodate regardless of whether the read succeeded: out: for (i = 0; i < pages_per_frame; i++) { pg = pages[i]; SetPageUptodate(pg); } Non-critical frame pages come from __filemap_get_folio(FGP_CREAT) and are not zeroed. On an error path that reaches out: before frame_mem is written, these pages keep uninitialized page-allocator contents but are still marked uptodate. A later read() is then served from the page cache and returns that stale kernel memory to user space. For an unprivileged user mounting a crafted NTFS image this is a repeatable kernel memory disclosure. Mark the pages uptodate only on success; on error leave them !uptodate so the read path re-reads them or reports the error. Fixes: 4342306f0f0d ("fs/ntfs3: Add file operations and implementation") Reported-by: Xiang Mei <xmei5@asu.edu> Signed-off-by: Weiming Shi <bestswngs@gmail.com> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-13fs/ntfs3: prevent positive E_NTFS_NONRESIDENT from reaching writeback error ↵Vidhu Sarwal
handling attr_data_write_resident() returns the internal positive status code E_NTFS_NONRESIDENT when the DATA attribute becomes non-resident. ntfs_writepages() propagates this value into generic writeback error handling, which expects a standard negative errno and triggers WARN_ON_ONCE(err > 0). Translate positive E_NTFS_* status codes to -EIO before recording the writeback error. This prevents positive internal status codes from reaching generic writeback code while preserving the existing behaviour of treating this path as a writeback error. Reported-by: syzbot+57f9327d593d301ce2a2@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=57f9327d593d301ce2a2 Signed-off-by: Vidhu Sarwal <vidhu.linux@gmail.com> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-13fs/ntfs3: fix ntfs_fnd leak when compare function is missingliyouhong
indx_insert_entry(), indx_delete_entry() and indx_update_dup() take a finder via fnd_get() before calling get_cmp_func(). If no compare function is available they return -EINVAL and never release the finder. Jump to the existing out path so fnd_put() still runs. Fixes: 3a2141b2f1c3 ("fs/ntfs3: resolve compare function in public index APIs") Signed-off-by: liyouhong <liyouhong@kylinos.cn> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-13fs/ntfs3: fix stale attr_b in attr_allocate_frame()Konstantin Komarov
ni_insert_nonresident() can create an attribute list and move the base $DATA attribute to another MFT record, which invalidates attr_b and mi_b. attr_allocate_frame() kept using the stale pointers afterwards to update valid_size, writing into a record that no longer holds the attribute. The same situation is already handled in attr_data_get_block_locked(), which re-reads the base attribute after the layout changes. Look up attr_b again after the insertion, and read valid_size from the attribute before the layout can change. While here, flatten the 'if (attr)' block in attr_allocate_frame() by returning early to ins_ext, and simplify an empty-bodied if in attr_data_get_block_locked(). Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-13fs/ntfs3: reject unaligned hole punching on compressed filesKonstantin Komarov
attr_punch_hole() handles a range that is not cluster aligned by reporting the frame size back to the caller, which zeroes the partial clusters and retries. Return -EINVAL for an unaligned punch on a compressed attribute; the sparse case is unaffected. Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-13fs/ntfs3: take ni_lock() once in ntfs_readdir()Konstantin Komarov
ntfs_readdir() took ni_lock() to load subrecords, dropped it, and then took it again for the index walk. The double-checked pattern around ni_load_all_mi() and the separate out_unlock label exist only because of that split. Take the lock once for the whole function and drop the second acquisition, the inner re-check and the duplicate error label. Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-13fs/ntfs3: reserve a compression unit in maxbytes_sparseKonstantin Komarov
With 32-bit clusters, the maximum size of a sparse file was computed as the largest offset addressable by a 32-bit VCN. Reserve one compression unit below the limit so the rounded-up VCN still fits. Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-13fs/ntfs3: allow a zero cluster count for resident attributesKonstantin Komarov
ntfs_iomap_begin() rejected a zero cluster count from attr_data_get_block() as corruption. For a resident attribute this is a normal result: the data lives in the MFT record, so no clusters are mapped, and the resident case is handled further down and returns before the cluster count is used. Move the check below the RESIDENT_LCN and EOF_LCN handling, so it only applies to the mapped case where a zero count really does indicate a broken record. Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-13fs/ntfs3: add 'ugm' mount option to control storing uid/gid/mode in xattrsKonstantin Komarov
On file creation ntfs3 stores the owner, group, mode and device number in the WSL extended attributes $LXUID, $LXGID, $LXMOD and $LXDEV, and may also write a POSIX ACL. These attributes are meaningless to Windows, and the packed size of the EAs is recorded in the directory entry as well, so every created file carries them. Add a 'ugm' mount option controlling this. It is enabled by default, preserving the current behaviour; mount with 'ugm=0' to create files without the WSL attributes. Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-13fs/ntfs3: do not force allocation for IOMAP_ZERO on a partial clusterKonstantin Komarov
ntfs_iomap_begin() set 'rw' for IOMAP_ZERO whenever the end of the range fell inside a cluster, forcing the sparse path to allocate clusters in order to zero them. Drop the IOMAP_ZERO case and only clamp clen_max when 'rw' is already set. Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-13fs/ntfs3: minor code cleanupsKonstantin Komarov
Use Add2Ptr() for pointer arithmetic in fill_name_de(), consistent with the rest of the driver, and reflow two statements to match the 80-column style. No functional change. Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-13fs/ntfs3: drop unused new_size argument from attr_make_nonresident()Konstantin Komarov
attr_make_nonresident() takes new_size but never uses it: the attribute's size is read from the record it is converting, and all three callers pass either the value already stored there or, in attr_set_size_res(), a size that the function ignores. Remove the argument. Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-13fs/ntfs3: zero newly allocated clusters when the request is smaller than the ↵Konstantin Komarov
frame For compressed attributes, allocation is rounded up to a whole compression frame, so a request covering only part of a frame still allocates clst_per_frame clusters. The clusters outside the requested range are then allocated but never written by the caller. Until now 'zero' was set only when allocation had to start before the requested VCN. When it started at vcn0 but extended past the end of the request, the tail clusters were left holding whatever was previously on disk. Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-13fs/ntfs3: show supported options when an unknown one is givenKonstantin Komarov
When an unrecognised mount option is passed, fs_parse() returns -ENOPARAM. Print the list of supported options alongside the key, so the correct spelling can be found directly. Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-07fs/ntfs3: check return values in indx_delete_entry()Dmitry Morgun
When the index tree collapses down to an empty root, indx_delete_entry() calls attr_set_size() and ni_remove_attr() for both ATTR_ALLOC and ATTR_BITMAP, but their return values are overwritten by the following call without being checked. In most other call sites of these functions the return value is checked, so add the same checks here in case an error at this point is meaningful. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block") Signed-off-by: Dmitry Morgun <d.morgun@ispras.ru> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-07fs/ntfs3: remove redundant if-block in check_attr()Matvey Kovalev
Condition of this if-block repeats another one from if-block above. So, condition is always false. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Matvey Kovalev <matvey.kovalev@ispras.ru> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-10-07fs/ntfs3: validate that EA entry size covers its name and valueAldo Ariel Panzardo
ntfs_read_ea() walks the on-disk $EA attribute and checks each EA_FULL entry for consistency. For an entry with a non-zero ef->size (the offset to the next entry) the loop only verifies that this stride fits in the remaining buffer, and then continues: if (ef->size) { ea_size = le32_to_cpu(ef->size); if (ea_size > bytes) goto out1; continue; } It never verifies that the entry's own name (ef->name_len) and value (ef->elength) actually fit inside ef->size. A later reader trusts ef->elength unconditionally; ntfs_get_ea() does: len = le16_to_cpu(ea->elength); /* up to 0xffff */ ... if (len > size) /* size is the user buffer */ return -ERANGE; memcpy(buffer, ea->name + ea->name_len + 1, len); A crafted image with a small but valid ef->size (e.g. 24) and ef->elength == 0xffff therefore passes validation, and a getxattr() with a large enough user buffer copies up to 64 KiB starting just past the short entry -- an out-of-bounds read of the ea_all allocation that leaks adjacent kernel heap memory to userspace. BUG: KASAN: slab-out-of-bounds in ntfs_get_ea+0x2b8/0x3f0 Read of size 65535 ... ntfs_get_ea -> ntfs_getxattr -> vfs_getxattr -> do_getxattr The zero-ef->size branch already computes the same struct_size() to derive the stride; mirror that in the non-zero branch and reject the entry when its declared size cannot hold the name and value. Fixes: 0e8235d28f3a ("fs/ntfs3: Check fields while reading") Cc: stable@vger.kernel.org Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@gmail.com> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-09-28fs/ntfs3: return -ERANGE for short xattr buffersBaolin Liu
ntfs3 currently returns -ENODATA when the xattr exists but the user buffer is too small. Return -ERANGE instead. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-09-28fs/ntfs3: reject an oversized resident attribute on the inline iomap pathMichael Bommarito
attr_data_get_block_locked() maps a resident attribute as a one-page IOMAP_INLINE extent: it allocates a single page, copies the resident value into it with memcpy(), and hands that page to ntfs_iomap_begin() as the inline data. The copy length is the on-disk resident value length (res.data_size), and mi_enum_attr() only bounds that length against the MFT record size. A corrupted volume with MFT records larger than a page can therefore present a resident $DATA whose length exceeds PAGE_SIZE, and the memcpy() then writes past the single destination page. Impact: reading or writing a resident file on a mounted crafted NTFS volume whose MFT records are larger than a page overflows the one-page inline buffer in attr_data_get_block_locked() with attacker-controlled bytes. Reject such an attribute in attr_data_get_block_locked(), before the page is allocated and the copy is made. Fixes: 099ef9ab9203 ("fs/ntfs3: implement iomap-based file operations") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-09-28fs/ntfs3: fix slab-out-of-bounds write in attr_insert_range()Xiang Mei (Microsoft)
When fallocate(FALLOC_FL_INSERT_RANGE) grows a still-resident ntfs3 attribute, attr_insert_range() shifts the inline data using the insert length 'bytes' as both the destination offset and the copy size: memmove(data + bytes, data, bytes); Both are wrong: the shift must start at the insertion point 'vbo' and move only the data past it (data_size - vbo). When bytes > data_size the memmove runs off the end of the data_size + bytes buffer and overflows the adjacent slab object. Since vbo < data_size is already enforced above, the reworked offsets stay within the data_size + bytes buffer and cannot under/overflow. BUG: KASAN: slab-out-of-bounds in attr_insert_range (fs/ntfs3/attrib.c:2581) Write of size 512 at addr ffff8880135e8b10 by task exploit/142 ... __asan_memmove (mm/kasan/shadow.c:95) attr_insert_range (fs/ntfs3/attrib.c:2581) ntfs_fallocate (fs/ntfs3/file.c:618) vfs_fallocate (fs/open.c:338) __x64_sys_fallocate (fs/open.c:362) ... Fixes: 9256ec35359f ("fs/ntfs3: Refactoring attr_insert_range to restore after errors") Reported-by: AutonomousCodeSecurity@microsoft.com Signed-off-by: Xiang Mei (Microsoft) <xmei5@asu.edu> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-09-28fs/ntfs3: fix integer overflow in find_log_rec() causing OOB readIbrahim Hashimov
find_log_rec() validates the on-disk LFS_RECORD_HDR.client_data_len field (`len`, a raw u32 read straight from a mounted $LogFile page) against the log's total available space: len = le32_to_cpu(rh->client_data_len); rec_len = len + log->record_header_len; if (rec_len >= log->total_avail) return -EINVAL; The addition is unchecked. For len in [0xffffffd0, 0xffffffff] (i.e. log->record_header_len away from UINT_MAX), `rec_len` wraps to a small u32 value that trivially clears the `rec_len >= log->total_avail` guard, so a record whose declared length is actually ~4 GiB is reported as valid and in-page. Because find_log_rec() wrongly accepts the record, its caller read_log_rec_lcb() hands it back to log_replay() as good. On the transaction-table replay leg, log_replay() re-derives the record length directly from the same raw, still-unclamped client_data_len field and uses it to size the restart-table blob: rec_len = le32_to_cpu(frh->client_data_len); /* ~0xffffffff */ ... t16 = le16_to_cpu(lrh->redo_off); rt = Add2Ptr(lrh, t16); t32 = rec_len - t16; /* still ~4 GiB */ if (!check_rstbl(rt, t32)) return -EINVAL; check_rstbl()'s own `bytes < ts` bounds guard is defeated because the caller-supplied `bytes` (t32) is itself the poisoned ~4 GiB value, so the guard can never trigger. The subsequent entry-validation loop then walks `rt->used` (also attacker-controlled) entries of sizeof(struct RESTART_TABLE) == 0x18 bytes each straight past the end of the kmalloc(log->page_size) log-page buffer allocated in read_log_page(), producing an out-of-bounds read that is reachable simply by mounting a crafted $LogFile (no genuine dirty-page / crash-recovery state is required). Confirmed via KASAN as a slab-out-of-bounds read in check_rstbl(), called from log_replay() -> ntfs_loadlog_and_replay() -> ntfs_fill_super() -> mount(2). Fix the root cause instead of hardening every downstream consumer of the poisoned length: make the addition in find_log_rec() overflow-safe with check_add_overflow(), mirroring the pattern fs/ntfs3/run.c already uses to validate other attacker-controlled on-disk length/offset arithmetic decoded from MAPPING_PAIRS runs, e.g.: if (check_add_overflow(vcn64, len, &next_vcn)) return -EINVAL; ... if (check_add_overflow(lcn, len, &lcn_end)) return -EINVAL; (fs/ntfs3/run.c, run_unpack()). With the overflow rejected instead of silently wrapped, `rec_len` is only ever a true, non-wrapped sum, so the existing `rec_len >= log->total_avail` check now correctly rejects any oversized record up front. log_replay()'s transaction-table leg then never gets a chance to re-read the poisoned client_data_len, and check_rstbl() is never invoked with an attacker-inflated `bytes` for this path. Verified on a v6.19 KASAN build: mounting a crafted $LogFile whose client_data_len overflows trips a KASAN slab-out-of-bounds-read report in check_rstbl() before this fix; with check_add_overflow() applied, the same image is cleanly rejected during log replay and no KASAN report fires. Fixes: b46acd6a6a62 ("fs/ntfs3: Add NTFS journal") Cc: stable@vger.kernel.org Signed-off-by: Ibrahim Hashimov <security@auditcode.ai> Assisted-by: AuditCode-AI:2026.07 Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-09-24ntfs3: fix resident attribute handling in run load pathsYi Xie
Don't dereference nres unless attr->non_res is set. ni_find_attr() can succeed with a resident record on a corrupted image, and run_unpack_ex() would mis-parse it as mapping pairs. Fix attr_load_runs(), attr_load_runs_vcn() and attr_set_size(). Fixes: 5ec75546dc71 ("ntfs: fix WARN_ON for resident attribute in ntfs_map_runlist_nolock()") Signed-off-by: Yi Xie <xieyi@kylinos.cn> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-09-24Fix OOB write if err == buflen in ntfs_readlink_hlp()Alexandro Calo
ntfs_utf16_to_nls() may return buflen. The caller later uses the returned length as the index for writing the trailing NUL byte, so err == buflen writes one byte past the end of buffer. Fix this by limiting err to the last valid buffer index before writing NUL. ntfs_utf16_to_nls() returning a negative value is already handled by if (err < 0) goto out; As long as buflen is guaranteed to be nonzero the patch is fine. As a defensive fix if(buflen==0) could be added. This heap out-of-bounds write requires a crafted filesystem image, which is not in the kernel threat model, but fixing memory errors would be nice to keep things secure. Signed-off-by: Alexandro Calo <alexandro.calo@nozominetworks.com> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-09-24fs/ntfs3: Fix heap overflow after ALIGN in mi_pack_runs()Alexandro Calo
When run_pack() returns a non-aligned byte count, ALIGN(err, 8) inflates it by 1-7 bytes, and since the destination of the memmove() is computed from that inflated value, the entire attribute tail could be copied 1-7 bytes past where the record buffer ends. The memmove() destination is next + new_run_size - run_size. For it to stay within the record, new_run_size must not exceed run_size + dsize, the space actually available. Since new_run_size = ALIGN(err, 8), a fix could be to ensures there is enough room that whatever ALIGN does to err, the result still fits within the available space. Restricting the budget of run_pack() should guarantee that. Something like: u32 avail = (run_size + dsize) & ~7u; err = run_pack(run, svcn, len, Add2Ptr(attr, run_off), avail, &plen); Now, run_pack() should never return 0. As now, the function returns at least 1. So this is fine. Negative values are caught as errors by if(err<0). The rounded-down avail may be smaller than the existing run size, if avail=0 run_pack is called and will write run_buf[0] = 0; that will be OOB, because the buffer size is zero, so imo the caller should avoid calling run_pack() with avail=0. After run_pack(), if plen = 0, then svcn + plen - 1 becomes svcn - 1. So, after run_pack(), it may be worth ensuring if(!plen). Lastly, I'm not sure if -ENOSPC is the right error code here, but it seems reasonable for a space condition. This heap out-of-bounds write requires a crafted filesystem image, which is not in the kernel threat model, but fixing memory errors would be nice to keep things secure. Signed-off-by: Alexandro Calo <alexandro.calo@nozominetworks.com> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-09-24fs/ntfs3: Fix OOB write if ret == buf_len in ntfs_utf16_to_nls()Alexandro Calo
'utf16s_to_utf8s()' is documented to return at most 'buf_len', the caller does not check whether 'ret == buf_len' before writing the terminator. The 'buf[ret] = '\0'' could write a NULL terminator one byte past the buffer. Fix this up by limiting ret to the last valid buffer index before writing NULL. As long as 'utf16s_to_utf8s()' never return a negative value and 'buf_len' is guaranteed to be nonzero the patch is fine. Anyway, as defensive fixes, if(ret<0) and if(buf_len==0) could be added. Signed-off-by: Alexandro Calo <alexandro.calo@nozominetworks.com> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
2026-09-23fs: port ->setattr() to pass const mnt_idmapChristian Brauner
Convert to const struct mnt_idmap. A mount's idmapping is immutable. The only thing that is allowed to be modified afterwards is the reference count and that is hidden behind mnt_idmap_get() and mnt_idmap_put(). Everything else only ever reads from the idmapping. This is the same model that struct cred uses and the idmapping is also rather sensitive. So make the idmap argument const wherever we can. The conversion is done from the bottom up so callers can continue to pass a non-const pointer to a const parameter until the conversion is finished. No functional changes. Link: https://patch.msgid.link/20260901-work-idmap-const-v1-24-54ccd48e100b@kernel.org Acked-by: Paul Moore <paul@paul-moore.com> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Seth Forshee <sforshee@kernel.org> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-09-23fs: port ->getattr() to pass const mnt_idmapChristian Brauner
Convert to const struct mnt_idmap. A mount's idmapping is immutable. The only thing that is allowed to be modified afterwards is the reference count and that is hidden behind mnt_idmap_get() and mnt_idmap_put(). Everything else only ever reads from the idmapping. This is the same model that struct cred uses and the idmapping is also rather sensitive. So make the idmap argument const wherever we can. The conversion is done from the bottom up so callers can continue to pass a non-const pointer to a const parameter until the conversion is finished. No functional changes. Link: https://patch.msgid.link/20260901-work-idmap-const-v1-23-54ccd48e100b@kernel.org Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Seth Forshee <sforshee@kernel.org> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-09-23fs: port ->create() to pass const mnt_idmapChristian Brauner
Convert to const struct mnt_idmap. A mount's idmapping is immutable. The only thing that is allowed to be modified afterwards is the reference count and that is hidden behind mnt_idmap_get() and mnt_idmap_put(). Everything else only ever reads from the idmapping. This is the same model that struct cred uses and the idmapping is also rather sensitive. So make the idmap argument const wherever we can. The conversion is done from the bottom up so callers can continue to pass a non-const pointer to a const parameter until the conversion is finished. No functional changes. Link: https://patch.msgid.link/20260901-work-idmap-const-v1-22-54ccd48e100b@kernel.org Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Seth Forshee <sforshee@kernel.org> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-09-23fs: port ->symlink() to pass const mnt_idmapChristian Brauner
Convert to const struct mnt_idmap. A mount's idmapping is immutable. The only thing that is allowed to be modified afterwards is the reference count and that is hidden behind mnt_idmap_get() and mnt_idmap_put(). Everything else only ever reads from the idmapping. This is the same model that struct cred uses and the idmapping is also rather sensitive. So make the idmap argument const wherever we can. The conversion is done from the bottom up so callers can continue to pass a non-const pointer to a const parameter until the conversion is finished. No functional changes. Link: https://patch.msgid.link/20260901-work-idmap-const-v1-21-54ccd48e100b@kernel.org Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Seth Forshee <sforshee@kernel.org> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-09-23fs: port ->mkdir() to pass const mnt_idmapChristian Brauner
Convert to const struct mnt_idmap. A mount's idmapping is immutable. The only thing that is allowed to be modified afterwards is the reference count and that is hidden behind mnt_idmap_get() and mnt_idmap_put(). Everything else only ever reads from the idmapping. This is the same model that struct cred uses and the idmapping is also rather sensitive. So make the idmap argument const wherever we can. The conversion is done from the bottom up so callers can continue to pass a non-const pointer to a const parameter until the conversion is finished. No functional changes. Link: https://patch.msgid.link/20260901-work-idmap-const-v1-20-54ccd48e100b@kernel.org Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Seth Forshee <sforshee@kernel.org> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>