From nobody Fri Jan 17 12:27:11 2025 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 4YZJrw3CKPz5kvcw; Fri, 17 Jan 2025 12:27:12 +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 4YZJrv43Fsz3Tdj; Fri, 17 Jan 2025 12:27:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737116831; 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=s1IKdbU2DukJqO4vJk6k6vUaho0PKbamOf79Mnb/mUs=; b=oQhcbHY54cv5NUdsCs9lH0HFpeRDZYFiev1SkSA0CPkQsSmw93LyPkOQ8Q1sfWmI8k+MxG L/vL3W2SESjjHvWha0l2UY4xd7EWK4rlOmauh/q+O0oPltbazpBixRNZssQ7U3gwkpGauF DaKyG2btZfRb990QqksuPSChrDbe0Qx4SnCOgqhzTMeOPpKRBCFyjAXsDdZFwV2rBLyCtp AvRj23mqHF3qcFJBd4SoNLfMBnOozq9JCWfpTfoVPrHrlDgqts2P+6XcB7urbXtB+/kzgb 2JiCKqdgB+V/tYh+4zWqAfZK5PXGPcMZ9/vb/a6NTJzZj339VTnkfpaBsLdhvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737116831; 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=s1IKdbU2DukJqO4vJk6k6vUaho0PKbamOf79Mnb/mUs=; b=lHCUgz0hu5gSC0iVuPl8pEar75dGo1PaCBuoBPsuoKPn8LaErP1mzDlCU7hHplopvegF9Z 7RypMwaJ13nZOMPDOMYQobbg9hcZuJ3YHTe2sDKAUhV7Wv+oSuDgOQGLsZ2QAuw2+bAgdL x/8ZPUKDBIciXB16HDTZuvgvTDI2VJy7u5JRfYh4KE0Yf6O1a1+TkX9SDVZ5eH7w5yvTK5 gRGmGRer/kHwDAGaCzSL+G0k2XtC+0OcTFGdXBFmS6YO4RUuZSIvyUfLTTSZoIHEdGFZ6T PLPv25YMmtckvB0VmsxerkxIEIpkAKlZC/fNynIlUimnpjkK6s9r6sXm28S3Mg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737116831; a=rsa-sha256; cv=none; b=pUSgrAUbOiNQ6U3ObJWuGfHGvIb3FJobN2CHSdD0mzht150/PgqhSyhtlKFppqBHpk+b6j qOu9Jxr1BqG06uB+KcGJ+RVdNkt40Rm9Q2Veq4OuapChMyfLxz3ENVRw0BvoDB3HfV0mr8 RgkHfSSO1ySdxK0mhCxgT1iF5iWQgd+XVH80+blJ5MiGCGiUmBhr6qLWS3+GUjDq6TBTKW Ax2X3LavPAX3P/trqUm5h6G/J4yN6m1yUqBOLB7ThLs/YXPPT2838uN20vzJC10BYAxlbx 5q06s+exIS3Hwvagna/P/mu8YZVgQrKoeosFg9utWiwGY88sbqtzB/4ErQJWTw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4YZJrv3cGnz2lx; Fri, 17 Jan 2025 12:27:11 +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 50HCRBgx052378; Fri, 17 Jan 2025 12:27:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50HCRB1m052375; Fri, 17 Jan 2025 12:27:11 GMT (envelope-from git) Date: Fri, 17 Jan 2025 12:27:11 GMT Message-Id: <202501171227.50HCRB1m052375@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: 29a0511b184d - stable/13 - mountd(8): parsecred(): Fallback to "nogroup" or GID_NOGROUP 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: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 29a0511b184d6d59c6b0fee72dd6f48e6b8d0081 Auto-Submitted: auto-generated The branch stable/13 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=29a0511b184d6d59c6b0fee72dd6f48e6b8d0081 commit 29a0511b184d6d59c6b0fee72dd6f48e6b8d0081 Author: Olivier Certner AuthorDate: 2024-10-08 09:21:17 +0000 Commit: Olivier Certner CommitDate: 2025-01-17 12:24:51 +0000 mountd(8): parsecred(): Fallback to "nogroup" or GID_NOGROUP In the 'uid:gid:gid:...' case (for '-maproot' or '-mapall'), if no GID is specified at all (i.e., input is of the form 'uid:', with the colon at the end), mountd(8) would pass credentials with an empty array of groups to the kernel. For security reasons, we have put in place a kernel fallback a while ago, which is to use the single group GID_NOGROUP (see commits cfbe7a62dc62 ("nfs, rpc: Ensure kernel credentials have at least one group") and 5169d4307eb9 ("nfs: Fallback to GID_NOGROUP on no groups")). Here, as we are in userland, we first try to find the GID number corresponding to "nogroup", and only then fall back to GID_NOGROUP, as nfsuserd(8) does. Approved by: markj (mentor) MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D47011 (cherry picked from commit bdc259ef382f76b1821d4356049d5b856c42901a) --- usr.sbin/mountd/mountd.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/usr.sbin/mountd/mountd.c b/usr.sbin/mountd/mountd.c index ebd88d3fdd66..6b3a9af1c279 100644 --- a/usr.sbin/mountd/mountd.c +++ b/usr.sbin/mountd/mountd.c @@ -273,6 +273,8 @@ static int xdr_mlist(XDR *, caddr_t); static void terminate(int); static void cp_cred(struct expcred *, struct expcred *); +static gid_t nogroup(); + #define EXPHASH(f) (fnv_32_buf((f), sizeof(fsid_t), 0) % exphashsize) static struct exportlisthead *exphead = NULL; static struct exportlisthead *oldexphead = NULL; @@ -1577,7 +1579,7 @@ get_exportlist_one(int passno) anon.cr_groups = anon.cr_smallgrps; anon.cr_uid = UID_NOBODY; anon.cr_ngroups = 1; - anon.cr_groups[0] = GID_NOGROUP; + anon.cr_groups[0] = nogroup(); exflags = MNT_EXPORTED; got_nondir = 0; opt_flags = 0; @@ -3582,7 +3584,7 @@ parsecred(char *namelist, struct expcred *cr) */ cr->cr_groups = cr->cr_smallgrps; cr->cr_uid = UID_NOBODY; - cr->cr_groups[0] = GID_NOGROUP; + cr->cr_groups[0] = nogroup(); cr->cr_ngroups = 1; /* * Get the user's password table entry. @@ -3651,6 +3653,11 @@ parsecred(char *namelist, struct expcred *cr) } groups[cr->cr_ngroups++] = group; } + if (cr->cr_ngroups == 0) { + /* cr->cr_groups[0] filled at start with nogroup(). */ + cr->cr_ngroups = 1; + return; + } if (cr->cr_ngroups > SMALLNGROUPS) cr->cr_groups = malloc(cr->cr_ngroups * sizeof(gid_t)); memcpy(cr->cr_groups, groups, cr->cr_ngroups * sizeof(gid_t)); @@ -3989,3 +3996,19 @@ cp_cred(struct expcred *outcr, struct expcred *incr) memcpy(outcr->cr_groups, incr->cr_groups, incr->cr_ngroups * sizeof(gid_t)); } + +static gid_t +nogroup() +{ + static gid_t nogroup = 0; /* 0 means unset. */ + + if (nogroup == 0) { + const struct group *gr = getgrnam("nogroup"); + + if (gr != NULL && gr->gr_gid != 0) + nogroup = gr->gr_gid; + else + nogroup = GID_NOGROUP; + } + return (nogroup); +}