Skip to content

RFC new mode 'shadow' for /proc/PID/setgroups

Giuseppe Scrivano lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest3 patches 13 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3setgroups: new mode 'shadow' for /proc/PID/setgroupsinclude/linux/cred.h include/linux/user_namespace.h kernel/groups.c +2 more+114 -339 replies
2/3getgroups: hide unknown groupskernel/groups.c kernel/uid16.c+44 -461 reply
3/3proc: hide unknown groups in statusfs/proc/array.c+10 -21 reply

Reviews trailers per patch

2 of 3 patches have a Reviewed-by or Acked-by.

PatchSerge Hallyn
1/3
2/3R-b
3/3R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [RFC PATCH 0/3] new mode 'shadow' for /proc/PID/setgroups

This series is based on some old patches I've been playing with some years ago, but they were never sent to lkml as I was not sure about their complexity/usefulness ratio. It was recently reported by another user that these patches are still useful[1] so I am submitting the last version and see what other folks think about this feature.

Since the fix for CVE-2014-8989 in order to set a gids mapping for a user namespace when the user namespace owner doesn't have CAP_SETGID in its parent, it is necessary to first disable setgroups(2) through /proc/PID/setgroups.

Setting up a user namespace with multiple IDs mapped into is usually done through the privileged helpers newuidmap/newgidmap. Since these helpers run either as setuid or with CAP_SET[U,G]ID file capabilities, it is not necessary to disable setgroups(2) in the created user namespace. The user running in the user namespace can use setgroups(2) and drop the additional groups that it had initially.

This is still an issue on systems where negative groups ACLs, i.e. the group permissions are more restrictive than the entry for the other categories, are used. With such configuration, allowing setgroups(2) would cause the same security vulnerability described by CVE-2014-8989.

This patchset adds a new 'shadow' mode for the /proc/PID/setgroups file. It permits to safely enable setgroups also when negative groups ACLs are used.
When the 'shadow' mode is written to /proc/PID/setgroups, the current process groups are stored into the user namespace and they will be silently added on each setgroups(2) call. A child user namespace won't be able to drop these groups anymore.

To fully take advantage of this feature, newgidmap will also need to learn about the 'shadow' mode. An idea is that when the system or the user are using negative groups ACLs, then newgidmap needs to check that /proc/PID/setgroups is set to 'deny' or 'shadow' before allowing a mapping. The configuration for negative groups ACLs can either be a system wide or per user setting.

[1] https://lore.kernel.org/lkml/[email protected]/T/#mc53e0fc80203b8209a8836d5861a267ce22c5c0f

Giuseppe Scrivano (3):
setgroups: new mode 'shadow' for /proc/PID/setgroups
getgroups: hide unknown groups
proc: hide unknown groups in status

 fs/proc/array.c                |  12 +++-
 include/linux/cred.h           |   4 +-
 include/linux/user_namespace.h |  11 +++-
 kernel/groups.c                | 100 +++++++++++++++++++++------------
 kernel/uid16.c                 |  90 ++++++++++++++++++-----------
 kernel/user_namespace.c        |  34 +++++++++--
 6 files changed, 169 insertions(+), 82 deletions(-)
Signature · 1 line
2.31.1