Fix adding symlink to the sandbox paths#10456
Conversation
Regression test for #9579
…o a symlink out of the store Bind-mounting symlinks is apparently not possible, which is why the thing was failing. Fortunately, symlinks are small, so we can fallback to copy them at no cost. Fix #9579 Co-authored-by: Artturin <Artturin@artturin.com>
Doesn't change much, but brings a bit more consistency to the code
e477ce7 to
ae47372
Compare
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin 2.18-maintenance
git worktree add -d .worktree/backport-10456-to-2.18-maintenance origin/2.18-maintenance
cd .worktree/backport-10456-to-2.18-maintenance
git switch --create backport-10456-to-2.18-maintenance
git cherry-pick -x 872d93eb13f22e8705e03903b65c7eba8b26a99b 913db9f7385b8717d9eaf6269e9f319e78e4c564 ae4737294e91ab93526612b17950e1bc4f0b47f0 |
|
Successfully created backport PR for |
This comment was marked as resolved.
This comment was marked as resolved.
|
Successfully created backport PR for |
This comment was marked as resolved.
This comment was marked as resolved.
|
Successfully created backport PR for |
|
Git push to origin failed for 2.21-maintenance with exitcode 1 |
|
Thanks @thufschmitt for picking this up, I am sorry I let the last one stagnate. |
NixOS#10456 fixed the addition of symlink store paths to the sandbox, but also made it so that the hardcoded sandbox paths (like `/etc/hosts`) were now bind-mounted without following the possible symlinks. This made these files unreadable if there were symlinks (because the sandbox would now contain a symlink to an unreachable file rather than the underlying file). In particular, this broke FOD derivations on NixOS as `/etc/hosts` is a symlink there. Fix that by canonicalizing all these hardcoded sandbox paths before adding them to the sandbox.
Fix adding symlink to the sandbox paths (cherry-picked from commit da1e977) Change-Id: I221c85a38180800ec6552d2e86a88df48398fad8
The upstream issue appears to be fixed by NixOS/nix#10456.
#10456 fixed the addition of symlink store paths to the sandbox, but also made it so that the hardcoded sandbox paths (like `/etc/hosts`) were now bind-mounted without following the possible symlinks. This made these files unreadable if there were symlinks (because the sandbox would now contain a symlink to an unreachable file rather than the underlying file). In particular, this broke FOD derivations on NixOS as `/etc/hosts` is a symlink there. Fix that by canonicalizing all these hardcoded sandbox paths before adding them to the sandbox. (cherry picked from commit acbb152)
#10456 fixed the addition of symlink store paths to the sandbox, but also made it so that the hardcoded sandbox paths (like `/etc/hosts`) were now bind-mounted without following the possible symlinks. This made these files unreadable if there were symlinks (because the sandbox would now contain a symlink to an unreachable file rather than the underlying file). In particular, this broke FOD derivations on NixOS as `/etc/hosts` is a symlink there. Fix that by canonicalizing all these hardcoded sandbox paths before adding them to the sandbox. (cherry picked from commit acbb152)
#10456 fixed the addition of symlink store paths to the sandbox, but also made it so that the hardcoded sandbox paths (like `/etc/hosts`) were now bind-mounted without following the possible symlinks. This made these files unreadable if there were symlinks (because the sandbox would now contain a symlink to an unreachable file rather than the underlying file). In particular, this broke FOD derivations on NixOS as `/etc/hosts` is a symlink there. Fix that by canonicalizing all these hardcoded sandbox paths before adding them to the sandbox. (cherry picked from commit acbb152) (cherry picked from commit 1cc79f1) # Conflicts: # tests/functional/linux-sandbox.sh
|
I think this fix is wrong, and it incurs some annoying performance regressions when used on non-cow filesystems with large sources. This example program, which creates #include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/mount.h>
int main() {
if (mkdir("a", 0755) == -1) {
perror("mkdir");
return 1;
}
if (symlink("a", "b") == -1) {
perror("symlink");
return 1;
}
if (mkdir("mnt", 0755) == -1) {
perror("mkdir");
return 1;
}
if (mount("b", "mnt", NULL, MS_BIND, NULL) == -1) {
perror("mount");
return 1;
}
return 0;
}It results in the following mount, as the symlink is being followed on the If following the link is not desired, the new mount API could be used, as shown here. 1 Footnotes |


Bind-mounting symlinks is apparently not possible, which is why the
thing was failing.
Fortunately, symlinks are small, so we can fallback to copy them at no cost.
Fix #9579
Priorities and Process
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.