Skip to content

Follow absolute sysroot links to host paths - #280

Merged
jserv merged 1 commit into
sysprog21:mainfrom
open-sources-port:elfuse-host-symlink-bridges
Aug 11, 2026
Merged

Follow absolute sysroot links to host paths#280
jserv merged 1 commit into
sysprog21:mainfrom
open-sources-port:elfuse-host-symlink-bridges

Conversation

@doanbaotrung

@doanbaotrung doanbaotrung commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

Allow sysroot-staged symlinks with absolute targets to resolve through the normal host fallback path, while keeping relative symlink climb-outs blocked.

This fixes host bridge links such as Downloads -> /Users//Downloads returning ELOOP.


Summary by cubic

Allow absolute-target symlinks staged in the sysroot to resolve via the normal host fallback, fixing ELOOP on host bridge links like Downloads -> /Users/<user>/Downloads. Relative “..” climb-outs stay blocked.

  • Bug Fixes
    • Follow sysroot absolute-target links to host paths when the host target exists; leave dangling links to resolve in the sysroot. Applies to absolute paths, dirfd/openat, trailing-slash directory opens, and chains where a relative link leads to an absolute-target link.
    • Block relative escapes (ELOOP) when a relative target would reach a host path; recheck dirfd-relative lookups against the sysroot.
    • Add a byte-exact link resolver to preserve Linux ENOTDIR behavior and prevent incorrect host fallback; update tests and stage /host-home-link and /home/muplar/Download to verify host bridge links (including trailing-slash directory opens).

Written for commit 5555c08. Summary will update on new commits.

Review in cubic

@doanbaotrung
doanbaotrung force-pushed the elfuse-host-symlink-bridges branch 4 times, most recently from 1ea60a8 to c3e2f5b Compare August 9, 2026 12:11
@doanbaotrung
doanbaotrung marked this pull request as draft August 9, 2026 12:14
@doanbaotrung
doanbaotrung force-pushed the elfuse-host-symlink-bridges branch 2 times, most recently from c4b032c to aa9039d Compare August 9, 2026 13:47
@doanbaotrung
doanbaotrung marked this pull request as ready for review August 9, 2026 14:10

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 5 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tests/test-sysroot-symlink-target.c">

<violation number="1" location="tests/test-sysroot-symlink-target.c:146">
P2: This new test resolves `Download/` to the host's `$HOME/Downloads` and FAILs the whole suite when that directory does not exist on the machine running CI (`~/.config`-less, headless, or freshly-provisioned macOS runners often have no Downloads). Unlike `/host-home-link` (target `$HOME`, which always exists), there is no guarantee `$HOME/Downloads` is present, so the opendir returns NULL and the regression guard fails spuriously. Recommend staging a guaranteed empty host dir (e.g. under `$tmpdir` sibling or `mktemp -d`) as the link target instead of depending on the caller's real Downloads folder.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/syscall/proc-state.c Outdated
DIR *dir;
if (chdir("/home/muplar") < 0) {
FAIL("chdir /home/muplar");
} else if ((dir = opendir("Download/")) != NULL) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This new test resolves Download/ to the host's $HOME/Downloads and FAILs the whole suite when that directory does not exist on the machine running CI (~/.config-less, headless, or freshly-provisioned macOS runners often have no Downloads). Unlike /host-home-link (target $HOME, which always exists), there is no guarantee $HOME/Downloads is present, so the opendir returns NULL and the regression guard fails spuriously. Recommend staging a guaranteed empty host dir (e.g. under $tmpdir sibling or mktemp -d) as the link target instead of depending on the caller's real Downloads folder.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tests/test-sysroot-symlink-target.c, line 146:

<comment>This new test resolves `Download/` to the host's `$HOME/Downloads` and FAILs the whole suite when that directory does not exist on the machine running CI (`~/.config`-less, headless, or freshly-provisioned macOS runners often have no Downloads). Unlike `/host-home-link` (target `$HOME`, which always exists), there is no guarantee `$HOME/Downloads` is present, so the opendir returns NULL and the regression guard fails spuriously. Recommend staging a guaranteed empty host dir (e.g. under `$tmpdir` sibling or `mktemp -d`) as the link target instead of depending on the caller's real Downloads folder.</comment>

<file context>
@@ -121,6 +122,36 @@ int main(void)
+        DIR *dir;
+        if (chdir("/home/muplar") < 0) {
+            FAIL("chdir /home/muplar");
+        } else if ((dir = opendir("Download/")) != NULL) {
+            closedir(dir);
+            PASS();
</file context>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.

I changed the fixture in third_party/elfuse/mk/tests.mk so Download no longer points to $HOME/Downloads.

It now does:

mkdir -p "$$tmpdir/host-downloads"
ln -s "$$tmpdir/host-downloads" "$$tmpdir/home/muplar/Download"

So the test target is guaranteed to exist on CI, while still exercising the same guest-facing opendir("Download/") path.

Verified with:

make -C third_party/elfuse test-sysroot-symlink-target

Comment thread src/syscall/path.c
Comment thread src/syscall/path.c Outdated
Allow sysroot-staged symlinks with absolute targets to resolve through
the normal host fallback path, while keeping relative symlink climb-outs
blocked.

This fixes host bridge links such as Downloads -> /Users/<user>/Downloads returning
ELOOP.
@doanbaotrung
doanbaotrung force-pushed the elfuse-host-symlink-bridges branch from aa9039d to 5555c08 Compare August 9, 2026 14:31
@jserv
jserv requested a review from Max042004 August 9, 2026 20:35
@jserv
jserv merged commit a2b5f3c into sysprog21:main Aug 11, 2026
21 checks passed
@jserv

jserv commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Thank @doanbaotrung for contributing!

@doanbaotrung
doanbaotrung deleted the elfuse-host-symlink-bridges branch August 11, 2026 07:16
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.

2 participants