Skip to content

lsns: don't abort if /proc/self/ns/user is absent; probe other ns entries#3772

Merged
karelzak merged 1 commit into
util-linux:masterfrom
masatake:lsns--dont-abort-if-no-user-ns
Oct 6, 2025
Merged

lsns: don't abort if /proc/self/ns/user is absent; probe other ns entries#3772
karelzak merged 1 commit into
util-linux:masterfrom
masatake:lsns--dont-abort-if-no-user-ns

Conversation

@masatake

@masatake masatake commented Oct 2, 2025

Copy link
Copy Markdown
Member

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")

…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>
@karelzak karelzak merged commit be97692 into util-linux:master Oct 6, 2025
34 of 35 checks passed
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.

2 participants