Skip to content

Commit 6f9757e

Browse files
committed
syscall: use O_SEARCH for held directory traversal
Since 3.5.0 the receiver resolves its destination one component at a time with held directory fds. Without O_PATH these are opened O_RDONLY|O_DIRECTORY, so on macOS every ancestor of the destination must be readable, not just searchable. A destination below a mode 0711 home, or a sandbox that denies listing $HOME, fails with change_dir#1. Use O_SEARCH|O_DIRECTORY where O_PATH is unavailable. macOS 13+ and illumos check only search permission for it; older macOS and NetBSD ignore it, so they keep the existing O_RDONLY|O_DIRECTORY behaviour. Run the search-only tests on macOS 13+.
1 parent 5479ce9 commit 6f9757e

5 files changed

Lines changed: 22 additions & 10 deletions

File tree

‎SECURITY.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,11 @@ leaf symlink into a file read.
200200
`secure_relative_open()` resolves a path with a single portable mechanism on
201201
every platform: a per-component walk on a stack of held directory fds. On
202202
Linux, anchors and traversal components use
203-
`O_PATH|O_DIRECTORY|O_NOFOLLOW`; other platforms retain the
204-
`O_RDONLY|O_DIRECTORY` fallback. Descending into a real subdirectory pushes
203+
`O_PATH|O_DIRECTORY|O_NOFOLLOW`; platforms with `O_SEARCH` but no `O_PATH`
204+
(macOS, illumos, NetBSD) use `O_SEARCH|O_DIRECTORY|O_NOFOLLOW`, which needs
205+
only search permission on macOS 13+ and illumos and read permission on older
206+
macOS and NetBSD, whose kernels ignore it; the rest (OpenBSD, DragonFly)
207+
retain the `O_RDONLY|O_DIRECTORY` fallback. Descending into a real subdirectory pushes
205208
its fd, a `..` pops back to the already-held parent (a pop at the anchor is
206209
refused), and an in-tree directory symlink is followed by reading its target
207210
and walking that off the same stack (absolute targets refused, symlink hops

‎syscall.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,17 @@ extern int operator_path_resolve; /* defined below; fwd-declared for the exclude
7878
extern int filesfrom_owner_walk_override; /* defined below; used by files-from implied dirs */
7979

8080
/* A directory fd used only for pathname traversal, fchdir(), or as *at()
81-
* authority does not need read permission on Linux. Keep the portable
82-
* O_RDONLY fallback for systems without O_PATH. */
81+
* authority does not need read permission: use O_PATH on Linux and O_SEARCH
82+
* (search permission only) elsewhere, e.g. macOS 13+ and illumos. Kernels
83+
* that ignore it (macOS < 13, NetBSD) treat it as O_RDONLY. O_SEARCH implies
84+
* O_DIRECTORY only on macOS, so request it explicitly. Keep the portable
85+
* O_RDONLY fallback for other systems. */
8386
static int directory_traverse_flags(void)
8487
{
8588
#if defined O_PATH && defined O_DIRECTORY
8689
return O_PATH | O_DIRECTORY;
90+
#elif defined O_SEARCH && defined O_DIRECTORY
91+
return O_SEARCH | O_DIRECTORY;
8792
#elif defined O_DIRECTORY
8893
return O_RDONLY | O_DIRECTORY;
8994
#else

‎testsuite/search-only-destination_test.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
from rsyncfns import SCRATCHDIR, rmtree, rsync_argv, test_fail, test_skipped
1616

17-
if not sys.platform.startswith('linux'):
18-
test_skipped('search-only-destination is Linux-specific')
17+
# O_PATH on Linux; O_SEARCH on macOS 13+ (Darwin 22), which older kernels ignore.
18+
if not (sys.platform.startswith('linux')
19+
or (sys.platform == 'darwin' and int(os.uname().release.split('.')[0]) >= 22)):
20+
test_skipped('search-only-destination needs O_PATH (Linux) or O_SEARCH (macOS 13+)')
1921

2022
launcher = []
2123
if os.geteuid() == 0:

‎testsuite/search-only-held-dirfd_test.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
SCRATCHDIR, forced_protocol, rmtree, rsync_argv, test_fail, test_skipped,
1919
)
2020

21-
if not sys.platform.startswith('linux'):
22-
test_skipped('search-only held-dirfd coverage is Linux-specific')
21+
# O_PATH on Linux; O_SEARCH on macOS 13+ (Darwin 22), which older kernels ignore.
22+
if not (sys.platform.startswith('linux')
23+
or (sys.platform == 'darwin' and int(os.uname().release.split('.')[0]) >= 22)):
24+
test_skipped('search-only held-dirfd coverage needs O_PATH (Linux) or O_SEARCH (macOS 13+)')
2325

2426
launcher = []
2527
if os.geteuid() == 0:

‎testsuite/skiplist/macos.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ rrsync-sender-leaf-flip
3232
rrsync-sender-parent-pin
3333
rrsync-symlink
3434
rrsync-userns-procfs
35-
search-only-destination
36-
search-only-held-dirfd
35+
search-only-destination # CI runs as root; dropping privileges needs setpriv
36+
search-only-held-dirfd # CI runs as root; dropping privileges needs setpriv
3737
sender-remove-source-root-anchor
3838
simd-checksum
3939
source-change-size-continues

0 commit comments

Comments
 (0)