From nobody Mon Oct 21 22:50:24 2024 X-Original-To: dev-commits-src-main@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 4XXVrc3y24z51jpv; Mon, 21 Oct 2024 22:50:24 +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 4XXVrc34Xlz4nw1; Mon, 21 Oct 2024 22:50:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729551024; 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=o/pIKOC/rtX4vHp05psP8toOjOCGXogDEr1wOkpgnv8=; b=RWfzC0FmBHy8dCTnn6jNk8cHtmmkPM2HmiOdDxeRPQuoNGRq3WUavzibtNxrdUWSbRA1Sf Vl94dGIoemrZ1yLD+sew14k2J31xYRsFKW3HlJ68kAOmz2R11VWYEFKjEr/jtwzUFff1IW jMqJSVH+rwm4BiRd+AFcbvkd54PXBs6oxqvvqnKTcDMBvnST38LmtLOBbpKR6TC8otoblG syAtJQ62TNLt2wBMnJ85vCDg2jIODtit7kIXzlugpKMoNlAFwXoMGXyoidvTau0NFsUd5H IuldzN6TvxTkArxjdee56x0I4sPd9Kb0bFPi4XagFtwD5YBnaUiK4ElLdyf04g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729551024; 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=o/pIKOC/rtX4vHp05psP8toOjOCGXogDEr1wOkpgnv8=; b=NifCAPXYRxeYj+HjqN9d07BA2lD+fns1RUMlVWyZqxo87d8KQE/y/K3uDwTV9wid3pSi/6 jhj39Hk0xEJti4YYe+t5n4bJM2B0L3V+Jh3FkoDP/dS+n9+Z12i/yEmxe+qZXfTKvIKvRR KxJM23unHxW7gjhrb6CehWYp4GsWw+XM1VwJBUFO3AtKPck5LOnKd2wWqkxxYQ8IVvJ9Ke JQ0S9+gofh26IMJRV7INyAq70LGB5XGh0rMQ4mQ0KXvza4MLf1jNYTSfLpaA61FwwkfB1T eOFFcK66/+oLV2pcCwN5dzsw5sjVw+F8UQm+l3QUerJ5l+8DqhMo5h9j7C2AZw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729551024; a=rsa-sha256; cv=none; b=mi/7M79pXifY/WUGyU0GlJNiLWz0nFIEhDwrxWRozegHIVtvtYbRodjwRxAqUH+KRRa50Y /arC2uGozW6Us0YoTWfwuHaZqqWZdWQslViffING6KcWBOfvrO1xlBl6Zq2ul2COiLfoQ7 oyrR3meSPSCesWyFwZCmfs/eunZaVcxawm3GOPb9sZ5wWOKIHGMvfyo7BC64Ma+fLoKS/o keGchwnnyh9Je3KtXDA4Xjx476q6RXQaj7zyX+bDQsnz2bEr/+QMIuS534qa1SZY+MOMZZ naGq8IkgML0hmcZEjUwmUzXsrHVQSA/uPxTFxvlq98SNcWFohj9Qmrkh86vRpQ== 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 4XXVrc2csmznj1; Mon, 21 Oct 2024 22:50:24 +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 49LMoOBB010087; Mon, 21 Oct 2024 22:50:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49LMoOaG010084; Mon, 21 Oct 2024 22:50:24 GMT (envelope-from git) Date: Mon, 21 Oct 2024 22:50:24 GMT Message-Id: <202410212250.49LMoOaG010084@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Rick Macklem Subject: git: caa309c8811d - main - nfsd: Fix handling of credentials with cr_ngroups == 0 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: caa309c8811d62a24cd07e3a1f6e9095eaf10c90 Auto-Submitted: auto-generated The branch main has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=caa309c8811d62a24cd07e3a1f6e9095eaf10c90 commit caa309c8811d62a24cd07e3a1f6e9095eaf10c90 Author: Rick Macklem AuthorDate: 2024-10-21 22:48:39 +0000 Commit: Rick Macklem CommitDate: 2024-10-21 22:48:39 +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. Reviewed by: brooks MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D47204 --- 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 40cfa236a07d..95362ce8a310 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);