cred: simpler, 1D supplementary groups
authorAlexey Dobriyan <adobriyan@gmail.com>
Sat, 10 Sep 2016 10:34:19 +0000 (20:34 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Sat, 10 Sep 2016 10:34:19 +0000 (20:34 +1000)
commitd3db3451c1e74aade6938a02d346f4b0b8187a77
treea188a05cef2ddbd556a5a15c1b35ed6b030e0e57
parent8ee9c3ad64c45bde8253bcc02390d0634e93be98
cred: simpler, 1D supplementary groups

Current supplementary groups code can massively overallocate memory and is
implemented in a way so that access to individual gid is done via 2D
array.

If number of gids is <= 32, memory allocation is more or less tolerable
(140/148 bytes).  But if it is not, code allocates full page (!)
regardless and, what's even more fun, doesn't reuse small 32-entry array.

2D array means dependent shifts, loads and LEAs without possibility to
optimize them (gid is never known at compile time).

All of the above is unnecessary.  Switch to the usual
trailing-zero-len-array scheme.  Memory is allocated with
kmalloc/vmalloc() and only as much as needed.  Accesses become simpler
(LEA 8(gi,idx,4) or even without displacement).

Maximum number of gids is 65536 which translates to 256KB+8 bytes.  I
think kernel can handle such allocation.

On my usual desktop system with whole 9 (nine) aux groups,
struct group_info shrinks from 148 bytes to 44 bytes, yay!

Nice side effects:
* "gi->gid[i]" is shorter than "GROUP_AT(gi, i)", less typing,

* fix little mess in net/ipv4/ping.c
  should have been using GROUP_AT macro but this point becomes moot,

* aux group allocation is persistent and should be accounted as such.

Link: http://lkml.kernel.org/r/20160817201927.GA2096@p183.telecom.by
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Vasily Kulikov <segoon@openwall.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
14 files changed:
arch/s390/kernel/compat_linux.c
drivers/staging/lustre/lustre/ptlrpc/sec.c
fs/nfsd/auth.c
fs/nfsd/nfs4state.c
fs/proc/array.c
include/linux/cred.h
kernel/groups.c
kernel/uid16.c
net/ipv4/ping.c
net/sunrpc/auth_generic.c
net/sunrpc/auth_gss/gss_rpc_xdr.c
net/sunrpc/auth_gss/svcauth_gss.c
net/sunrpc/auth_unix.c
net/sunrpc/svcauth_unix.c
This page took 0.028309 seconds and 5 git commands to generate.