]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
nsenter: Fix invalid fd check in enter_namespaces
authorVladimir Riabchun <vladimir.riabchun@virtuozzo.com>
Wed, 10 Jun 2026 13:28:48 +0000 (15:28 +0200)
committerVladimir Riabchun <vladimir.riabchun@virtuozzo.com>
Wed, 10 Jun 2026 13:28:51 +0000 (15:28 +0200)
When nsenter is executed with closed stdin, one pid_fd will be 0,
which is a valid file descriptor. But with current code namespace switch
is skipped, leading to incorrect results.

Fixes: f18be0ca5aa7 ("nsenter: use pidfd to enter target namespaces")
Signed-off-by: Vladimir Riabchun <vladimir.riabchun@virtuozzo.com>
sys-utils/nsenter.c

index b10c5773f0515aad890686ee5ae355c5ce6920e9..c1706cef948d5874bcda741a4ec8d43cff8442fe 100644 (file)
@@ -356,7 +356,7 @@ static void enter_namespaces(int pid_fd, int namespaces, bool ignore_errors)
 {
        struct namespace_file *n =  NULL;
 
-       if (pid_fd) {
+       if (pid_fd >= 0) {
                int ns = 0;
                while ((n = next_enabled_nsfile(n, namespaces))) {
                        if (n->fd < 0)