summaryrefslogtreecommitdiff
path: root/fs/ntfs
AgeCommit message (Collapse)Author
11 daysntfs: convert a named $DATA stream safely when making room in a recordWahid Khan
When an attribute has to grow and the mft record is full, ntfs_resident_attr_resize() walks the other resident attributes and converts them to non-resident ones. For $DATA it always opens the unnamed data inode of the base inode, even if the attribute found is a named stream: tvi = ntfs_iget(sb, base_ni->mft_no); ntfs_attr_make_non_resident(NTFS_I(tvi), value_len); value_len is the length of the stream, so it does not match the attribute that ntfs_attr_make_non_resident() looks up for the unnamed inode, and the WARN_ON() on entry fires: WARNING: fs/ntfs/attrib.c:2115 at ntfs_attr_make_non_resident ntfs_resident_attr_resize ntfs_attr_expand_locked ntfs_expand_for_write ntfs_file_write_iter vfs_write It does not need a damaged volume. A file with an alternate data stream whose record has no room left is enough. Open a named stream by name with ntfs_attr_iget(), as is done for the other attribute types in this loop, and keep ntfs_iget() for the unnamed one. The loop runs with the mft record lock held and takes no lock of the stream inode, so converting a stream from here needs more care than the plain lookup gives: - A reader of the stream holds the folio lock and then takes the mft record lock in ntfs_read_iomap_begin_resident(), the conversion takes them the other way round and waits for folio 0. Take the folio with FGP_NOWAIT in this loop and skip the attribute if it is busy. The loop only tries to free space. The same inversion exists for the conversion of the attribute being resized, which waited for folio 0 with the lock held and hangs against an mmap fault or splice reader. Use FGP_NOWAIT there too. The resize then fails with -EBUSY while such a reader is stuck on the lock, instead of hanging. Do not look for room in other attributes either: the reader keeps the folio until the lock is dropped, so the attribute can neither be converted nor written without waiting for it, and the loop would only convert other attributes for nothing. FGP_NOWAIT also fails when the folio can not be allocated, so on failure look the folio up: only one that is there means a busy folio, otherwise return -ENOMEM. - A stream that is in the inode cache can be open, being written, being removed or already unlinked. A write that passed its residency check before the conversion carries on with a non-resident attribute, and a stream in the middle of ntfs_stream_finish_remove() is converted under its feet. Convert only a stream that is not cached. - An attribute inode of a file that has no links left is evicted on the last iput() with its dirty folio, so what was converted is lost and an open file reads its extended attributes back as missing. Convert nothing, of any type, in a file that is being deleted or has no links left. - The unnamed data is converted through the file's own inode, whose i_rwsem only a resize of the unnamed data itself holds. When a stream or an extended attribute is being resized, a writer of the file can have passed its residency check and carry on with a non-resident attribute (iomap_iter warnings, recursive mrec_lock). When the unnamed data is the attribute being resized, its conversion was just tried by the caller. Do not convert the unnamed data from this loop. - Do not convert the attribute that is being resized either. Its conversion was just tried and failed, for instance on a busy folio, and a second try that succeeds leaves the resize to go on with the resident layout of a record that is now non-resident. - The lookup of a stream ignores case, so a stream whose name differs only in case from an earlier one resolves to that one and the length does not match again. Compare the names exactly. Fixes: 495e90fa3348 ("ntfs: update attrib operations") Cc: stable@vger.kernel.org # v7.1+ Signed-off-by: Wahid Khan <wahidzk0091@gmail.com> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
11 daysntfs: don't let a fatal signal interrupt metadata readsYue Yang
read_mapping_folio() returns -EINTR when the caller has a fatal signal pending while it waits for the read it submitted. ntfs reads its metadata through it and treats the failure as a volume error, so killing a task that waits on a metadata read turns the volume read-only with errors=remount-ro. A read that is part of an update also stops the update half way: killing an rm can leave clusters allocated in $Bitmap, an MFT record in use without a directory entry, or a directory index with entries that point to freed records. Killing a mount makes it fail with bogus $AttrDef and $UpCase errors, or leaves the volume mounted read-only with a bogus $MFTMirr or $BadClus error. Add ntfs_read_metadata_folio(), which waits for the read uninterruptibly, and use it for metadata reads. Named stream contents, compressed data and the read-only bitmap scans through ntfs_get_locked_folio(), whose callers do not report a volume error, keep using read_mapping_folio(). A named stream write that is interrupted that way no longer reports a volume error either. A killed task now waits for its metadata read to complete, as it does on filesystems that use the buffer cache. Closes: https://github.com/namjaejeon/linux-ntfs/issues/98 Fixes: 11ccc9107dc4 ("ntfs: update runlist handling and cluster allocator") Fixes: 115380f9a2f9 ("ntfs: update mft operations") Fixes: af0db57d4293 ("ntfs: update inode operations") Fixes: 495e90fa3348 ("ntfs: update attrib operations") Fixes: 0a8ac0c1fa0b ("ntfs: update directory operations") Fixes: 5218cd102aec ("ntfs: update misc operations") Fixes: 6251f0b0de7d ("ntfs: update super block operations") Fixes: 8506a8031ebf ("ntfs: validate and reserve bad clusters at mount") Cc: stable@vger.kernel.org Signed-off-by: Yue Yang <xkeyc@qq.com> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
11 daysntfs: flush sibling attribute mappings during stream fsyncNamjae Jeon
Stream fsync skips sibling mappings, so an attribute converted to non-resident during a resize can lose its old contents after a crash. Flush sibling mappings through the shared fsync path. Skip self-parent FILE_NAME entries to avoid recursively locking the root directory's MFT record. Fixes: 48996054b706 ("ntfs: add named stream ioctls support") Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
11 daysntfs: limit MFT mirror comparisons to system recordsBaolin Liu
Windows 10 can leave $MFTMirr records from record 16 onwards stale on volumes with large clusters. Comparing them can falsely report corruption. Commit 749357bd48c1 ("ntfs: mount hibernated volumes read-only regardless of errors=") made these mismatches force a read-only mount even with errors=continue. Limit the record checks and comparison to the first 16 records within the mirror, following ntfs-3g. Keep reading the full mirror for runlist mapping and location checks, and leave mirror writeback unchanged. Fixes: 2beaa98b46c4 ("ntfs: restore $MFT mirror contents check") Cc: stable@vger.kernel.org Link: https://github.com/tuxera/ntfs-3g/commit/85e208176ffd16ce9a51a9f534b194f0ebbde6e3 Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-11-14Merge tag 'ntfs-for-7.4-rc3' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/ntfs Pull ntfs fixes from Namjae Jeon: - Validate that $INDEX_ALLOCATION is open and non-resident before reading or writing index blocks, preventing NULL pointer dereferences when an earlier index operation has not opened it - Check that index allocation inodes are non-resident and child VCNs are non-negative and within bounds before directory lookup reads, preventing a deadlock when $INDEX_ALLOCATION is missing or damaged - Validate file names against the index entry's key length, preventing out-of-bounds reads when directory enumeration resumes using a copied key - Return -ENOENT for NTFS_IOC_LIST_STREAMS on deleted base files and fix unsigned underflow in its buffer bounds check, preventing out-of-bounds writes when the sizing and filling passes disagree - Use kfree() for the temporary runlist allocated with kmalloc() on merge failure, resolving the Coccinelle allocation/free mismatch warning * tag 'ntfs-for-7.4-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/ntfs: ntfs: open the index allocation before reading or writing an index block ntfs: do not read an index block outside $INDEX_ALLOCATION ntfs: silence kmalloc/kvfree mismatch warning ntfs: check the file name against the key length of an index entry ntfs: fix out-of-bounds write race in NTFS_IOC_LIST_STREAMS
2026-11-10Merge 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-08Merge tag 'devm_kmalloc_obj-v7.4-rc2' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux Pull devm_kmalloc_obj conversion from Kees Cook: - treewide refresh of kmalloc_obj() conversions - devm_kmalloc_obj conversion rules added to Coccinelle scripting - treewide conversion of devm_kmalloc() family to devm_kmalloc_obj() * tag 'devm_kmalloc_obj-v7.4-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: treewide: Convert devm_kmalloc() family to the devm_kmalloc_obj() family coccinelle: kmalloc_obj: Include devm_kmalloc_obj conversion rules treewide: refresh kmalloc_obj() conversions
2026-11-08ntfs: open the index allocation before reading or writing an index blockWahid Khan
ntfs_ib_write() and ntfs_ib_read() use icx->ia_ni without checking it. ntfs_ir_reparent() only opens the index allocation through ntfs_ia_add() when the root is a small index. For a root that is already marked as a large index it calls ntfs_ib_write() directly. The lookup does not open the index allocation either when it ends in the root. If the last entry of the root has no child node, ia_ni is still NULL when the root has to be moved into an index block, and the write dereferences it: Oops: general protection fault, KASAN: null-ptr-deref in range [0x0000000000000128-0x000000000000012f] RIP: 0010:ntfs_inode_attr_pwrite+0x52/0x1600 ntfs_ir_make_space ntfs_ie_add ntfs_index_add_filename __ntfs_link ntfs_link vfs_link A single byte of an image from mkntfs is enough. In a directory that has one empty index block, clear INDEX_ENTRY_NODE (flags 3 -> 2) of the last entry of the $INDEX_ROOT and link() a file into the directory. Commit 9365c4a1357e ("ntfs: fix NULL dereference on index allocation open failure") covers the case where ntfs_ia_open() fails in the lookup. Here it was never tried. Open the index allocation on demand in both helpers and fail with -EIO if that does not work. ntfs_ia_open() also succeeds for a directory that has no $INDEX_ALLOCATION attribute. The inode it returns is then an empty resident stub that does not describe an index allocation, so reject that case too. Fixes: 0a8ac0c1fa0b ("ntfs: update directory operations") Cc: stable@vger.kernel.org # v7.1+ Signed-off-by: Wahid Khan <wahidzk0091@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-11-08ntfs: do not read an index block outside $INDEX_ALLOCATIONWahid Khan
A directory whose $INDEX_ROOT has a child node but whose $INDEX_ALLOCATION is missing or damaged gets an empty index inode from ntfs_read_locked_index_inode(): size 0 and not non-resident. ntfs_lookup_inode_by_name() still follows the child node and reads a folio from that inode while it holds the mft record lock of the directory. Since the resident iomap read started to take base_ni->mrec_lock, that read waits for a lock the caller already holds: INFO: task init:1 is blocked on a mutex likely owned by task init:1. __mutex_lock __ntfs_read_iomap_begin ntfs_read_iomap_next iomap_read_folio ntfs_read_folio ntfs_lookup_inode_by_name ntfs_lookup The task never returns, and neither does anything else that needs the directory's mft record. It takes one corrupted byte on an image from mkntfs: change the first byte of the type of the $INDEX_ALLOCATION attribute header of a directory with index blocks from 0xa0 to 0x00. The first lookup in that directory hangs. Check that the index inode is non-resident and that the vcn lies inside it before every index block read, and fail with -EIO otherwise. This also rejects a negative vcn, which was only checked on later descents. Fixes: d9e00c457d4a ("ntfs: serialize resident iomap reads with mrec_lock") Cc: stable@vger.kernel.org # v7.3+ Signed-off-by: Wahid Khan <wahidzk0091@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-11-08ntfs: silence kmalloc/kvfree mismatch warningNamjae Jeon
The temporary runlist is allocated with kmalloc(). Free it with kfree() on merge failure to silence the Coccinelle warning. Fixes: b041ca562526 ("ntfs: update iomap and address space operations") Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/r/202611060717.0Na5FqQR-lkp@intel.com/ Reported-by: Julia Lawall <julia.lawall@inria.fr> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-11-08ntfs: check the file name against the key length of an index entryWahid Khan
ntfs_index_entry_inconsistent() checks that the file name of a $FILE_NAME key fits in the index entry. It does not check that the name fits in the key, which is what key_length describes. Code that works on the key alone relies on that. ntfs_readdir() copies key_length bytes of the key of the next entry to resume the enumeration, and later uses the copy to search the index. If file_name_length is larger than the key holds, the name comparison reads past the copy: BUG: KASAN: slab-out-of-bounds in ntfs_file_compare_values+0x2d1/0x4b0 Read of size 2 at addr ffff88800a4ef2ce by task init/1 ntfs_file_compare_values ntfs_collate ntfs_ie_lookup ntfs_index_lookup ntfs_readdir iterate_dir Allocated by task 1: kmemdup_noprof ntfs_readdir The buggy address is located 0 bytes to the right of allocated 78-byte region Two bytes of an image from mkntfs are enough: in an entry whose name has six characters (key_length 78), change file_name_length from 6 to 7, so the key claims 80 bytes. The entry itself is 96 bytes, so the existing check lets it pass. The next readdir of the directory reads the extra bytes. Check the name against key_length, and check that the key is large enough to hold file_name_length in the first place. Fixes: 0a8ac0c1fa0b ("ntfs: update directory operations") Cc: stable@vger.kernel.org # v7.1+ Signed-off-by: Wahid Khan <wahidzk0091@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-11-08ntfs: fix out-of-bounds write race in NTFS_IOC_LIST_STREAMSXingyuan Mo
NTFS_IOC_LIST_STREAMS walks the base inode's MFT attributes twice: a first pass sizes the output buffer, a second pass fills it, both times filtering out streams that ntfs_stream_unlinked() reports as unlinked. That filter is the culprit: it treats a stream inode that is no longer in the inode hash as live, which is precisely the state a stream being deleted ends up in. When a base file is deleted while one of its named streams is still open, ntfs_cleanup_deleted_inode() sets NInoStreamUnlinked on the stream inode and removes it from the inode hash after dropping the MFT record lock. Nothing serializes this against the ioctl's two passes, so if the flag and the unhash land between them, the first pass excludes the stream while the second pass includes it, and the ioctl writes an entry the allocation never accounted for. The per-entry bounds check cannot catch this divergence, because "offset > required - entry_size" underflows when entry_size exceeds required. With a 1-character stream sizing the buffer at 48 bytes and a 250-character stream surfacing only in the second pass, a 544-byte entry is written into the 48-byte kmalloc-64 allocation. Close the hole in two steps: - Reject base inodes that are being deleted before walking their attributes, like the other named stream entry points in this file already do. This also stops the listing from reporting streams of a deleted base file as live, which is reproducible even without the race. - Make the bounds check underflow-safe so any remaining divergence between the passes can only produce -EOVERFLOW, never an out-of-bounds write. KASAN report from the reproducer (timestamps stripped): BUG: KASAN: slab-out-of-bounds in ntfs_ioctl_list_streams+0x7a9/0xa00 Write of size 500 at addr ffff88800b1931a8 by task ntfs_ads_race/305 CPU: 2 UID: 0 PID: 305 Comm: ntfs_ads_race Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0x73/0xb0 print_report+0xd1/0x610 kasan_report+0xff/0x130 kasan_check_range+0x10c/0x1c0 __asan_memcpy+0x3f/0x70 ntfs_ioctl_list_streams+0x7a9/0xa00 ntfs_ioctl+0x3b6/0x420 __x64_sys_ioctl+0xd1/0x120 x64_sys_call+0x2a5/0x2220 do_syscall_64+0x109/0x5e0 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK> Allocated by task 305: kasan_save_stack+0x3d/0x60 kasan_save_track+0x18/0x40 kasan_save_alloc_info+0x3b/0x50 __kasan_kmalloc+0x9c/0xa0 __kvmalloc_node_noprof+0x2dd/0x800 ntfs_ioctl_list_streams+0x57f/0xa00 ntfs_ioctl+0x3b6/0x420 __x64_sys_ioctl+0xd1/0x120 x64_sys_call+0x2a5/0x2220 do_syscall_64+0x109/0x5e0 entry_SYSCALL_64_after_hwframe+0x77/0x7f The buggy address belongs to the object at ffff88800b193180 which belongs to the cache kmalloc-64 of size 64 The buggy address is located 40 bytes inside of allocated 48-byte region [ffff88800b193180, ffff88800b1931b0) Fixes: 48996054b706 ("ntfs: add named stream ioctls support") Signed-off-by: Xingyuan Mo <hdthky0@gmail.com> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
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-11-02ntfs: don't allow compression on volumes with clusters larger than 4KZhan Xusheng
On a volume made with "mkntfs -c 8192", a user can set FILE_ATTR_COMPRESSED on an empty file through system.ntfs_attrib. Writing to the file and reading it back after dropping the page cache then crashes: BUG: KASAN: slab-out-of-bounds in ntfs_read_compressed_block+0xa2c/0x2040 Read of size 8192 at addr ffff88804355a000 by task dd/106 The read path only handles clusters up to 4K. It copies each cluster out of a single page, and a compression block of 16 8K clusters does not fit in the 64K ntfs_compression_buffer. Loading an inode already rejects compressed data on such volumes. Reject the flag change the same way. Fixes: fc053f05ca28 ("ntfs: add reparse and ea operations") Cc: stable@vger.kernel.org Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-11-02ntfs: don't allow resident values to overlap the attribute headerNamjae Jeon
The resident value bounds check allows value_offset to point inside the attribute header. The reported image has an unnamed $DATA attribute with a value_offset of zero and a value_length of two, which passes lookup. Appending to this file makes ntfs_resident_attr_value_resize() shrink the attribute record to eight bytes. Moving the following attributes then overwrites the resident header fields, so the subsequent memset() uses a corrupted value_offset and writes outside the MFT record buffer. Require the resident value to start after the complete resident header. Both lookup paths then return -EIO for the corrupt record, before callers can resize or access its value. Fixes: 495e90fa3348 ("ntfs: update attrib operations") Reported-by: Robert Morris <rtm@mit.edu> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-29ntfs: fix a self-deadlock on writes to non-resident named streamsHongling Zeng
The stream write ioctl holds the stream mapping's invalidate lock across ntfs_inode_attr_pwrite(), which calls ntfs_extend_initialized_size() for named streams, and that function takes the same lock again, before the check that could skip the extension. A write to a non-resident named stream through NTFS_IOC_STREAM_WRITE deadlocks on itself. The ioctl is the only caller that reaches the named stream branch of ntfs_inode_attr_pwrite(), and it always holds the lock there, so split off __ntfs_extend_initialized_size(), which expects the caller to hold the invalidate lock, and call it from that branch. The write and mmap paths keep taking the lock themselves. Fixes: 3f11c48d4f94 ("ntfs: add pathname access for named streams") Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-29ntfs: keep the file size on a failed initialized-size extensionHongling Zeng
ntfs_extend_initialized_size() only extends the initialized size and never changes the data size, but on a failure it calls truncate_setsize() with the old initialized size, which shrinks the VFS size down to it and drops the page cache beyond that point. None of the callers rolls the shrunk size back. A buffered write into a hole has nothing to roll back - the data size never changed - so the file keeps the shrunk size even though the data size on disk is intact. The mmap and named stream callers return without any rollback either. The sizes did not change, so nothing needs the shrink. Remove it. Fixes: af0db57d4293 ("ntfs: update inode operations") Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-29ntfs: avoid overflow when limiting attribute read lengthHyunchul Lee
ntfs_inode_attr_pread() limits a read to the attribute size using pos + count. A large count can overflow the signed sum and bypass the attribute EOF boundary check. Compare count with isize - pos instead, after validating pos, so the read length limit cannot wrap. Fixes: af0db57d4293 ("ntfs: update inode operations") Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-29ntfs: initialize VCN when inserting index entriesHyunchul Lee
When a leaf index entry is promoted during a split, ntfs_ih_insert() extends a copied entry with the NODE VCN field. Initialize that field before copying the new entry into the parent index. The promoted entry must reference the old child VCN, while the existing parent entry is updated to reference the newly allocated right child. Fixes: 0a8ac0c1fa0b ("ntfs: update directory operations") Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-29ntfs: reject negative attribute read positionsHyunchul Lee
A corrupt index entry can produce a VCN whose byte offset overflows. Reject negative positions before they reach pointer arithmetic in ntfs_inode_attr_pread(). Fixes: 0a8ac0c1fa0b ("ntfs: update directory operations") Reported-by: Robert Morris <rtm@mit.edu> Link: https://lore.kernel.org/ntfs/10091.1793100344@localhost/ Signed-off-by: Hyunchul Lee <hyc.lee@gmail.com> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-27ntfs: Fix error handling in __ntfs_create()Bart Van Assche
In __ntfs_create(), if ntfs_init_acl() fails before ntfs_mft_record_alloc() is called, jumping to err_out frees MFT record 0 ($MFT), unmaps an unmapped record and unlocks the unheld &dir_ni->mrec_lock and &ni->mrec_lock mutexes. Call iput(vi) and return ERR_PTR(err) directly instead, matching the ntfs_mft_record_alloc() failure path right below it. Fixes: af0db57d4293 ("ntfs: update inode operations") Signed-off-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-23ntfs: handle a failed size rollback in the write error pathHongling Zeng
ntfs_file_write_iter() extends the data and initialized sizes before it copies the user data and restores them when the write then fails. The restoration is best-effort: both results are discarded, even though the extension is already recorded in the dirty MFT record. When the restoration fails too, the extended sizes reach the disk while the VFS inode keeps reporting the old ones: after a remount the file appears grown again, with an uninitialized tail where the failed write never put any data, and nothing records the failure. Keep both undo results: roll the initialized size back first, and roll the data size back only when that rollback succeeded. The data rollback goes through the same VFS-facing truncate ntfs_setattr_size() uses, which also supports compressed attributes, and keeps the VFS size on the durable data size when it fails. Its shrink clamps the initialized size to the rolled-back data size, which can sit above the old initialized size, so a failed initialized size rollback would leave the clamp in place and expose the uninitialized tail. The undo runs under the mapping invalidate lock, like ntfs_setattr_size(), which the truncate expects. On an undo failure, set NVolSetErrors(), which the next persistence point persists as VOLUME_IS_DIRTY, and log a message for the errors= policy. Fixes: 9c87959601e8 ("ntfs: update file operations") Suggested-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-22ntfs: fix u16 truncation of the update sequence array count checkZhan Xusheng
ntfs_check_restart_page_header() bounds the on-disk system page size by recomputing the update sequence array count from it: u16 ra_ofs, usa_count, usa_ofs, usa_end = 0; ... usa_count = 1 + (logfile_system_page_size >> NTFS_BLOCK_SIZE_BITS); if (usa_count != le16_to_cpu(rp->usa_count)) return false; The right hand side is computed in u32 but stored in a u16, so the count wraps once the system page size reaches 0x2000000. An image claiming any larger power of two passes the check by also claiming usa_count == 1. Nothing else limits the value, so ntfs_check_and_load_restart_page() goes on to kvzalloc() up to 2 GiB for the restart page and copy that many bytes a page at a time. The size is only rejected afterwards, by the (size >> NTFS_BLOCK_SIZE_BITS) != usa_count test in post_read_mst_fixup(). Compute the count in a u32 so the existing check rejects an over-large system page size instead of being defeated by the truncation. This adds no new limit: the array holds one u16 per protected sector plus the update sequence number and must end within the first sector, which caps usa_count at 240 and the system page size at 64 KiB. Widen ra_ofs and usa_ofs as well, as ntfs_check_restart_area() already does: both are loaded from __le16 on-disk fields and every comparison is against a non-negative value, so no result changes. Fixes: 1e9ea7e04472 ("Revert "fs: Remove NTFS classic"") Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-22ntfs: reject index blocks with a too small entries offsetHang Nan
Index blocks read from the volume are checked for a plausible header, but nothing keeps a block from placing its entries closer to the header than ntfs_ib_alloc() does when it creates one. The allocation adds the update sequence array, one entry per 512-byte sector plus the terminator, to the index header and aligns the result to 8 bytes, so the first entry of a 4096-byte block starts at offset 40, while a corrupt block may declare 16. ntfs_ib_copy_tail() then copies the entries that follow the median entry from the source block into a freshly allocated destination. The tail is sized as index_length minus entries_offset and the median entry, both from the source, while the destination only has allocated_size minus the canonical offset of room. With the values above the tail is 4040 bytes and the destination holds 4032, so the last 8 bytes are written past the end of the new allocation, with contents taken from the mounted image. Reject such a block when it is read: entries_offset must not be smaller than the canonical offset for the block size. Derive it from block_size rather than from the block's own usa_count, which post_read_mst_fixup() treats as "not protected" when it does not match the block size, and use the same helper in ntfs_ib_alloc() so both stay in sync. Fixes: 0a8ac0c1fa0b ("ntfs: update directory operations") Signed-off-by: Hang Nan <2122295973@qq.com> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: support persistent noatime attributeXuewen Wang
NTFS currently rejects FS_NOATIME_FL in its fileattr setter. This prevents users from disabling automatic access-time updates on individual files or directories with chattr +A. Store noatime in bit 3 of the private $LINUXFLAGS EA and restore S_NOATIME when loading an inode. Report and accept FS_NOATIME_FL in the fileattr callbacks, updating the in-memory flag only after the EA update succeeds. The VFS then suppresses automatic atime updates for the inode, while chattr -A restores the mount's atime policy. Document the new on-disk bit and that newly created children do not inherit the attribute. Suggested-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Xuewen Wang <wangxuewen@kylinos.cn> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: roll back the ACL xattr commit when the WSL mode update failsHongling Zeng
ntfs_set_acl_ex() commits the ACL xattr before it rewrites the WSL mode EA, and removes it again when the rewrite fails. That only undoes a set that created the xattr: when the update replaced or removed an existing one, the old ACL is discarded along with the failed update. No error is recorded when the undo fails, so the new, typically more permissive, ACL is left on disk while i_mode, the mode EA and the cached ACL keep the old values. After a remount, a chmod 0640 -> 0777 that reported failure leaves the file accessible to the relaxed ACL while stat() still reports 0640. Save the previous xattr before committing the update, and restore it when the mode EA rewrite fails. A removed xattr is created again, since XATTR_REPLACE fails with -ENODATA once the removal dropped the entry. Remove the new xattr only when there was no previous one, and skip the undo when the commit changed nothing. A failed rollback is recorded: NVolSetErrors(), which the next persistence point persists as VOLUME_IS_DIRTY, and a log message the errors= policy acts on. The flag cannot be written to disk here directly: the target inode's mrec_lock is held and the $Volume mrec_lock cannot be nested under it. Fixes: fc053f05ca28 ("ntfs: add reparse and ea operations") Cc: stable@vger.kernel.org Suggested-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: report birth time for symbolic linksXuewen Wang
NTFS already loads the creation time into i_crtime and reports it through ntfs_getattr(). However, the symbolic-link inode operations omit getattr, so statx() with AT_SYMLINK_NOFOLLOW falls back to generic_fillattr() and does not return STATX_BTIME for the link itself. Use ntfs_getattr() for symbolic links to expose their stored creation time. Signed-off-by: Xuewen Wang <wangxuewen@kylinos.cn> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: support FS_IOC_GETFSUUIDBaolin Liu
NTFS reads the 64-bit volume serial number from the boot sector but leaves the superblock UUID unset. As a result, the generic FS_IOC_GETFSUUID handler returns ENOTTY for files and directories on an NTFS volume. Register the on-disk little-endian serial number as an eight-byte filesystem identifier with super_set_uuid(). The generic VFS handler can then expose the existing volume identifier. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: flush the block device when syncing a directoryDaeMyung Kang
ntfs_dir_fsync() writes directory metadata and calls sync_blockdev(), but does not flush the block device write cache. A successful fsync() can therefore leave the directory's metadata in a volatile device cache. Issue a cache flush after successful writeback and return any flush error. This matches the regular-file fsync and syncfs paths. With QEMU blkdebug injecting -EIO for flush_to_disk, fsync() on an NTFS directory returned 0 before this change while syncfs() returned -EIO. After this change, both return -EIO. A kretprobe confirmed the flush error in the directory fsync path. Fixes: 1e9ea7e04472 ("Revert "fs: Remove NTFS classic"") Cc: stable@vger.kernel.org Signed-off-by: DaeMyung Kang <charsyam@gmail.com> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: report block device flush failures from fsyncDaeMyung Kang
ntfs_file_fsync() calls blkdev_issue_flush() after writeback but discards its return value. If the device cannot flush its write cache, fsync() reports success even though the file is not guaranteed to be durable. Reproduce this with QEMU blkdebug failing flush_to_disk with -EIO. On ntfs-next at 04fb910da2c8, a kretprobe recorded -EIO from blkdev_issue_flush() while fsync() returned 0. With this change, fsync() returns -EIO and logs the failure. The syncfs() path already reports this error. Fixes: 9c87959601e8 ("ntfs: update file operations") Cc: stable@vger.kernel.org Signed-off-by: DaeMyung Kang <charsyam@gmail.com> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: fix NULL dereference on index allocation open failureNamjae Jeon
ntfs_index_lookup() returns -ENOENT when ntfs_ia_open() fails to open the index allocation. This error path leaves icx->ib unset, unlike a missing key in an otherwise valid index, which returns an insertion context. ntfs_ie_add() treats -ENOENT as a valid insertion position and dereferences icx->ib when the lookup is not in the index root. A corrupt $I30 bitmap attribute can therefore cause a NULL pointer dereference when adding a directory entry. Return -EIO for index allocation open failures so insertion aborts through the existing error path. Keep -ENOENT for genuinely missing keys and document that other errors leave no valid index entry. Fixes: 0a8ac0c1fa0b ("ntfs: update directory operations") Reported-by: 1sh1ro <yangguikun19@qq.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: compare streams_interface with mounted volume on remountDaeMyung Kang
During reconfiguration, fc->s_fs_info points to a newly allocated ntfs_volume. It does not contain the mounted volume's stream setting. Consequently, a windows mount rejects a remount with the same streams_interface=windows setting, but accepts streams_interface=none without changing the active pathname interface. This also breaks an ordinary read-only remount when the existing windows setting is passed again, for example from fstab. Compare the requested setting with the mounted volume instead. Report an unsupported change with ntfs_warning() so it does not invoke the mounted filesystem's error-handling policy. Fixes: 2de2cdd9cc08 ("ntfs: add pathname access for named streams") Signed-off-by: DaeMyung Kang <charsyam@gmail.com> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: widen the sub-block offsets in ntfs_decompress()Zhan Xusheng
ntfs_decompress() tracks where the current sub-block starts and ends inside the destination page with two u16s: u16 do_sb_start; u16 do_sb_end; ... do_sb_start = *dest_ofs; do_sb_end = do_sb_start + NTFS_SB_SIZE; *dest_ofs is an int page offset masked with ~PAGE_MASK, and NTFS_SB_SIZE is 0x1000, so do_sb_end needs PAGE_SIZE + 0xfff of range. That exceeds u16 once PAGE_SIZE reaches 0x10000: the last sub-block of a page starts at 0xf000 and do_sb_end wraps from 0x10000 to 0. The zero-fill that pads a short sub-block then computes a negative length: if (dp_addr < dp_sb_end) { int nr_bytes = do_sb_end - *dest_ofs; memset(dp_addr, 0, nr_bytes); A sub-block made only of symbol tokens reaches this without consulting do_sb_end on the way, because that path just does *dp_addr++ = *cb++; ++*dest_ofs; and is bounded by dp_addr against dp_sb_end. With do_sb_start at 0xf000 and eight literal bytes emitted, nr_bytes is -61448 and the memset() runs for 18446744073709490168 bytes. Getting there is cheap: fifteen sub-blocks of eleven bytes each advance *dest_ofs to 0xf000, since the same zero-fill pads each of them out to 0x1000 while do_sb_end is still exact, and the sixteenth one triggers the wrap. A compression block is 0x10000 bytes with 4 KiB clusters and the fixed compression unit of 4, so all sixteen fit with room to spare. Phrase tokens are bounded against do_sb_end and so return -EOVERFLOW instead, and the if (*dest_index == dest_max_index && do_sb_end > dest_max_ofs) check at the top of the sub-block stops firing for the same reason. Use int for both, matching *dest_ofs and dest_max_ofs. The narrow type came in with the original import and survived the removal and revert of the driver. Fixes: 1e9ea7e04472 ("Revert "fs: Remove NTFS classic"") Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: reject direct I/O reads of encrypted filesZhan Xusheng
ntfs_file_read_iter() refuses direct I/O for compressed and WOF compressed attributes but lets encrypted ones reach iomap_dio_rw(). ntfs_read_iomap_begin_non_resident() has no NInoEncrypted() test, so it reports IOMAP_MAPPED for the attribute's real clusters and the raw on-disk ciphertext is copied to the caller. Buffered reads are refused by ntfs_read_folio(), but direct I/O never calls it. Fixes: 9c87959601e8 ("ntfs: update file operations") Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: do not read ahead encrypted filesZhan Xusheng
ntfs_read_folio() refuses EFS-encrypted files with -EOPNOTSUPP because decryption is not implemented. ntfs_readahead() has no NInoEncrypted() test and passes them to iomap_readahead(), which maps the runlist and fills the folios with the raw on-disk ciphertext. The folios are marked uptodate, so the read that follows never reaches ->read_folio and returns ciphertext instead of -EOPNOTSUPP. ntfs_read_locked_inode() sets NInoEncrypted() and NInoNonResident() for a non-resident encrypted $DATA attribute and rejects the encrypted-and-compressed combination, so none of the three existing conditions fires. read(), mmap(), splice() and fadvise() all populate the page cache through readahead. Skipping readahead leaves the folio unpopulated, so the read falls back to ntfs_read_folio() and gets the intended error. Fixes: b041ca562526 ("ntfs: update iomap and address space operations") Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com> Reviewed-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: persist nodump in the $LINUXFLAGS EABaolin Liu
Store nodump in bit 2 of LINUXFLAGS and allow it through fileattr_set. Report the cached persistent bit through fileattr_get and STATX_ATTR_NODUMP, including the statx supported-attribute mask. Reuse the existing EA update and inode-load paths; nodump needs no additional inode flag enforcement. Document the complete immutable, append-only and nodump bitmask. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: persist append-only in the $LINUXFLAGS EABaolin Liu
Extend the persistent fileattr interface to append-only using bit 1 of LINUXFLAGS. Restore S_APPEND on inode load and update it after successful EA writes. Include append in the known-bit mask while retaining all other unknown bits. Reuse the existing VFS capability checks and EA safeguards. Document append-only alongside immutable. Both flags now survive inode reclaim and remount without changing the NTFS attribute format. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: persist immutable in the $LINUXFLAGS EABaolin Liu
Add a fileattr setter for immutable and store its state in bit 0 of a little-endian u32 in the private $LINUXFLAGS EA. Reuse the standard NTFS EA attributes and restore the flag when loading an inode, so eviction and unmount do not discard the setting. Use $LINUXFLAGS to avoid the WSL-owned $LX namespace. Preserve unknown bits and delete the entry only when the entire value is zero. Reject malformed values with EUCLEAN. Reject direct xattr writes and removal to avoid bypassing fileattr permissions or stale cached state. Update the cached flags only after the EA update succeeds. Reject clearing immutable on system metadata files and files protected by sys_immutable, following inode-load policy. Do not persist a bit derived solely from this policy. Preserve append state without allowing it to be changed at this stage. Compression, encryption and mount-wide case folding remain read-only. Document the format and its Linux-only enforcement. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: add fileattr query supportBaolin Liu
Add fileattr_get operations for files and directories, as well as the existing symlink and special inode operation tables. Report compression, encryption, immutable and append-only from cached inode state, and FS_CASEFOLD_FL from the mount-wide case sensitivity policy. This introduces querying only. It neither reads a private flag EA nor allows userspace to change the reported flags. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: restore EA attributes when an update failsBaolin Liu
Creating or replacing an EA can leave EA data and information out of sync if a later update fails. Existing deletion rollback ignores its own errors, and creation changes metadata before preparing the new list. Prepare the complete new list while retaining both original attributes. Update EA data and information only after preparation succeeds, restore both on failure, and publish the cached presence state only on success. Keep structure errors as EUCLEAN and preserve operation errors. Mark the volume erroneous and shut it down if either restoration fails. This handles synchronous failures; it does not make the two updates atomic across power loss or guarantee restoration on a failing device. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: distinguish empty EA values from removalBaolin Liu
The EA setter identifies removal using a zero value length together with XATTR_REPLACE. A replacement with a valid empty value is therefore mistaken for deletion. Use a NULL value to identify removal and keep zero-length values valid. Reject removal or XATTR_REPLACE for an absent entry before creating metadata, including when the file has no EA attributes. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: preserve EA attribute lookup errorsBaolin Liu
ntfs_attr_exist() treats lookup failures as absence. Using it while updating EAs can select creation or removal paths after an allocation or I/O failure. Use an EA-local lookup helper that preserves errors from mapping the MFT record, allocating the search context and looking up the attribute. Check both EA attributes before modifying either and return EUCLEAN if only one exists. Keep the known presence state for the final update. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: propagate EA write and truncate errorsBaolin Liu
ntfs_write_ea() replaces negative write errors with EIO and ignores errors when shrinking the attribute after writing a shorter list. This can report success even though the final resize failed. Preserve negative write errors, use EIO for short writes, and return truncate failures to the caller. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: validate EA chains and link zero-terminated tailsBaolin Liu
A zero next-entry offset terminates an EA list. Appending an entry without linking the old tail makes the new entry unreachable. Invalid entries are also treated as missing names, allowing setters to proceed on corrupt metadata. Validate the entire chain before modifying it and connect a zero tail to the append position. Check name terminators and retain the full tail span when removing an entry. Return EUCLEAN for malformed EA structures and inconsistent information lengths, preserving that error through the get, set and list paths. Keep ENOENT for a missing name and translate it to ENODATA only at the xattr read boundary. Preserve lower-level read errors. Reuse the same full-chain validation in ntfs_listxattr(), including size-only queries, before copying names. Reject malformed lists with EUCLEAN instead of returning an empty or partial list. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: keep the EA presence flag after creating the first entryBaolin Liu
The successful EA update path tests ea_info_qsize when updating NInoHasEA, but this size excludes the appended entry. Creating the first EA, or replacing the only entry, can therefore clear the cached presence flag despite a successful update. Reads then return ENODATA until reload. Include the appended entry in the size used for the presence test. Signed-off-by: Baolin Liu <liubaolin@kylinos.cn> Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: add pathname access for named streamsNamjae Jeon
Add an optional Windows-style pathname interface for named $DATA streams, enabled with streams_interface=windows. The option defaults to none, and the named-stream ioctls remain available regardless of this setting. Support lookup, creation, and removal of named streams for existing regular files and directories. A stream is opened as a regular file through the base-name and stream-name form in the final path component. A stream can be created only for an existing file or directory. The pathname interface accepts a base file name and stream name only. It rejects paths that also specify an NTFS attribute type such as $DATA. In windows mode, ordinary filenames containing a colon are hidden from directory listings and cannot be accessed through the pathname interface. Match stream names case-insensitively. Streams and their base objects report the same inode number. Removing the base object while a stream is open detaches the stream from the namespace. Since NTFS has no orphan-stream list, a crash can leave the stream data unreachable on disk. Expose named streams as regular file descriptors for the file operations requested by Wine, including read, write, fsync, fdatasync, sync_file_range, file locking, mmap, futimes, fstat, ftruncate, SEEK_DATA, SEEK_HOLE, fallocate, and pathname unlink. Stream timestamps are shared with the base file. fstat reports the base metadata and inode number with the stream's own size and allocation. Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: add named stream ioctls supportNamjae Jeon
NTFS supports multiple named $DATA attributes, commonly known as alternate data streams. Add NTFS-specific ioctls to list, read, write, and remove named streams through an opened base file or directory. The UAPI provides separate commands for each operation. - NTFS_IOC_STREAM_READ - NTFS_IOC_STREAM_WRITE - NTFS_IOC_STREAM_REMOVE - NTFS_IOC_LIST_STREAMS Read and write requests use struct ntfs_stream to specify the stream name, byte offset, and transfer length. Writes create the stream if it does not already exist. A write failure after creation may leave the new stream visible. It is not rolled back because another caller may already have opened it. Userspace can remove it with NTFS_IOC_STREAM_REMOVE. The list command returns variable-length entries containing each named stream's data size, allocated size, and name. If the buffer is too small, the command returns -ENOSPC without copying entries. bytes_returned reports the required buffer size, and stream_count reports the number of streams. Stream names use the mounted filesystem NLS by default. Set NTFS_STREAM_FL_UTF16 to pass or receive raw UTF-16LE names. In NLS mode, names that cannot be represented by the mounted character set are omitted from the list. Use UTF-16 mode for lossless enumeration. Read and write transfers are limited to 16 MiB per request. Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: propagate EA truncate errorsNamjae Jeon
Propagate errors from truncating an EA stream so callers do not report a successful xattr update after a failed resize. Fixes: fc053f05ca28 ("ntfs: add reparse and ea operations") Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
2026-10-20ntfs: clear stale pagecache on initialized-size extensionNamjae Jeon
iomap_zero_range() skips holes, so EOF-polluted cache data can survive gap zeroing. Discard the uninitialized cache range before advancing initialized_size so later reads cannot expose stale bytes. Perform the cleanup in ntfs_extend_initialized_size() so both file writes and shared writable mmap preparation use it. Hold the invalidate lock while reading initialized_size, clearing the cache, zeroing the gap, and updating the attribute. Release the lock on every exit path. Fixes: af0db57d4293 ("ntfs: update inode operations") Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>