aboutsummaryrefslogtreecommitdiffstats
path: root/net/sunrpc/svcauth_unix.c
diff options
context:
space:
mode:
authorAlexey Dobriyan <adobriyan@gmail.com>2016-10-07 20:03:12 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-10-07 21:46:30 -0400
commit81243eacfa400f5f7b89f4c2323d0de9982bb0fb (patch)
tree9f0bc53a6569fdf1de3d30a61a80386b8bbd1c1f /net/sunrpc/svcauth_unix.c
parent954f74bf45268bcee0af21b6393c9c8acca7e075 (diff)
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> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'net/sunrpc/svcauth_unix.c')
-rw-r--r--net/sunrpc/svcauth_unix.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index dfacdc95b3f5..64af4f034de6 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -517,7 +517,7 @@ static int unix_gid_parse(struct cache_detail *cd,
517 kgid = make_kgid(&init_user_ns, gid); 517 kgid = make_kgid(&init_user_ns, gid);
518 if (!gid_valid(kgid)) 518 if (!gid_valid(kgid))
519 goto out; 519 goto out;
520 GROUP_AT(ug.gi, i) = kgid; 520 ug.gi->gid[i] = kgid;
521 } 521 }
522 522
523 ugp = unix_gid_lookup(cd, uid); 523 ugp = unix_gid_lookup(cd, uid);
@@ -564,7 +564,7 @@ static int unix_gid_show(struct seq_file *m,
564 564
565 seq_printf(m, "%u %d:", from_kuid_munged(user_ns, ug->uid), glen); 565 seq_printf(m, "%u %d:", from_kuid_munged(user_ns, ug->uid), glen);
566 for (i = 0; i < glen; i++) 566 for (i = 0; i < glen; i++)
567 seq_printf(m, " %d", from_kgid_munged(user_ns, GROUP_AT(ug->gi, i))); 567 seq_printf(m, " %d", from_kgid_munged(user_ns, ug->gi->gid[i]));
568 seq_printf(m, "\n"); 568 seq_printf(m, "\n");
569 return 0; 569 return 0;
570} 570}
@@ -817,7 +817,7 @@ svcauth_unix_accept(struct svc_rqst *rqstp, __be32 *authp)
817 return SVC_CLOSE; 817 return SVC_CLOSE;
818 for (i = 0; i < slen; i++) { 818 for (i = 0; i < slen; i++) {
819 kgid_t kgid = make_kgid(&init_user_ns, svc_getnl(argv)); 819 kgid_t kgid = make_kgid(&init_user_ns, svc_getnl(argv));
820 GROUP_AT(cred->cr_group_info, i) = kgid; 820 cred->cr_group_info->gid[i] = kgid;
821 } 821 }
822 if (svc_getu32(argv) != htonl(RPC_AUTH_NULL) || svc_getu32(argv) != 0) { 822 if (svc_getu32(argv) != htonl(RPC_AUTH_NULL) || svc_getu32(argv) != 0) {
823 *authp = rpc_autherr_badverf; 823 *authp = rpc_autherr_badverf;