Skip to content

Emulate linkat on macOS symlinks and escape logs#240

Open
doanbaotrung wants to merge 1 commit into
sysprog21:mainfrom
open-sources-port:linkat
Open

Emulate linkat on macOS symlinks and escape logs#240
doanbaotrung wants to merge 1 commit into
sysprog21:mainfrom
open-sources-port:linkat

Conversation

@doanbaotrung

@doanbaotrung doanbaotrung commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

On macOS, linkat(2) fails with EINVAL when attempting to hard-link a
symbolic link itself. Fall back to creating a new symlink to the same
target when host linkat returns EINVAL.

In addition, sanitize verbose tracing logs by escaping control
characters in guest-provided path strings. This prevents guests
from injecting terminal escape sequences into the operator's
terminal.

Fix #237


Summary by cubic

Stop falling back to host paths for system directories when a guest path is missing in the sysroot. Prevents guest writes to the host and avoids SIP-related EPERM/EACCES on macOS.

  • Bug Fixes
    • Block fallback for /usr, /bin, /lib, /sbin, /var, /opt, and /etc.
    • Keep fallback for /etc/resolv.conf to preserve DNS.
    • Treat EINVAL in linkat as non-fallback to avoid host writes.
    • Escape control/non-ASCII in debug logs: paths for openat/readlinkat/faccessat, and target+linkpath for symlinkat.

Written for commit c40996c. Summary will update on new commits.

Review in cubic

cubic-dev-ai[bot]

This comment was marked as resolved.

@doanbaotrung doanbaotrung changed the title Draft: Restrict sysroot fallback to exclude system paths Restrict sysroot fallback to exclude system paths Jul 23, 2026
@jserv
jserv requested a review from Max042004 July 23, 2026 07:34
Comment thread src/syscall/syscall.c

@jserv jserv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Change the subject to be different from #241

On macOS, linkat(2) fails with EINVAL when attempting to hard-link a
symbolic link itself. Fall back to creating a new symlink to the same
target when host linkat returns EINVAL.

In addition, sanitize verbose tracing logs by escaping control
characters in guest-provided path strings. This prevents guests
from injecting terminal escape sequences into the operator's
terminal.

Fix sysprog21#237
@doanbaotrung doanbaotrung changed the title Restrict sysroot fallback to exclude system paths Emulate linkat on macOS symlinks and escape logs Jul 23, 2026
@doanbaotrung

This comment was marked as resolved.

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.

linkat fails with EINVAL on macOS hosts when linking symlinks (AT_SYMLINK_NOFOLLOW)

2 participants