From nobody Sat Nov 02 20:39:36 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 4XgqN83vHPz5chQG; Sat, 02 Nov 2024 20:39:36 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XgqN82zg9z44FN; Sat, 2 Nov 2024 20:39:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730579976; 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=udMBqgu7bwJUpCr5gOazgYQaoxRdRzCO2SCEznmDP1Q=; b=Cl3YE3xnHTlqzaKlNwPIpTw7wOWmuo306/M9Te/Bf3omufzi5rlV/Ko8r+epVZVOmEXfjU eK2bfwSmRpKnscGLVNUht+9nu1hRC1Rvtx8R0oG6u20hYzbowmZpCUgDVM02Td9SGAw78M +DbpWCNoik6LMLbntPrKxDuMl5NxdIezaPSHr02uB67nZG+dYOPpIOvrtRE9chIgVKBpWv fn37+pXxxxgfxvkagiwqmfiA6Z80mNO+1a84bL78NfOjrwmDMzvgkpgsazgEGH9hdn3pMe w8xs5R8tEoM/UKlcHOEmpy4blRGDak9bFdmU4fTYVTG3gfMNyL8N1wb3YVlbpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730579976; 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=udMBqgu7bwJUpCr5gOazgYQaoxRdRzCO2SCEznmDP1Q=; b=iQicRBcAAjB/t//IilM5T5yFQO9CqMMFCRZ/w6QmqSeA9dctud46OxOGJFa106sa/c0QVF K7AQkXwVM9tkAzMFbCj4RfhfEgTlHSwnM4ZhprYipcTxIyqSGb31YFxijG6bFxdMklH99U u7B+bSlW6CpQ+WGPxBP4fOAeguYTagpuKpBmcUjn5IyOuHYt9zczpaEMXM9bJDzCZEOODq 5GjH9aHSVtYulsv720lmxYKbS6OeXQ3jn/F8pD7TDdcyl987mZ2ZfWz4O7g//z3vXWGGpj kdNdgXEIyg8JzVUriucorFFHM6njH69Bgx4F1thb5rXokO02CSMeDmfOluGk9w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730579976; a=rsa-sha256; cv=none; b=Tsci/2rCOiPyB+MkkIPGwQmmPmLTJzt31bhsYqbUjz3hoROr823Y/CYYWbr+dcWbjfKR7Z WNCQ70bU0Xx5nHZVuYIZztY0Pf5G9GU5JkhvLoMMK2r+dg+OfaYdpQhO3Q1hZ7wCSjgKs0 yPbRXfOX+xFNg6NIq7Uu37EEXHToYvoyq9Un0ClWS2VKtgl+MpwzNJsLR2myr7yodC3Gqu 7AvvAZvsuktPHOqR5B4DTqmy2ROBUJgPrbjEcR4TtCdosAGOZgx6IMXSeztEbpbVcsgNmu klMcly7kd7mQHS5YTnqYANOS2ilsakJ+LjYA5p8OzC0wRDxItadrZbxjjuaz4A== 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 4XgqN82Td4zKQq; Sat, 2 Nov 2024 20:39:36 +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 4A2KdaKE046520; Sat, 2 Nov 2024 20:39:36 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A2Kda2O046517; Sat, 2 Nov 2024 20:39:36 GMT (envelope-from git) Date: Sat, 2 Nov 2024 20:39:36 GMT Message-Id: <202411022039.4A2Kda2O046517@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Certner Subject: git: d4e0d4d92e01 - main - cred: New crsetgroups_fallback() 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/main X-Git-Reftype: branch X-Git-Commit: d4e0d4d92e010b74404bddc87c1a1e8dbcaa25dd Auto-Submitted: auto-generated The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=d4e0d4d92e010b74404bddc87c1a1e8dbcaa25dd commit d4e0d4d92e010b74404bddc87c1a1e8dbcaa25dd Author: Olivier Certner AuthorDate: 2024-10-02 14:16:20 +0000 Commit: Olivier Certner CommitDate: 2024-11-02 20:37:42 +0000 cred: New crsetgroups_fallback() Similar to crsetgroups(), but allows an empty group array in input, treating it like a one-element array containing the passed fallback group. Approved by: markj (mentor) MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D46917 --- sys/kern/kern_prot.c | 18 ++++++++++++++++++ sys/sys/ucred.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index 0f49d000dfd2..504c79313408 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -2487,6 +2487,24 @@ crsetgroups(struct ucred *cr, int ngrp, const gid_t *groups) groups_normalize(&cr->cr_ngroups, cr->cr_groups); } +/* + * Same as crsetgroups() but accepts an empty groups array. + * + * This function ensures that an effective GID is always present in credentials. + * An empty array is treated as a one-size one holding the passed effective GID + * fallback. + */ +void +crsetgroups_fallback(struct ucred *cr, int ngrp, const gid_t *groups, + const gid_t fallback) +{ + if (ngrp == 0) + /* Shortcut. */ + crsetgroups_internal(cr, 1, &fallback); + else + crsetgroups(cr, ngrp, groups); +} + /* * Get login name, if available. */ diff --git a/sys/sys/ucred.h b/sys/sys/ucred.h index b8a3b609abae..75156cca09a5 100644 --- a/sys/sys/ucred.h +++ b/sys/sys/ucred.h @@ -167,6 +167,8 @@ void crcowfree(struct thread *td); void cru2x(struct ucred *cr, struct xucred *xcr); void cru2xt(struct thread *td, struct xucred *xcr); void crsetgroups(struct ucred *cr, int ngrp, const gid_t *groups); +void crsetgroups_fallback(struct ucred *cr, int ngrp, const gid_t *groups, + const gid_t fallback); /* * Returns whether gid designates a primary group in cred.