Skip to contentSkip to conversation

is one allowed to reenter a user namespace?

DISCUSSION Zbigniew Jędrzejewski-Szmek 2 participants 2 messages Jan 20, 2013 – Jan 21, 2013 Util-Linux package

lore
Share & tools
lore
#0 lore raw

Hi,
when trying to enter a namespace, the behaviour wrt. to entering an existing namespace that the process is _already_ a part of is different for user names and all other namespaces. For user namespaces one gets EINVAL, while for other namespaces it succeeds. In other words, for user namespaces only, entering the namspace is not idempotent.

# unshare --mount sleep 10000 &
# nsenter --target=$(pgrep sleep) --mount /bin/true
# nsenter --target=$(pgrep sleep) --ipc /bin/true
# nsenter --target=$(pgrep sleep) --net /bin/true
# nsenter --target=$(pgrep sleep) --uts /bin/true
# nsenter --target=$(pgrep sleep) --user /bin/true
nsenter: setns of 'ns/user' failed: Invalid argument
(and the EINVAL is from setns())

Is this difference intended?

-
Zbyszek

#1 lore raw
Quoted 17 lines · Zbigniew Jędrzejewski-Szmek

Hi,
when trying to enter a namespace, the behaviour wrt. to entering an existing namespace that the process is _already_ a part of is different for user names and all other namespaces. For user namespaces one gets EINVAL, while for other namespaces it succeeds. In other words, for user namespaces only, entering the namspace is not idempotent.

# unshare --mount sleep 10000 &
# nsenter --target=$(pgrep sleep) --mount /bin/true
# nsenter --target=$(pgrep sleep) --ipc /bin/true
# nsenter --target=$(pgrep sleep) --net /bin/true
# nsenter --target=$(pgrep sleep) --uts /bin/true
# nsenter --target=$(pgrep sleep) --user /bin/true
nsenter: setns of 'ns/user' failed: Invalid argument
(and the EINVAL is from setns())
Quoted 1 line

Is this difference intended?

Yes.

The definition of setns on a user namespace is that the process gains all capabilities in that namespace. As such if you could reenter your current user namespace you would gain all capabilities which would defeat the purpose of the capability bits.

Eric