Skip to content

newgidmap with only own gid, blocks nsenter #1256

@eZioPan

Description

@eZioPan

Let's assume user_a has GID 1000, and an entry in /etc/subgid user_a:10000:100.

When user run following commands:

unshare --user -- catatonit -P &
newuidmap <PID> 0 1000 1
newgidmap <PID> 0 1000 1
nsenter --target <PID> --user

nsenter will return nsenter: setgroups failed: Operation not permitted, since /proc/<PID>/setgroups has been set to deny.

But if user add an extra gid map, then nsenter works:

unshare --user -- catatonit -P &
newuidmap <PID> 0 1000 1
# add a range within /etc/subgid
newgidmap <PID> 0 1000 1 1 10000 10
nsenter --target <PID> --user

I don't get it logically why add an extra gid map should make /proc/<PID>/setgroups becomes allow. And this further affect nsenter's behavior.

I find this code leaves *allow_setgroups unmodified and makes setgroups to deny.

shadow/src/newgidmap.c

Lines 41 to 45 in ea109a3

/* Allow a process to map its own gid. */
if ((range->count == 1) && (getgid() == range->lower)) {
/* noop -- if setgroups is enabled already we won't disable it. */
return true;
}

Is this behavior intentional (set own gid map only cause setgroups to deny)? Or could this a bug from nsenter(require a setgroups to work)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions