-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nix cannot run other executables in chroot (No such file or directory) #7602
Comments
This breaks I'm kinda stuck now because my system needs repairing, but I can't pull updates to fix it.
|
@YellowOnion did you try to apply the patch to nixos-enter? It's not a proper fix for the issue, but might allow you to get back up and running. |
@VincentVanlaer I'll try it tomorrow, I'm currently inside a nixos-shell session with read-only nix stuff so I cant' patch anything. I wonder if bwrap is a better tool for this than a plain chroot and all it's flaws. |
@VincentVanlaer yeah your patch fixed it, I wonder if this is a regression in nix 2.11, maybe we can ping someone to get this more noticed because breaking core functionality like nixos-enter could be a disaster if it gets in to stable. |
Nix, like most packages, does not bundle its runtime command dependencies; so no |
I does do things with mount namespaces though, see my explanation above about restoreMountNamespace, which is called on invocation of any external process, including |
Yeah this doesn't directly have to do with See this repro I just did using a quick
This will even do bizarre things like attempt to copy a flake from outside the chroot into the store rather than the flake inside of the chroot, since it internally executes
|
I just ran into this today. Running nixos-rebuild after nixos-enter doesn't act as if its in the chroot (at least with certain commands, definitely git). Took me a few minutes to figure out what was happening. |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-04-10-nix-team-meeting-minutes-47/27357/1 |
@edolstra Did you get any progress on this? |
Something else I noticed, |
I think this really should be treated more urgently, as we can use one of the most important NixOS recovery measures only with workarounds that are neither obvious nor properly documented. Setting up a regular Having to use a workaround that doubles the amount of commands to use and which are even lesser known than Having to patch
Patching |
Yeah, I proposed that in NixOS/nixpkgs#224830 but didn't get a reply |
I think this should be considered a bug in
to escape out of the filesystem of the guest, which is not really desired behavior. |
This is necessary when we're in a chroot environment, where the process root is not the same as the root of the mount namespace (e.g. in nixos-enter). Fixes NixOS#7602.
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-06-09-nix-team-meeting-minutes-61/29163/1 |
Would stopping that not be more of a security feature rather than a usability feature? It seems to me that no sane/non-evil program will call setns with the namespaces of PID 1. |
Describe the bug
When running a nix command that use another executable (e.g.
man
,git
, ...) while chrooted, I get a variation of the following error:The culprit seems to be the restoring of the mount namespace in
restoreMountNamespace
. Usingsetns
will reset the root of the process to the root of the namespace, undoing any chroot that was active before.Steps To Reproduce
This only works if the OS you are chrooting from does not have
man
in one of the locations . This means that if you are using nixos to chroot into another nixos installation, it might seem that everything is fine. Hoewever, you are unknowingly using executables from outside the chroot.nixos-generate-config
andnixos-install
on a new partition)nixos-enter
nix-env --help
nix-env --version
outputnix-env (Nix) 2.11.1
Additional context
Note that this only affects
setns
and notunshare
. I presume this is the case because the kernel can guarantee that the root of the chroot still exists afterunshare
, but not in the case ofsetns
. Hence the problem only manifest whenrestoreMountNamespace
is called.I have two different suggestions to fix this bug:
setns
inrestoreMountNamespace
. The only way to do this (that I could find), is to pass a file descriptor of the root to the child process, have the child process obtain the path to the root with /proc, which is not guaranteed to succeed and then call chroot with that path.My preference is the second option, as it is guaranteed to work and doesn't expose anything in the chroot to the outside.
As part of my testing I have also modified
nixos-enter
to usepivot_root
instead ofchroot
as follows:As now the root of the namespace is what we originally wanted to chroot into,
setns
will no longer dump us back in the original OS.Priorities
Add 👍 to issues you find important.
The text was updated successfully, but these errors were encountered: