summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorJeremie Courreges-Anglas <jca@cvs.openbsd.org>2024-11-04 21:59:16 +0000
committerJeremie Courreges-Anglas <jca@cvs.openbsd.org>2024-11-04 21:59:16 +0000
commit440fa9681669edc3ab6d57985886cf874651b334 (patch)
treeac3c3c98c034b667ef754d42a03ad6c3754d5ce3 /sbin
parentfb9348cbdf5296f2eaba2d14073d6cb6b3cb1e41 (diff)
Ignore extra groups that don't fit in the buffer passed to getgrouplist(3)
Our kernel supports 16 groups (NGROUPS_MAX), but nothing prevents an admin from adding a user to more groups. With that tweak we'll keep on ignoring them instead of potentially reading past the buffer passed to getgrouplist(3). That behavior is explicitely described in initgroups(3). ok millert@ gilles@
Diffstat (limited to 'sbin')
-rw-r--r--sbin/mountd/mountd.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/sbin/mountd/mountd.c b/sbin/mountd/mountd.c
index 0ca61b39eb4..943b2fe7fad 100644
--- a/sbin/mountd/mountd.c
+++ b/sbin/mountd/mountd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mountd.c,v 1.92 2024/05/21 05:00:47 jsg Exp $ */
+/* $OpenBSD: mountd.c,v 1.93 2024/11/04 21:59:15 jca Exp $ */
/* $NetBSD: mountd.c,v 1.31 1996/02/18 11:57:53 fvdl Exp $ */
/*
@@ -2157,7 +2157,7 @@ parsecred(char *namelist, struct xucred *cr)
char *name, *names;
struct passwd *pw;
struct group *gr;
- int ngroups, cnt;
+ int maxgroups, ngroups, cnt;
/*
* Set up the unprivileged user.
@@ -2182,9 +2182,12 @@ parsecred(char *namelist, struct xucred *cr)
return;
}
cr->cr_uid = pw->pw_uid;
- ngroups = NGROUPS_MAX + 1;
- if (getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups))
+ maxgroups = ngroups = NGROUPS_MAX + 1;
+ if (getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups) == -1) {
syslog(LOG_ERR, "Too many groups for %s: %m", pw->pw_name);
+ /* Truncate group list */
+ ngroups = maxgroups;
+ }
/*
* compress out duplicate
*/