]> git.ipfire.org Git - thirdparty/rsync.git/commit
syscall: add symlink-race-safe do_*_at() wrappers and harden secure_relative_open
authorAndrew Tridgell <andrew@tridgell.net>
Tue, 5 May 2026 05:02:48 +0000 (15:02 +1000)
committerAndrew Tridgell <andrew@tridgell.net>
Wed, 20 May 2026 00:01:22 +0000 (10:01 +1000)
commit30656c5e358b1c6033f4caf24f3e11b29d25c9f4
tree65675eaa1cf87bb066982d7f76f6637d51b2bf44
parent15d296425609a997f56eb8f9017ff73922f99b20
syscall: add symlink-race-safe do_*_at() wrappers and harden secure_relative_open

Add the rest of the path-based syscall wrappers and migrate every
receiver-side caller:
  - do_lchown_at, do_rename_at, do_mkdir_at, do_symlink_at,
    do_mknod_at, do_link_at, do_unlink_at, do_rmdir_at,
    do_utimensat_at, do_stat_at, do_lstat_at

Same shape as do_chmod_at: open each parent under
secure_relative_open(), call the *at() variant against the dirfd,
fall through to the bare path-based syscall in non-daemon /
chrooted / absolute-path / no-parent cases. macOS's
setattrlist-based set_times tier is also routed through the
utimensat_at path on daemon-no-chroot.

Hardenings to secure_relative_open() itself:
  - confine basedir resolution under the same kernel mechanism
    used for relpath (basedirs from --copy-dest / --link-dest are
    sender-controllable in daemon mode)
  - reject any '..' component (bare '..', 'foo/..', 'subdir/..')
    so the per-component O_NOFOLLOW fallback can't escape
  - return the dirfd we built up from the per-component fallback
    when the caller passed O_DIRECTORY (otherwise every do_*_at
    failed with EINVAL on platforms without RESOLVE_BENEATH)

Adds testsuite/alt-dest-symlink-race.test and
testsuite/secure-relpath-validation.test (with t_secure_relpath
helper) as regression coverage for the new hardenings.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
15 files changed:
Makefile.in
backup.c
cleanup.c
delete.c
generator.c
hlink.c
receiver.c
rsync.c
runtests.py
syscall.c
t_secure_relpath.c [new file with mode: 0644]
testsuite/alt-dest-symlink-race.test [new file with mode: 0755]
testsuite/secure-relpath-validation.test [new file with mode: 0755]
util1.c
xattrs.c