You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
chrootenv: breaks when root contains broken symlink #33106
Steam no longer launches.
Reverting the changes introduced in #31182 and #32899 fixes the issue.
Steps to reproduce
❯ $(nix-build '<nixpkgs>' -A steam)/bin/steam
/nix/store/iqh6if4haz9x510q0166mz0k55z26k8l-chrootenv:chrootenv.c:59: stat(/result): No such file or directory
/nix/store/iqh6if4haz9x510q0166mz0k55z26k8l-chrootenv:chrootenv.c:132: nftw(/tmp/chrootenvKFDgfE): Directory not empty
It would seem strange but to double check - you wouldn't happen to have a broken result symlink sitting in your root folder? Otherwise I'm not sure what else could trigger this error.
After thinking about this, chrootenv should just replicate whatever is in user's root, and if includes a broken symlink, so be it. It also fails to clean up, which should never happen.
I observe strange behaviour in the clean up callback. I see it firing and working for a brief period of time before the bind mounts are cleared and trying to clear out contents of those recursively.
I'm not that great with C code and semantics of various syscalls but so far with various experiments I've seen it try to remove a file from within read-only bind mounted /nix/store, and from bind mounted /root. Upon changing permissions on /root to grant read/write/execute access to the user running steam the contents of /root (outside of chroot) were deleted.
I'm not sure what determines the directory traversal order - does it seem plausible it may traverse first through directories owned by the user invoking steam? I have not tried invoking steam as root.
I can't trigger this, no matter what I do. I have an invalid symlink in /, and in (world-writable) /root, and I've tried plain chrootenv, steam-run and proper steam. I only get the strace that I've posted above.
You have something strange going on with your root dir:
I'm still unclear why this seems to be only reproducible on my system but just to confirm - this looks to be fixed after the change that was applied in master.
FTW_MOUNT
If set, stay within the same file system (i.e., do not cross mount points).
(emphasis mine) IIUC bind mounts may break the assumption of "same filesystem == same mount point"? So would any filesystem mounted multiple times under different locations.
This seems to be done at kernel level. It seems to me that directories are iterated through only inside the mount namespace (i.e. in the child process), and not outside of it, although that doesn't explain why I can't reproduce it anyway.
It seems FTW_MOUNT is not doing what its name implies [...]
Patch above removes FTW_MOUNT, so it goes beyond this flag. Also I don't see any logic that would handle that in glibc nftw implementation. It seems that some syscalls work differently in mount namespace, or more probably, rather, outside of it: i.e. maybe namespaced mounts are not listable outside of the namespace. That seems to be most logical to me of all explanations so far.
atexit firing in the child as well as the parent caused the issue [...]
Perhaps: but nftw won't return until it recursively removes all files, and parent blocks until child exits, so parent should have nothing to clean up after child. It seems that some syscalls work differently inside child (which is in a mount namespace) and outside in parent (which hasn't called unshare and thus doesn't have a mount namespace).
In any case - thank you for your patience, fixing this and all your work on steam (and all other nixpkgs work) :-) It's very much appreciated!
@yegortimoshenko I've been seeing this occasionally (like once every couple of hundred runs) and I've been trying to track it down, just got some nice log output. Here's my modified chrootenv.c:
It looks like remove was being called on the root of the chroot but the directory open-data was still inside of it! (this is a directory that sits at my root directory /open-data, it's just a mounted 4TB ext4 HDD).
But from the logs remove was already called on open-data! And it returned successfully since we return and check the error code (I assume).
So is this just an issue about calling sync after a remove?
hmm...
I'd like to add a feature here that let's users add custom bind mounts during runtime (like docker's -v /host:/target), should this just be an environment variable to pass extra opts to bwrap? That feels a bit hacky to me.
UPDATE: implemented this with build-time options, not the same but enough for my use case
This has been automatically marked as stale because it has had no activity for 180 days.
If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.
Here are suggestions that might help resolve this more quickly:
Search for maintainers and people that previously touched the related code and @ mention them in a comment.
Activity
pbogdan commentedon Dec 27, 2017
It would seem strange but to double check - you wouldn't happen to have a broken
resultsymlink sitting in your root folder? Otherwise I'm not sure what else could trigger this error.srhb commentedon Dec 27, 2017
I just reached the same conclusion after adding result to the blacklist also removed the issue! That's some nice psychic debugging, thanks!
lukateras commentedon Dec 27, 2017
It fails because now it links everything to chrootenv, not just whitelisted dirs. Perhaps we should check for broken symlinks.
lukateras commentedon Dec 27, 2017
After thinking about this, chrootenv should just replicate whatever is in user's root, and if includes a broken symlink, so be it. It also fails to clean up, which should never happen.
[-]Steam fails to launch after chroot changes[/-][+]chrootenv: breaks when root contains broken symlink[/+]pbogdan commentedon Dec 27, 2017
I observe strange behaviour in the clean up callback. I see it firing and working for a brief period of time before the bind mounts are cleared and trying to clear out contents of those recursively.
I'm not that great with C code and semantics of various syscalls but so far with various experiments I've seen it try to remove a file from within read-only bind mounted /nix/store, and from bind mounted /root. Upon changing permissions on /root to grant read/write/execute access to the user running steam the contents of /root (outside of chroot) were deleted.
I'm not sure what determines the directory traversal order - does it seem plausible it may traverse first through directories owned by the user invoking steam? I have not tried invoking steam as root.
lukateras commentedon Dec 27, 2017
@pbogdan: This is really bad. Can you drop by IRC?
lukateras commentedon Dec 27, 2017
This should never happen because
FTW_MOUNTflag is set. If you are right, this is Bumblebee 2.0.lukateras commentedon Dec 27, 2017
I can't reproduce this, even with world-writable
/root. Relevant part ofstrace(cleanup):Which shows that it doesn't remove any files, only bind mount points.
pbogdan commentedon Dec 27, 2017
strace of the process https://gist.github.com/pbogdan/4d7d5b450b2d14aed6f382fb17caaf27 - in particular https://gist.github.com/pbogdan/4d7d5b450b2d14aed6f382fb17caaf27#file-steam-trace-L425
lukateras commentedon Dec 27, 2017
I can't trigger this, no matter what I do. I have an invalid symlink in
/, and in (world-writable)/root, and I've tried plainchrootenv,steam-runand propersteam. I only get the strace that I've posted above.You have something strange going on with your
rootdir:What could that mean? Also, please post your
nix-info -m.pbogdan commentedon Dec 28, 2017
I'm still unclear why this seems to be only reproducible on my system but just to confirm - this looks to be fixed after the change that was applied in master.
Also it seems like part of the issue could have been
FTW_MOUNTnot preventing descending into the folders bind mounted into the chroot, for the bind mounts that reside on the same filesystem / device. Looking at https://sourceware.org/git/?p=glibc.git;a=blob;f=io/ftw.c;h=6cca0e4cbc30835f5f298be0cd9e350c80791085;hb=HEAD the check is performed onst_devof the folder to be traversed, andst_devof the initial directory, and I believe those would be the same for bind mounts originating from the same filesystem (unless I misunderstood the code).19 remaining items
pbogdan commentedon Jan 1, 2018
According to https://linux.die.net/man/3/nftw:
(emphasis mine) IIUC bind mounts may break the assumption of "same filesystem == same mount point"? So would any filesystem mounted multiple times under different locations.
lukateras commentedon Jan 1, 2018
Try to apply the following patch on top of master:
Build with:
Output:
This seems to be done at kernel level. It seems to me that directories are iterated through only inside the mount namespace (i.e. in the child process), and not outside of it, although that doesn't explain why I can't reproduce it anyway.
pbogdan commentedon Jan 1, 2018
Oh yes - I don't think this is reproducible on master at all. I only remain curious why this would occur at all in the first place. It seems
FTW_MOUNTis not doing what its name implies, andatexitfiring in the child as well as the parent caused the issue (the child may inherit the callbacks if it doesn't reach successful http://man7.org/linux/man-pages/man3/exec.3.html invocation AFAICT?).In any case - thank you for your patience, fixing this and all your work on steam (and all other nixpkgs work) :-) It's very much appreciated!
lukateras commentedon Jan 1, 2018
Patch above removes
FTW_MOUNT, so it goes beyond this flag. Also I don't see any logic that would handle that in glibcnftwimplementation. It seems that some syscalls work differently in mount namespace, or more probably, rather, outside of it: i.e. maybe namespaced mounts are not listable outside of the namespace. That seems to be most logical to me of all explanations so far.Perhaps: but
nftwwon't return until it recursively removes all files, and parent blocks until child exits, so parent should have nothing to clean up after child. It seems that some syscalls work differently inside child (which is in a mount namespace) and outside in parent (which hasn't calledunshareand thus doesn't have a mount namespace).No problem! ^_^
illegalprime commentedon Feb 16, 2019
@yegortimoshenko I've been seeing this occasionally (like once every couple of hundred runs) and I've been trying to track it down, just got some nice log output. Here's my modified
chrootenv.c:(so the above prints the path and then anything inside of it if it's a directory)
Here's my log output:
It looks like
removewas being called on the root of the chroot but the directoryopen-datawas still inside of it! (this is a directory that sits at my root directory/open-data, it's just a mounted 4TB ext4 HDD).But from the logs remove was already called on
open-data! And it returned successfully since we return and check the error code (I assume).So is this just an issue about calling
syncafter aremove?hmm...
illegalprime commentedon Feb 16, 2019
UPDATE: I just realized since things aren't being cleaned up I still have those files around in
/tmp:this path is significant because this is where I was running my FHSEnv-ed app from.
my test setup was basically:
EDIT: but why wasn't this path visited by
nftw? something withopen-databeing a bind mount?illegalprime commentedon Feb 16, 2019
another update, I also seem to have a lot of chroots which aren't getting cleaned up:
specifically:
only 2 are in the error state described in my previous comment while the rest are 'full' as above.
but i've been running this chroot app hundreds of times to try to hit this bug, so 13 not cleaned up is a small number.
lukateras commentedon Feb 17, 2019
Thinking we should drop chrootenv in favor of bwrap (@jtojnar suggested that a long time ago, and was right all along).
illegalprime commentedon Feb 17, 2019
i'll try to make a
bwrapversion and post my progress, seems promising.illegalprime commentedon Feb 17, 2019
@yegortimoshenko this is what i have so far, seems to work OK:
master...illegalprime:chrootenv-2-bwrap
I'd like to add a feature here that let's users add custom bind mounts during runtime (like docker's-v /host:/target), should this just be an environment variable to pass extra opts to bwrap? That feels a bit hacky to me.UPDATE: implemented this with build-time options, not the same but enough for my use case
stale commentedon Jun 13, 2020
Thank you for your contributions.
This has been automatically marked as stale because it has had no activity for 180 days.
If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.
Here are suggestions that might help resolve this more quickly:
siraben commentedon Apr 10, 2021
Still relevant.