Skip to content

fix: fix hardlinking between different directories.#56

Open
zicklag wants to merge 1 commit into
Zouuup:mainfrom
zicklag:fix/hardlink-to-different-dirs
Open

fix: fix hardlinking between different directories.#56
zicklag wants to merge 1 commit into
Zouuup:mainfrom
zicklag:fix/hardlink-to-different-dirs

Conversation

@zicklag
Copy link
Copy Markdown

@zicklag zicklag commented Apr 27, 2026

Fixes a bug due to the kernel's special handling of the FSRefer access.

Previously landrun would restrict file paths with one call to RestrictPaths() and restrict network access with a second call to RestrictNet().

The issue is that when we call RestrictNet(), it carries with it an implicit restriction on the FSRefer access. According to the kernel docs on FSRefer:

This is the only access right which is denied by default by any ruleset, even if the right is not specified as handled at ruleset creation time. The only way to make a ruleset grant this right is to explicitly allow it for a specific directory by adding a matching rule to the ruleset.

We get around this by making a single call to Restrict() instead of two separate calls, unless either the filesystem or network are unrestricted, in which case we just restrict the one that is still restricted with RestrictPaths() or RestrictNet().

Interestingly, even before this PR, running landrun with --unrestrestricted-network actually fixes the hardlink issue because it doesn't create the second landlock layer for the network access.

# This will fail in the previous version of landrun
landrun --rwx / ln somefile.txt somedir/link.txt
# This will succeed because we only create one landlock layer
landrun --rwx / --unrestrestricted-network ln somefile.txt somedir/link.txt

AI usage disclosure: DeepSeek v4 Flash was used to find the root cause of the issue. I have my entire chat transcript public for transparency. You can see exactly how I prompted it, and all the models tool calls, thinking, etc. Nothing was redacted. By the end of the session I believe I understand the fix, and why it works, and I sign off on the code as having put my own full due dilligence into making sure it made sense to me and lined up with the kernel documentation as well as my own tests.

Fixes: #55

Fixes a bug due to the kernel's special handling of the FSRefer access.

Previously landrun would restrict file paths with one call to
RestrictPaths() and restrict network access with a second call to
RestrictNet().

The issue is that when we call RestrictNet(), it carries with it an
implicit restriction on the FSRefer access. According to the kernel docs
on FSRefer:

> This is the only access right which is denied by default by any ruleset,
> even if the right is not specified as handled at ruleset creation time.
> The only way to make a ruleset grant this right is to explicitly allow it
> for a specific directory by adding a matching rule to the ruleset.

We get around this by making a single call to Restrict() instead of two
separate calls, unless either the filesystem or network are
unrestricted, in which case we just restrict the one that is still
restricted with RestrictPaths() or RestrictNet().
@rusty-snake
Copy link
Copy Markdown

#48/#49

@zicklag
Copy link
Copy Markdown
Author

zicklag commented Apr 28, 2026

Haha, well, cool. I didn't realize there was already a fix for it. 🙃

@rusty-snake
Copy link
Copy Markdown

When I read the description I remembered some PR was already talking about two layers.

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.

Can't Compile Rust In Landrun

2 participants