lsns: don't abort if /proc/self/ns/user is absent; probe other ns entries#3772
Merged
karelzak merged 1 commit intoOct 6, 2025
Merged
Conversation
…ries In 7d5036f ("lsns: show namespaces only kept alive by open file descriptors"), I added code that calls stat(2) on /proc/self/ns/user and made lsns exit after reporting an error if the call failed. I assumed /proc/self/ns/user would be available on all platforms. As Axel Karjalainen reported (link below), that assumption was wrong: on some platforms, the file is absent. Exiting for this reason is undesirable. The stat(2) call is used to obtain the dev_t of the backing device of nsfs. However, /proc/self/ns/user is not the only source; calling stat(2) on other namespace files under /proc/self/ns yields the same dev_t. This change iterates over entries under /proc/self/ns and uses the first one whose stat(2) succeeds. Reported-by: Axel Karjalainen <axel@axka.fi> Link: util-linux#2902 (comment) Fixes: 7d5036f ("lsns: show namespaces only kept alive by open file descriptors") Signed-off-by: Masatake YAMATO <yamato@redhat.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.
In 7d5036f ("lsns: show namespaces only kept alive by open file descriptors"), I added code that calls stat(2) on /proc/self/ns/user and made lsns exit after reporting an error if the call failed. I assumed /proc/self/ns/user would be available on all platforms.
As Axel Karjalainen reported (link below), that assumption was wrong: on some platforms, the file is absent. Exiting for this reason is undesirable.
The stat(2) call is used to obtain the dev_t of the backing device of nsfs. However, /proc/self/ns/user is not the only source; calling stat(2) on other namespace files under /proc/self/ns yields the same dev_t. This change iterates over entries under /proc/self/ns and uses the first one whose stat(2) succeeds.
Reported-by: Axel Karjalainen axel@axka.fi
Link: #2902 (comment)
Fixes: 7d5036f ("lsns: show namespaces only kept alive by open file descriptors")