From nobody Fri Nov 15 13:00:53 2024 X-Original-To: dev-commits-src-branches@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 4XqcZs5w5Xz5d6gd; Fri, 15 Nov 2024 13:00:53 +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 4XqcZs54WQz4pNV; Fri, 15 Nov 2024 13:00:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731675653; 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=n59KBt3o6Pe5sKXAGgx859yGXRUttzWwCazmIUt7uSk=; b=OmNOkJ2n0KFX7Ay8lXJMOWfN88YJDnCK4/Rf8golmdzWqbd2tsdF3hIzocleQEa/YqV9pl 8FU0jmP0Dy8hA4V/uXcsTZfDDf4dWNAil5eWkXjB7oQ90sTN3pk6n3WyT6oOLKDeAzKi/G xxZxfh4fCoTQW2DGKBZ0UZgwq8u+wyqxLIY7+LR/URZqfD29saHyLy7kX5Jf5DpUA6xHpa uZGG9m3zdACSeqYgTs2s0XGVYvT4X4Kq2ea8IMuwp784KNZdnX/CmAARY30c34E4g1Sy5i dPxYfkj7fmVYfg0mhZm2Rq3xpOqJZ1fWlSwrAq981clvjaSqenIgKM5UFFaGjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731675653; 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=n59KBt3o6Pe5sKXAGgx859yGXRUttzWwCazmIUt7uSk=; b=afJ9AoqaT6j11zLaVkGmJKnKEr39ySnQRk91m75rolfBMpljmrKldhhSL8qUR8yP/ZGynZ UpFKot3FZrodDMep4tw6PwEKhMJvpWzP6Z0dHuZlf50gjXCX0vxdvmJoj/Y7ZVwoBkrbIy g2TvRLhAiN2YTqTOTWYEi1+v7pGWqjxNUaAIIruYU8VNyUABhl0IZJPkllyiepsdVYTA2L Ne3DgZIYKwNwxXe+0040XbVePt9LnMK1+glQZizPMuFzygdyxV16Vp8r+zDu7eBdG8JIk3 /PahBadCN2Pm99I6L9UQP8+3UUtv8KPugpV0iQfVWD3lUCSRgM9n5JAtBzdUsw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1731675653; a=rsa-sha256; cv=none; b=ggdeBQe4A8WvEmsyjhRG7xxOGC/yMQMoy/ocbDZWrhPGqc8OzNUNrJVwcmniv/Vef7RPs2 Cb6KHSExPn8j/euqvsJf5N25adOSuyuuMfgMYuBPqNYmbjE0sP4g6Rzrw2o032EKWGwKJ3 e0gblrtDFmUBf7EbsQiYcYMPueln3K8OAVgqLX0kPBDLIm5MiYJKaPmz4m4JSU9DZyJweq AFsYOIgEXNRzIobpn1J1uuWHEJ3gOSQk2lePQQRZ76Pu9R6ARo+/KamaGya0b0Szcw1CX6 pMhe7K502Dv2OqEkO2w3bN/gd+Ex+RL1LGknYIqq1VZJqc5Qr38AVOwSD1eD9A== 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 4XqcZs4GYYzPNl; Fri, 15 Nov 2024 13:00:53 +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 4AFD0rEa071318; Fri, 15 Nov 2024 13:00:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AFD0rQD071315; Fri, 15 Nov 2024 13:00:53 GMT (envelope-from git) Date: Fri, 15 Nov 2024 13:00:53 GMT Message-Id: <202411151300.4AFD0rQD071315@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: c985effa7d91 - stable/13 - cred: New crsetgroups_fallback() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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: c985effa7d918a0e3c129613191c7f2307acb4ba Auto-Submitted: auto-generated The branch stable/13 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=c985effa7d918a0e3c129613191c7f2307acb4ba commit c985effa7d918a0e3c129613191c7f2307acb4ba Author: Olivier Certner AuthorDate: 2024-10-02 14:16:20 +0000 Commit: Olivier Certner CommitDate: 2024-11-15 12:59:09 +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 (cherry picked from commit d4e0d4d92e010b74404bddc87c1a1e8dbcaa25dd) Approved by: markj (mentor) --- 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 ae3667146519..ddd45ef1357b 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -2495,6 +2495,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 eb5f0ad839e5..876919f56fb1 100644 --- a/sys/sys/ucred.h +++ b/sys/sys/ucred.h @@ -170,6 +170,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.