From nobody Thu Oct 24 01:14:22 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 4XYnxp4mnHz5ZtD1; Thu, 24 Oct 2024 01:14:22 +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 4XYnxp42nqz4vWt; Thu, 24 Oct 2024 01:14:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729732462; 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=vQTKpkiQyPlbboTfhV7Z2+1LMEtZCCM1pXL4Yqxl6LI=; b=DJbhFvMD6t4+QSdrLY9GFrq0iZUvS2VMe2KJ1aElXzRx3kLK0G3pjS9Kr9V6BWrku6MkBw Yki0tBtM+PwYORdEgBOBhRhymWvuB+FTVKwEiilfU6jb4lPxxUj4WVMyc8s7mO4qIed/Nk 0bdyB4xHuDHm2iOJgBL39AsfaK7Y5wY2J46ybKIrI1c69WIJJNSaPNMHORH8/jto2hgRrd bSv04dN4gnlHF0vjx8xdyivUZ1on9sFToFeBxXMYcBb4sbf5KXkVijulUqS15dOigzw33z SWvN2rEOp0+ic01+dcyLcJJsCEhIo4+66ysO6rNTWoVLesUYCCk3yb4hp2ELVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729732462; 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=vQTKpkiQyPlbboTfhV7Z2+1LMEtZCCM1pXL4Yqxl6LI=; b=h61ev12aGVrQ/UiYrK4njqoXzLlUSF2vB33zUUGM+i85OwbZvyaaHExpF5JvVK6BeJxK0Y 4zk6CPE79sD2YKKwUojFKb/7Iww34GpFhNn9SaR3/YykHGHB5H9UZ9n1UAVWDN8KCye2pm cEvwEafvadXUbKxR4/S2Lq1IH5mep0PP8ieHxwGLpbZoRMDMnBxW25lV4Pyuc5AI4VEvLb /UDLkOJ0iB6rYYQYbkExr04/DwLhy8LcRKJ5hVsqqpN/zCdxG4cmr8aCkonnd74candpfv O2lyD1B8fEJTw8h3cLVEPcfiSzQDtQlqS5INW4H7YIi9WlI0A1SI9fd0dyN7qw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729732462; a=rsa-sha256; cv=none; b=XWXOwtu/DOP4g5Z+IAT34jhvx74eF/5HigJb5G3zQWUzdIUnyCWLlvrnWYQU3GnsxIwElV BF45W9o03+B/P00t2ngP7yvEpzz2fFY8cPoITCiUiAbpKGhVqyFTSDIXjTrNNFUABeO3qo 3kSh55TPGCftKPKLIVaz2Rq8b47fAearShtHluh53SWme5VNskjCuZmLQt8d4QBq9NQLRt MOSvoxdIQnAwU2FDDT3BuT4jRfXVcTtLVs/PATTOUE4+PYyBHzZFaQQD2lGMwEHq9cr9Bo HIqF1M88CyoT8oAI/xDveKs+s5cw8H1uEMqYEOe1UQuVG4FRQKhIxLbsKNxRFg== 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 4XYnxp3dzrzLd2; Thu, 24 Oct 2024 01:14:22 +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 49O1EMPR018872; Thu, 24 Oct 2024 01:14:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49O1EMwr018869; Thu, 24 Oct 2024 01:14:22 GMT (envelope-from git) Date: Thu, 24 Oct 2024 01:14:22 GMT Message-Id: <202410240114.49O1EMwr018869@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: fcd20d3181a7 - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: fcd20d3181a7df9ebbb8d333db594a210194959f Auto-Submitted: auto-generated The branch stable/13 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=fcd20d3181a7df9ebbb8d333db594a210194959f commit fcd20d3181a7df9ebbb8d333db594a210194959f Author: Rick Macklem AuthorDate: 2024-10-21 22:48:39 +0000 Commit: Rick Macklem CommitDate: 2024-10-24 01:13:24 +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 0d7e4c73fe69..fa0222bbf3b2 100644 --- a/sys/fs/nfsserver/nfs_nfsdsubs.c +++ b/sys/fs/nfsserver/nfs_nfsdsubs.c @@ -1623,7 +1623,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; @@ -1682,8 +1682,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 5dea43971e3d..abe989045fb8 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -1306,6 +1306,13 @@ int 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 (0); + if (cred->cr_groups[0] == gid) return (1);