ntfs3: symlink() fails with ENOENT when $Reparse reuses an index block in an unloaded $INDEX_ALLOCATION segment
Hi,
on one of my NTFS volumes, every symlink() started to fail with ENOENT, while creating regular files, directories and hard links kept working. The volume is consistent (ntfsfix -n on the unmounted device reports no problems), remounting does not help, and nothing is logged to dmesg. It is reproducible from scratch on a freshly made image (script below).
Kernel: 7.3.0 (CachyOS 7.3.0-4; fs/ntfs3 identical to linux-7.3.y). The code path described below is unchanged in linux-next and in the Paragon devel tree as of 2026-10-29.
How it showed up
----------------
Proton (Steam's Wine) builds each game prefix out of ~1350 symlinks. After a dozen prefixes had been created and some deleted on the volume, building a new prefix died partway through with:
os.symlink(...) -> FileNotFoundError: [Errno 2] No such file or directory
At that point $Extend/$Reparse held ~15k entries, and its $INDEX_ALLOCATION was split over two MFT records via $ATTRIBUTE_LIST (records 26 and 111941 in ntfsinfo -F '/$Extend/$Reparse').
Where the ENOENT comes from
---------------------------function_graph trace (funcgraph-retval) of a failing symlink(), cut down to the relevant calls:
ntfs_create_inode() {
ntfs_insert_reparse() {
indx_insert_entry() {
indx_insert_into_buffer() {
indx_add_allocate() {
ni_find_attr() {
ni_find_attr() {
} /* indx_add_allocate ret=0x0 */
indx_new() {
ntfs_get_bh() {
run_lookup_entry(); /* ret=0x0 */
} /* ntfs_get_bh ret=-2 */
} /* indx_new ret=-2 */
} /* indx_insert_into_buffer ret=-2 */
} /* indx_insert_entry ret=-2 */
} /* ntfs_insert_reparse ret=-2 */
} /* ntfs_create_inode ret=-2 */indx_add_allocate() finds a free bit in the $R bitmap that lies within the existing allocation ("Reuse index." branch, so attr_set_size() is not called). indx_new() then calls ntfs_get_bh() on indx->alloc_run for that VBN. The runs for that part of $INDEX_ALLOCATION live in an extension record and have never been loaded into alloc_run, so run_lookup_entry() fails and ntfs_get_bh() returns -ENOENT.
indx_read() handles exactly this case: on -ENOENT from ntfs_read_bh_ra() it calls attr_load_runs_range() for the block and retries. indx_new() has no such fallback.
Reproducer
----------
Needs root, mkntfs (ntfs-3g) and python3; uses a 2 GiB sparse image.
1. mkntfs a 2 GiB image, mount it with ntfs3.
2. Create 40000 symlinks, writing an 8 KiB file after every 40 so that the $R allocation gets fragmented and spills into extension records.
3. Delete 20000 of those symlinks (frees $R index blocks), umount.
4. Mount again and create symlinks: ENOENT.
On my machine step 4 fails at the same symlink (#14940) in two runs from scratch. Without step 3 (no freed blocks) or without the remount (runs are still in memory), I could not trigger it.
---- repro.sh ----
#!/bin/sh
# ntfs3: symlink() fails with ENOENT once $Extend/$Reparse:$R reuses a freed
# index block whose runs are not loaded (indx_new -> ntfs_get_bh).
# Needs: root, mkntfs (ntfs-3g), python3.
# Uses a 2 GiB sparse image in $1 (default: cwd).
set -eu
dir=$(realpath "${1:-.}")
img=$dir/ntfs3-reparse.img
mnt=$dir/ntfs3-reparse.mntfill() { # fill <dir> <count>: <count> symlinks, an 8 KiB file after every 40
python3 - "$1" "$2" <<'EOF'
import errno, os, sys
d, n = sys.argv[1], int(sys.argv[2])os.makedirs(d + "/l", exist_ok=True); os.makedirs(d + "/s", exist_ok=True) for i in range(n):
try:
os.symlink("/nonexistent", f"{d}/l/{i:06d}")
except OSError as e:
print(f"symlink #{i} in {d}: {errno.errorcode[e.errno]}"); sys.exit(1)
if i % 40 == 39:
open(f"{d}/s/{i:06d}", "wb").write(b"\0" * 8192)print(f"{n} symlinks in {d}: ok")
EOF
}
truncate -s 2G "$img"
mkntfs -F -Q -L repro "$img" >/dev/null 2>&1 loop=$(losetup --find --show "$img")
mkdir -p "$mnt"
trap 'umount "$mnt" 2>/dev/null; losetup -d "$loop"' EXIT
mount -t ntfs3 "$loop" "$mnt"
# Grow $R until its $INDEX_ALLOCATION spills into extension records. fill "$mnt/a" 40000
# Free some $R index blocks.
find "$mnt/a/l" -name '0[01]*' -delete
umount "$mnt"
# After remount, $R runs are loaded lazily.
mount -t ntfs3 "$loop" "$mnt"
uname -r
# Expected: ENOENT (here: at symlink #14940).
fill "$mnt/b" 20000
---- end ----
Suggested fix (untested: not compiled or run, only checked that it applies to linux-7.3.y with offset -3). It mirrors the indx_read()
fallback: on -ENOENT from ntfs_get_bh(), load the runs with attr_load_runs_range() under indx->run_lock and retry.
fs/ntfs3/index.c +15 -0
@@ -987,6 +987,21 @@ } err =ntfs_get_bh (ni->mi.sbi, &indx->alloc_run, vbo, bytes, &r->nb); +if (err == -ENOENT ) { +/* +* A reused block may lie in an $INDEX_ALLOCATION segment whose +* runs have not been loaded yet. Load them, as indx_read() does. +*/ +const struct INDEX_NAMES *in = &s_index_names[indx->type]; + +down_write (&indx->run_lock); + err =attr_load_runs_range (ni,ATTR_ALLOC , in->name, in->name_len, + &indx->alloc_run, vbo, vbo + bytes); +up_write (&indx->run_lock); +if (!err) + err =ntfs_get_bh (ni->mi.sbi, &indx->alloc_run, vbo, + bytes, &r->nb); + }if (err) {kfree (index);
I have not checked whether a failed symlink() leaves anything behind (MFT record, directory entry). Large directories ($I30) go through indx_new() too and may hit the same path, but I have not tried to reproduce that.
I can test a patch on the reproducer image if that helps.
Thanks,
Maciej
PATCH 1/1 fs/ntfs3: fix ENOENT in indx_new() for blocks with unloaded runs
indx->alloc_run is filled on demand, one $INDEX_ALLOCATION segment at a time. When the attribute is split over several MFT records (via $ATTRIBUTE_LIST), a segment none of whose blocks has been read since the inode was loaded may have no runs in alloc_run. indx_read_ra() handles
this: when ntfs_read_bh_ra() fails with -ENOENT, it loads the runs with attr_load_runs_range() and retries.
indx_new() has no such fallback. When indx_add_allocate() takes a free bit from the index bitmap that lies inside the existing allocation, the allocation is not extended and nothing loads the runs for that block. ntfs_get_bh() in indx_new() then fails with -ENOENT, and so does the insert that needed the new index block.
This was hit on $Extend/$Reparse, which gets an entry for every symlink. After many symlinks had been created and some deleted, and the volume remounted, symlink() started to fail with ENOENT and kept
failing: the bit is marked used only after indx_new() succeeds, so indx_find_free() returned the same free bit every time.
ntfs_create_inode
ntfs_insert_reparse
indx_insert_entry
indx_insert_into_buffer
indx_new
ntfs_get_bh <- -ENOENT
Creating regular files and directories, which add no $Reparse entry, kept working. Other indexes, including $I30 of large directories, go through the same indx_new() path.
Load the missing runs in indx_new() the same way indx_read_ra() does and retry ntfs_get_bh().
The missing fallback was found with an AI assistant comparing indx_new() with indx_read_ra() (see Assisted-by).
---
Notes:
The code change is the same as the untested diff in the report (only the comment now names indx_read_ra()); it is now tested.
Tested on the ntfs3 devel tree (ee1cb3443cff) in a virtme-ng VM, with lockdep and KASAN enabled, using the reproducer from the report:
- without this patch, symlink #14940 fails with ENOENT. The failed symlink() leaves nothing behind: after a remount b/l holds exactly the 14940 symlinks created before it.
- with it, all 20000 symlinks are created. After another remount all of them read back correctly and can be deleted; ntfsinfo (ntfs-3g) then counts 20332 entries in $Extend/$Reparse:$R, i.e. the 20000 remaining a/l symlinks plus one end entry per INDX block (332). ntfsfix -n reports no problems and there are no KASAN reports.
In this tree the reproducer's readdir (find -delete) trips the known "bad unlock balance in ntfs_readdir" (syzbot; "[PATCH v2] fs/ntfs3: fix double ni_unlock() in ntfs_readdir()"), which turns lockdep off before the indx_new() path runs. So I repeated the patched run without any readdir, deleting the symlinks by name: debug_locks stayed 1 for the whole run, there were no lockdep or KASAN reports, and a function trace showed attr_load_runs_range() being called from indx_new(), i.e. the new fallback ran.
The failure in the report comes from indx_insert_into_buffer(); the indx_insert_into_root() caller and $I30 directories were not specifically tested.
Starting from the function_graph trace I collected, an AI assistant located the missing fallback by comparing indx_new() with indx_read_ra(), and drafted the fix and this changelog. I have reviewed and tested them.
fs/ntfs3/index.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
fs/ntfs3/index.c +17 -0
@@ -987,6 +987,23 @@ static struct indx_node *indx_new(struct ntfs_index *indx, } err =ntfs_get_bh (ni->mi.sbi, &indx->alloc_run, vbo, bytes, &r->nb); +if (err == -ENOENT ) { +/* +* A reused block may lie in an $INDEX_ALLOCATION segment +* whose runs are not loaded yet. Load them, as +* indx_read_ra() does. +*/ +const struct INDEX_NAMES *in = &s_index_names[indx->type]; + +down_write (&indx->run_lock); + err =attr_load_runs_range (ni,ATTR_ALLOC , in->name, + in->name_len, &indx->alloc_run, vbo, + vbo + bytes); +up_write (&indx->run_lock); +if (!err) + err =ntfs_get_bh (ni->mi.sbi, &indx->alloc_run, vbo, + bytes, &r->nb); + }if (err) {kfree (index);
base-commit: ee1cb3443cff5a800948b662756f75b17ca63fe2
Signature · 1 line
2.56.0