fix: reject symlinks with sysopen O_EXCL|O_CREAT per POSIX#376
Draft
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
fix: reject symlinks with sysopen O_EXCL|O_CREAT per POSIX#376toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
toddr-bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
POSIX open(2) mandates that O_EXCL|O_CREAT must fail with EEXIST when the final path component is a symbolic link, regardless of where it points. This is a security feature to prevent symlink race attacks (TOCTOU). Previously, sysopen with O_EXCL|O_CREAT would follow symlinks and only check whether the resolved target existed, allowing exclusive-create through a symlink — violating POSIX semantics. Add a pre-resolution check: when both O_EXCL and O_CREAT are set, inspect the path directly (without following) and fail immediately if it is a symlink. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
sysopen() with O_EXCL|O_CREAT now fails with EEXIST when the path is a symbolic link, matching POSIX open(2) semantics.
Why
POSIX mandates this behavior as a security measure against symlink race attacks (TOCTOU). Previously, O_EXCL|O_CREAT would follow the symlink and only check whether the resolved target existed — allowing exclusive-create through a symlink, which defeats the purpose of O_EXCL.
How
Added a pre-resolution check in
__sysopen: before following symlinks, if both O_EXCL and O_CREAT are set, inspect the path directly via_get_file_object(). If it's a symlink, return EEXIST immediately.Testing
7 new tests in
t/sysopen.tcovering:Full test suite passes (pre-existing
fh-ref-leak.tfailure is an upstream Overload::FileCheck version issue, unrelated).🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 54 insertions(+)
Code scan: clean
Tests: failed (4 Failed, 94 test)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline