Repository navigation
Conversation
The path layer follows some links itself before it hands a name to a sysroot resolver, and the resolver starts its walk as if none had been followed: its MAXSYMLINKS count begins at zero, and a name reached through a relative link is free to fall back to the host, which the resolver refuses after a relative link of its own. Each resolver takes a path_walk_t with the links the caller followed and whether one had a relative target, and starts its count and its followed-link state from it, so a name the caller reached through links takes the host fallback rule for a followed link rather than the one for a name the guest typed. Every caller passes NULL here, so no answer changes.
The links path_backing_dotdot follows before a '..' are lost once the name it rewrote reaches the sysroot resolver, so the resolver counts its own links from zero and judges the name as one the guest typed. A chain of 25 links under /dev/bus that goes on as 16 more outside it resolved, where Linux answers ELOOP at the 41st, and a relative link under /dev/bus reached a host file outside the sysroot, where the same link elsewhere in the sysroot gets ELOOP. path_rewrite_dev_climb records in a path_walk_t the links it follows and whether one had a relative target, and path_translate_at hands it to the sysroot resolver with the rewritten name. test-usb-sysfs-sysroot runs the guest again with the argument backing, over a sysroot where hrel and habs under /dev/bus and /lk link to a host directory. It resolves 40 links before a '..' and gets ELOOP for 41, and gets ELOOP for a relative link to the host directory before a '..' under /dev/bus as under /lk, while an absolute one reaches it under both. On c57282f the 41-link and relative checks fail. Both fail with the walk left out of path_translate_at, and the relative one with the relative target left unrecorded or with the resolver taking the name it is handed for one the guest typed.
With a sysroot link from /dev/bus/link to usb, /dev/bus/link/001/001 and /dev/bus/link/001/../001/001 answered ENOENT where Linux serves the usbfs node, and stat of /dev/bus/link answered ENOENT for a directory. The path layer followed a link only right before a '..', and left every other link to the sysroot resolver, which follows it within the sysroot, and the sysroot does not hold the layer's /dev/bus/usb. path_dev_bus_follow_link follows the first link among the backing's names in a /dev/bus name, up to its first '..', as Linux follows each link where the walk meets it, and path_rewrite_dev_climb starts the walk again from the result. A link that ends the name is followed only when the sysroot resolver would follow it, so lstat and readlink still see the link. path_backing_dotdot is left with names that hold no link, and the walk goes on in the sysroot resolver only once the name has left /dev/bus: a name left there holds no link to follow, and handed the walk, the create resolver would refuse mkdir through a link to usb with ELOOP where mkdir under /dev/bus/usb gets ENOENT. test-usb-sysfs-sysroot reaches the node through such a link from an absolute name, after a '..', against a /dev/bus dirfd and from a /dev/bus cwd, checks stat, lstat and readlink of the link and mkdir through it, and repeats the link count and host checks with no '..' after the first link. With links left unfollowed, those six checks fail and so does each check with a link before a '..'. The check of the link itself fails with a link that ends the name never or always followed, and the mkdir check with the walk handed over for a name left in /dev/bus. With the link before a '..' left unfollowed, the checks that have one fail, as do the matrix columns fold-in-link and fold-in-loop, and with the walk or the relative target left out of what the resolver is handed, the 41-link or relative checks fail.
There was a problem hiding this comment.
3 issues found across 7 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="mk/tests.mk">
<violation number="1" location="mk/tests.mk:1841">
P2: The relative fixtures point inside a nonexistent `sysroot/tmp/...` path rather than at the staged host directory, so the new `backing` lane cannot exercise its relative-link escape checks and fails with `ENOENT` instead of `ELOOP`. Use paths relative to each link's parent (`../../../host` under `/dev/bus` and `../../host` under `/lk`).</violation>
</file>
<file name="src/syscall/path.c">
<violation number="1" location="src/syscall/path.c:932">
P2: This drops the shared `MAXSYMLINKS` count for paths that remain lexically under `/dev/bus` but continue into backing components after `..`. A chain split across that boundary can follow more than 40 links instead of returning `ELOOP`; preserve the caller walk for the resolver while keeping synthetic `/dev/bus` names out of backing resolution.</violation>
</file>
<file name="src/syscall/proc-state.c">
<violation number="1" location="src/syscall/proc-state.c:1089">
P2: The resolver does not continue a caller-started walk when the target lands under a forced sysroot root such as `/tmp`. Subsequent symlinks are resolved by `sysroot_path_exists()` without the caller’s link count, allowing chains beyond the shared `MAXSYMLINKS` limit; run the link walker from `links` before applying the forced-root fallback rules.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| ln -s "../..$$tmpdir/host" "$$sysroot/dev/bus/hrel"; \ | ||
| ln -s "..$$tmpdir/host" "$$sysroot/lk/hrel"; \ |
There was a problem hiding this comment.
P2: The relative fixtures point inside a nonexistent sysroot/tmp/... path rather than at the staged host directory, so the new backing lane cannot exercise its relative-link escape checks and fails with ENOENT instead of ELOOP. Use paths relative to each link's parent (../../../host under /dev/bus and ../../host under /lk).
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At mk/tests.mk, line 1841:
<comment>The relative fixtures point inside a nonexistent `sysroot/tmp/...` path rather than at the staged host directory, so the new `backing` lane cannot exercise its relative-link escape checks and fails with `ENOENT` instead of `ELOOP`. Use paths relative to each link's parent (`../../../host` under `/dev/bus` and `../../host` under `/lk`).</comment>
<file context>
@@ -1836,7 +1836,14 @@ test-usb-sysfs-sysroot: $(ELFUSE_BIN) $(TEST_DIR)/test-usb-sysfs-sysroot
- $(TEST_DIR)/test-usb-sysfs-sysroot search root
+ $(TEST_DIR)/test-usb-sysfs-sysroot search root; \
+ mkdir "$$tmpdir/host" "$$sysroot/lk"; : > "$$tmpdir/host/f"; \
+ ln -s "../..$$tmpdir/host" "$$sysroot/dev/bus/hrel"; \
+ ln -s "..$$tmpdir/host" "$$sysroot/lk/hrel"; \
+ ln -s "$$tmpdir/host" "$$sysroot/dev/bus/habs"; \
</file context>
| ln -s "../..$$tmpdir/host" "$$sysroot/dev/bus/hrel"; \ | |
| ln -s "..$$tmpdir/host" "$$sysroot/lk/hrel"; \ | |
| ln -s "../../../host" "$$sysroot/dev/bus/hrel"; \\ | |
| ln -s "../../host" "$$sysroot/lk/hrel"; \\ |
| if (path_rewrite_usb_aliases(tx, flags, &walk) < 0) | ||
| return -1; | ||
| const path_walk_t *walked = | ||
| path_prefix_match(tx->guest_path, "/dev/bus", 8) ? NULL : &walk; |
There was a problem hiding this comment.
P2: This drops the shared MAXSYMLINKS count for paths that remain lexically under /dev/bus but continue into backing components after ... A chain split across that boundary can follow more than 40 links instead of returning ELOOP; preserve the caller walk for the resolver while keeping synthetic /dev/bus names out of backing resolution.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/syscall/path.c, line 932:
<comment>This drops the shared `MAXSYMLINKS` count for paths that remain lexically under `/dev/bus` but continue into backing components after `..`. A chain split across that boundary can follow more than 40 links instead of returning `ELOOP`; preserve the caller walk for the resolver while keeping synthetic `/dev/bus` names out of backing resolution.</comment>
<file context>
@@ -839,8 +920,16 @@ int path_translate_at(guest_fd_t dirfd,
+ if (path_rewrite_usb_aliases(tx, flags, &walk) < 0)
return -1;
+ const path_walk_t *walked =
+ path_prefix_match(tx->guest_path, "/dev/bus", 8) ? NULL : &walk;
/* /dev/shm/<leaf> maps into the per-UID host backing dir, through the same
</file context>
| bool folded = false; | ||
| bool followed_link = false; | ||
| bool followed_relative_link = false; | ||
| unsigned links = walked ? walked->links : 0; |
There was a problem hiding this comment.
P2: The resolver does not continue a caller-started walk when the target lands under a forced sysroot root such as /tmp. Subsequent symlinks are resolved by sysroot_path_exists() without the caller’s link count, allowing chains beyond the shared MAXSYMLINKS limit; run the link walker from links before applying the forced-root fallback rules.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/syscall/proc-state.c, line 1089:
<comment>The resolver does not continue a caller-started walk when the target lands under a forced sysroot root such as `/tmp`. Subsequent symlinks are resolved by `sysroot_path_exists()` without the caller’s link count, allowing chains beyond the shared `MAXSYMLINKS` limit; run the link walker from `links` before applying the forced-root fallback rules.</comment>
<file context>
@@ -1082,8 +1086,9 @@ static const char *proc_resolve_sysroot_path_flags(const char *path,
bool folded = false;
- bool followed_link = false;
- bool followed_relative_link = false;
+ unsigned links = walked ? walked->links : 0;
+ bool followed_link = links > 0;
+ bool followed_relative_link = walked && walked->relative;
</file context>
| /* As the sysroot resolvers below decide for the last name: a | ||
| * trailing slash follows it, and a create does not. | ||
| */ | ||
| bool follow = !(flags & PATH_TR_CREATE) && |
There was a problem hiding this comment.
PATH_TR_CREATE is also what sys_openat_path passes for every O_CREAT, so this never follows a final link for open(O_CREAT) without O_EXCL. With /dev/bus/link -> usb/001/001, open("/dev/bus/link", O_RDWR | O_CREAT) goes to the backing, where the host follows the link to a dev/bus/usb/001/001 the sysroot does not hold and answers ENOENT. Linux follows an existing final link there and opens the usbfs node.
sys_openat_path drops O_EXCL and O_NOFOLLOW when it picks PATH_TR_CREATE | PATH_TR_CREATE_PARENTS, and mkdirat and symlinkat must keep not following, so the layer cannot tell the cases apart today. It needs a flag of its own that sys_openat_path sets for O_CREAT without O_EXCL or O_NOFOLLOW. If that is out of scope here, add it to the differences listed in docs/internals.md and take it as a follow-up.
| */ | ||
| bool followed_link = false; | ||
| bool followed_relative_link = false; | ||
| bool followed_link = walked && walked->links > 0; |
There was a problem hiding this comment.
On a case-sensitive sysroot, walked->links only sets followed_link here. The byte-exact branch below checks the parent with access, so the host follows the links that are left and counts them from zero against its own limit. mkdir("/dev/bus/c41/l0/n") over the new c41 fixture follows 25 links in the layer and leaves /lk/c41/l0/n, and access on /lk/c41/l0 follows the other 16 and succeeds. Linux answers ELOOP at the 41st link, and so does the case-folding branch above, which starts resolve_through_links at walked->links.
Walk the parent's links from walked->links in this branch too, as resolve_byte_exact_through_links does for a lookup. If not, name this gap in docs/internals.md and pin it with a create case in the backing lane.
This is the follow-up committed to in #444: the links the path layer follows count toward one
MAXSYMLINKSwith the sysroot resolver's, and a link anywhere in a/dev/busname resolves in the guest namespace, with the walk starting again from its target.With a sysroot link from
/dev/bus/linktousb,/dev/bus/link/001/001and/dev/bus/link/001/../001/001answerENOENTonmain, where Linux serves the usbfs node: the path layer follows a link only right before a.., and leaves every other one to the sysroot resolver, which does not hold/dev/bus/usb. A chain of 25 links under/dev/busthat goes on as 16 more outside it resolves, where Linux answersELOOPat the 41st, because the path layer and the sysroot resolver each count from zero. For the same reason, a relative link under/dev/busfollowed by a..reaches a host file outside the sysroot, where the same link elsewhere in the sysroot getsELOOP.The first commit lets a sysroot resolver go on from a walk its caller started, with every caller passing
NULL, and the second passes it the linkspath_backing_dotdotfollows. The third follows a link wherever it sits in a/dev/busname.docs/internals.mdstates what still differs from Linux: a link outside/dev/buswhose target is under it, as from/lk/uto/dev/bus/usb, is followed by the sysroot resolver alone; on a sysroot withoutdev/bus/usb, a..that pops/dev/bus/usbis left to the backing, which cannot walk it, so/dev/bus/usb/../link/001/001isENOENT; and a link replaced between its lookup and the read of its target fails the walk withEINVAL.Reproduce with the fixture devices and a static aarch64 busybox, over a sysroot holding the link:
On
mainboth fail withNo such file or directory. With these commits they printcharacter special fileanddirectory, as Linux does.Tested on macOS 15.6.1 (24G90) with the 15.5 SDK on an Apple M1 (MacBookAir10,1). In
make check,tests/driver.shpasses 102 of 103 on this branch and onmain, andmake test-matrix-elfuse-aarch64gives 317 passed, 1 failed and 10 skipped on both. The failure in all four runs istest-thread-churntiming out. The new checks intest-usb-sysfs-sysrootalso pass with the sysroot on a case-sensitive volume, where the sysroot resolver takes its byte-exact walk.Summary by cubic
Fixes how symlinks in
/dev/busnames resolve so the path layer follows them in the guest namespace, counting toward the sameMAXSYMLINKSlimit as the sysroot resolver. Both the sysroot resolvers and the path layer now share one link count and relative-target state, so names reached through links take the same host-fallback rules as links the resolver follows itself. With a sysroot link from/dev/bus/linktousb,/dev/bus/link/001/001and/dev/bus/link/001/../001/001now serve the usbfs node, wheremainansweredENOENT; a chain of 41 links now fails withELOOP, and a relative link to outside the sysroot no longer reaches a host file.path_resolve_sysroot_*andproc_resolve_sysroot_*take apath_walk_tdescribing the links the caller already followed; every existing caller passesNULL.path_dev_bus_follow_linkfollows the first backing link in a/dev/busname, with the link resolved in the guest namespace and a trailing slash andstatfollowing a final link whilelstatandreadlinkstill see it.docs/internals.mddocuments the remaining differences from Linux: links outside/dev/bustargeting it, a..that pops/dev/bus/usbon a sysroot without it, and a link replaced between lookup and read.Written for commit ecc0bd5. Summary will update on new commits.