Skip to content

syscall: handle un-stat-able intermediate mount dirs in ona_open() - #1171

Open
seks99x wants to merge 1 commit into
RsyncProject:masterfrom
seks99x:fix-unstatable-intermediate-dir
Open

seks99x wants to merge 1 commit into
RsyncProject:masterfrom
seks99x:fix-unstatable-intermediate-dir

Conversation

@seks99x

@seks99x seks99x commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Fixes #1170

On Android (and certain FUSE/container mount setups), intermediate directories like /storage/emulated fail fstatat(AT_SYMLINK_NOFOLLOW) with ENOENT (via vfs_getattr) even though their VFS dentry exists and resolves during normal kernel path traversal (link_path_walk). Because ona_open() stats each component one by one before opening it, paths traversing /storage/emulated/0 fail prematurely with ENOENT.

Fix

When an intermediate component (!is_last) in ona_open() fails fstatat() with ENOENT, fall back to opening that single component directly via openat(dfd, comp, dir_traverse_flags | O_NOFOLLOW):

  • dir_traverse_flags (O_PATH | O_DIRECTORY on Linux) successfully holds the directory fd for traversal even when fstatat() fails on the intermediate mount root.
  • Keeps every *at() operation strictly single-component (comp never contains a '/'), preserving atomic O_NOFOLLOW and O_DIRECTORY enforcement with zero TOCTOU window.
  • Advances abspath via abspath_step() and enforces --confine-root / daemon confinement via abspath_outside_confinement().

Testing

testsuite/unstatable-intermediate-dir_test.py compiles a small Linux LD_PRELOAD interposer (fake_android_fuse.so) that returns ENOENT on fstatat for bare "emulated" or "*/emulated" while allowing openat() traversal through to "0":

  • Verifies deep paths (emulated/0/Documents), leaf paths (emulated/0), relative ./ walks, and trusted symlinks (/sdcard -> .../storage/emulated/0).
  • Verifies that missing children under "emulated" still fail with ENOENT, and that --files-from (the only one currently enforcing confinement here; src/dest confinement is fixed in Enforce --confine-root on destination/source paths and update confinement tests #1169) symlink escapes under --confine-root traverse "emulated/0" and fail with ELOOP (not ENOENT).

@seks99x
seks99x force-pushed the fix-unstatable-intermediate-dir branch from 088b927 to a9d5955 Compare November 13, 2026 20:32
@seks99x

seks99x commented Nov 13, 2026 •

Copy link
Copy Markdown
Member Author

I think this could be raced. No well parent-held fd and the path could be called relatively containing a / . I'll fix it.

@seks99x
seks99x force-pushed the fix-unstatable-intermediate-dir branch from a9d5955 to 5074f19 Compare November 13, 2026 20:56
@seks99x

seks99x commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

@kkrrz test please.

@kkrrz

kkrrz commented Nov 13, 2026

Copy link
Copy Markdown

@seks99x
Tested 5074f19 on Termux (Android 14, aarch64) without --insecure-links.
Local copy, cd + ./ destination, remote pull (user@server:/path/ -> /storage/emulated/0/Documents/),
and a copy into the Termux home directory all work:

$ ./rsync -v ~/t.txt /storage/emulated/0/Documents/
t.txt
sent 88 bytes  received 35 bytes  246.00 bytes/sec

$ cd /storage/emulated/0/Documents && ~/rsync-pr/rsync -v ~/t.txt ./
t.txt
sent 88 bytes  received 35 bytes  246.00 bytes/sec

Released 3.5.2 fails on these commands with change_dir#1 ... failed: No such file or directory (2) at /storage/emulated.

Note: in my local build, configure did not define SEARCH_ONLY_DIRFD_FLAG, so the walk fell back to
O_RDONLY|O_DIRECTORY and failed with EACCES opening / (same as #1050).
After adding #define SEARCH_ONLY_DIRFD_FLAG O_PATH to config.h (as in the Termux package build), all of the above succeed.
This seems specific to my ad-hoc configure run (I had to pass --build/--host manually), not to this PR.

Thanks for the fix!

@seks99x

seks99x commented Nov 14, 2026

Copy link
Copy Markdown
Member Author

Thanks for testing!

On Android, intermediate FUSE mount roots such as /storage/emulated fail
fstatat(AT_SYMLINK_NOFOLLOW) with ENOENT (via vfs_getattr) even though
their VFS dentry exists and resolves during path traversal.

When an intermediate component (is_last == 0) in ona_open() fails fstatat()
with ENOENT, fall back to opening the single component directly via
openat(dfd, comp, dir_traverse_flags | O_NOFOLLOW). Because O_PATH |
O_DIRECTORY | O_NOFOLLOW pins the VFS directory dentry without invoking
vfs_getattr(), it traverses un-stat-able intermediate mount points while
preserving atomic single-component O_NOFOLLOW/O_DIRECTORY checks,
abspath tracking, and confinement.
@seks99x
seks99x force-pushed the fix-unstatable-intermediate-dir branch 2 times, most recently from 62b98a9 to 0da0cbe Compare November 15, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[3.5.2] Android/Termux: destination under /storage/emulated/0 fails with ENOENT (intermediate path component not stat-able)

2 participants