Skip to content

fix: fake root hides only EPERM, EACCES and a masked ENOENT from utime calls - #57

Merged
oonid merged 5 commits into
mainfrom
fix/fake-root-utime-errors
Nov 8, 2026
Merged

oonid merged 5 commits into
mainfrom
fix/fake-root-utime-errors

Conversation

@oonid

@oonid oonid commented Nov 8, 2026

Copy link
Copy Markdown
Owner

What

Audit P8 and P4, in extension/fake_id0/fake_id0.c.

P8. Under fake root (euid 0), the exit handler for utimensat/utimes/futimesat/utime turned every error into 0. It exists so dpkg and tar can set times on link2symlink paths, where SELinux masks the result as ENOENT (important-notes.md, Failure 1). But EBADF, EINVAL, EROFS, ENOTDIR and the rest became success too: utimensat with invalid flags returned 0. Now utime_error_hidden() hides only EPERM, EACCES and an ENOENT for a target that exists. A real ENOENT for a missing target still reaches touch(1), and everything else passes through.

P4. utime_target_missing() accepted a read_string() result of exactly PATH_MAX, which can be a buffer without a NUL, then lstated it. It now rejects that, as the rest of proot does (>= PATH_MAX). A guest path that long fails translation with ENAMETOOLONG before this runs, so this is a guard rather than a reachable bug, and has no test of its own.

  • New fakeroot test 7: setting the times of an existing file succeeds; invalid flags give EINVAL, a closed fd EBADF, a relative path under a closed dirfd EBADF.
  • libproot.so rebuilt (NDK r27c); libpr-cli.so rebuilt to embed the test.
  • Docs: proot-improvement.md §28, important-notes.md, integration-tests.md, README and AGENTS.md (60 tests, 69 runs).

Tests

On an Android 17 device:

  • Red: with the proot from main, test 7 fails: utimensat with invalid flags: rc=0 errno=9, want errno 22.
  • Green: test 7 passes on Ubuntu 26.04 and Alpine.
  • Full suite from the app: 69/69 on both.
  • Unchanged for the cases the handler exists for: apt-get install and remove of a package in Ubuntu (dpkg sets times while unpacking), and touch creating a new file and updating an existing one.
  • Test binary: cargo clippy -D warnings and cargo fmt --check clean.

oonid added 5 commits November 8, 2026 10:21
A fakeroot test sets the times of an existing file, then expects
EINVAL for invalid flags, EBADF for a closed fd and EBADF for a
relative path under a closed dirfd. fake_id0's utime exit handler
turned every error into 0, so utimensat with bad flags succeeded.
Under fake root the utimensat/utimes/futimesat/utime exit handler
turned every error into 0, for dpkg and tar on link2symlink paths
where SELinux reports ENOENT. EBADF, EINVAL, EROFS, ENOTDIR and the
rest became success too. Only EPERM, EACCES and an ENOENT for a
target that exists are hidden now; other errors pass through, and a
real ENOENT for a missing target still reaches touch(1).
read_string returns PATH_MAX both for a string that fills the buffer
and for one cut off without a NUL; utime_target_missing accepted it
and could lstat an unterminated buffer. It now rejects it, as the
rest of proot does. A guest path that long fails translation with
ENAMETOOLONG first, so this guards rather than fixes a reachable bug.
@oonid
oonid merged commit 7ffb7a9 into main Nov 8, 2026
1 check passed
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.

1 participant