From nobody Thu Oct 24 01:07:32 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XYnnw29hdz5Zsg9; Thu, 24 Oct 2024 01:07:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XYnnw1dPqz4tgp; Thu, 24 Oct 2024 01:07:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729732052; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ecQd4BdCtG8uCxJy4FkWHrr9Y5mNAoDNeBlOPqKgy/4=; b=yti7JFMs47E/WCzcbj9CGR83kRuugoVyO0VzRgHwOTonsAkenYegM+yKnZLDjsL0Tn9i3P 5bjTKHDH2h4OrshJ8kwAmSqESLwL/B4WM0elTI7XkDfXCxjCA3W3vUy56ujap40fZs9GoD KRmC0NGiVEduzERzClRrxhhh5PFpjPPzEz607wvVnx1+TMS7XroWKjRohr2NQtS2/WV1cJ 910iOGSIFeq9AsnT8QdN9eKaXiDWc3vNV0zkR6Y8VGGaclXmeZprAhO8YlcMgEzfkrDXOZ pxwHvLSaQnVqHUJ2xX57PRK+U14njlGBe9Hciu+a2Jo2zcREdNj3CcENOCkYwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729732052; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ecQd4BdCtG8uCxJy4FkWHrr9Y5mNAoDNeBlOPqKgy/4=; b=Llba4hajWBSN3v7d7UVuqmbSqpLXhYp2yv4u2GyyC7v5ZZ9BYfASoYJLPKc54hUaOhVz+t RtbWV/8y7yZ+4757P8PVrc0aotERrpl8U0mfJWibuBPtYItrh9hRM4lHbG9x6+kmQZ0HiH gslfRL9knA6SGLwTYui3p/tUBjdYavPXilKftzsxNrb1vuwqqT/mfnlQa0+FWQNch33DAD ch0My+wWz7XGqYMR3i/k/bxDq15/LULmBW4Mwd4Vk/WpRsIwmkG6LwwxNoGg7KUhVrEKb+ 7nPbWDWLKvEI9HmWHBm2pya/g54ahXv78ZxuBY+LRvAv1wrikI6boWhwcXqgDA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729732052; a=rsa-sha256; cv=none; b=jCnonBG2r3/Nmss6mJRzPs72lzwpml1PbsJ2Of2la1iWx+qUu+F9Glt3kJZeOOgY41YgZ8 0qPf2HjR2NcDNgCOkuEJhvxe+BFtieQTFIJODztpHT7e++dqxF+X1t2I7YNK70FerCYn7b upBMG6Lf0hlbvAtJOd3FvJ1dt9Bl/1JfOgehMOR02DygcyJw+DWT98CFdfagVaHp2/o25k aTz3rnag8YX31CfrfeG1PsUtvp9F9lmEQG2ouwLGrKRou1uHJjgOZJVUSkXtueKdPUELV0 GVIHQ3B+m/U2Txb2c9+Gjj20m543GPW/nKO0cqpmps1qyhmOX+YfLKiRdIXg7Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XYnnw1FM8zLQB; Thu, 24 Oct 2024 01:07:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49O17Wc7001732; Thu, 24 Oct 2024 01:07:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49O17WFB001729; Thu, 24 Oct 2024 01:07:32 GMT (envelope-from git) Date: Thu, 24 Oct 2024 01:07:32 GMT Message-Id: <202410240107.49O17WFB001729@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Rick Macklem Subject: git: f6e1add0c9d3 - stable/14 - nfsd: Fix handling of credentials with cr_ngroups == 0 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rmacklem X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: f6e1add0c9d3a3629f6968cb02a031c1d78b24c5 Auto-Submitted: auto-generated The branch stable/14 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=f6e1add0c9d3a3629f6968cb02a031c1d78b24c5 commit f6e1add0c9d3a3629f6968cb02a031c1d78b24c5 Author: Rick Macklem AuthorDate: 2024-10-21 22:48:39 +0000 Commit: Rick Macklem CommitDate: 2024-10-24 01:06:26 +0000 nfsd: Fix handling of credentials with cr_ngroups == 0 There has been a documented case in the exports(5) man page forever, which specifies that the -maproot or -mapall may have a single user entry, followed by a ':'. This case is defined as specifying no groups (aka cr_ngroups == 0). This patch fixes the NFS server so that it handles this case correctly. After MFC'ng this patch to stable/13 and stable/14, I propose that this unusual case be deprecated and no longer allowed in FreeBSD15. At that point, this patch can be reverted. (cherry picked from commit caa309c8811d62a24cd07e3a1f6e9095eaf10c90) --- sys/fs/nfsserver/nfs_nfsdsubs.c | 5 ++--- sys/kern/kern_prot.c | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sys/fs/nfsserver/nfs_nfsdsubs.c b/sys/fs/nfsserver/nfs_nfsdsubs.c index d80826993f23..2fd877775c79 100644 --- a/sys/fs/nfsserver/nfs_nfsdsubs.c +++ b/sys/fs/nfsserver/nfs_nfsdsubs.c @@ -1620,7 +1620,7 @@ nfsrv_checkuidgid(struct nfsrv_descript *nd, struct nfsvattr *nvap) if (nd->nd_cred->cr_uid == 0) goto out; if ((NFSVNO_ISSETUID(nvap) && nvap->na_uid != nd->nd_cred->cr_uid) || - (NFSVNO_ISSETGID(nvap) && nvap->na_gid != nd->nd_cred->cr_gid && + (NFSVNO_ISSETGID(nvap) && !groupmember(nvap->na_gid, nd->nd_cred))) error = NFSERR_PERM; @@ -1679,8 +1679,7 @@ nfsrv_fixattr(struct nfsrv_descript *nd, vnode_t vp, } if (NFSISSET_ATTRBIT(attrbitp, NFSATTRBIT_OWNERGROUP) && NFSVNO_ISSETGID(nvap)) { - if (nvap->na_gid == nd->nd_cred->cr_gid || - groupmember(nvap->na_gid, nd->nd_cred)) { + if (groupmember(nvap->na_gid, nd->nd_cred)) { nd->nd_cred->cr_uid = 0; nva.na_gid = nvap->na_gid; change++; diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index 7d28475b5db8..d7de7deb2c0c 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -1310,6 +1310,13 @@ bool groupmember(gid_t gid, struct ucred *cred) { + /* + * The nfsd server can use a credential with zero groups in it + * when certain mapped export credentials are specified via exports(5). + */ + if (cred->cr_ngroups == 0) + return (false); + if (gid == cred->cr_groups[0]) return (true);