Skip to content

Commit 4672adc

Browse files
Rick MacklemRick Macklem
authored andcommitted
nfs_commonsubs.c: Add a sanity check for nid_ngroup
The nfsuserd(8) daemon passes user credentials (uid + gids) into the kernel for users and groups identified by name (received from a NFSv4 server). This patch add a sanity check for the number of groups (nid_ngroup) passed in. It's only purpose is to protect against a bogus nfsuserd(8) running in a jail. Reported by: Ilja Van Sprundel <[email protected]> Reviewed by: markj MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D53389
1 parent 9447a40 commit 4672adc

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

sys/fs/nfs/nfs_commonsubs.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4192,10 +4192,15 @@ nfssvc_idname(struct nfsd_idargs *nidp)
41924192
nidp->nid_namelen);
41934193
if (error == 0 && nidp->nid_ngroup > 0 &&
41944194
(nidp->nid_flag & NFSID_ADDUID) != 0) {
4195-
grps = malloc(sizeof(gid_t) * nidp->nid_ngroup, M_TEMP,
4196-
M_WAITOK);
4197-
error = copyin(nidp->nid_grps, grps,
4198-
sizeof(gid_t) * nidp->nid_ngroup);
4195+
grps = NULL;
4196+
if (nidp->nid_ngroup > NGROUPS_MAX)
4197+
error = EINVAL;
4198+
if (error == 0) {
4199+
grps = malloc(sizeof(gid_t) * nidp->nid_ngroup, M_TEMP,
4200+
M_WAITOK);
4201+
error = copyin(nidp->nid_grps, grps,
4202+
sizeof(gid_t) * nidp->nid_ngroup);
4203+
}
41994204
if (error == 0) {
42004205
/*
42014206
* Create a credential just like svc_getcred(),

0 commit comments

Comments
 (0)