From nobody Fri Nov 15 10:49:02 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 4XqYfl0wp7z5cyqF; Fri, 15 Nov 2024 10:49:03 +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 4XqYfk4h8hz4X08; Fri, 15 Nov 2024 10:49:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731667742; 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=Tw+vm8OdCtBFbrid/ghRKxcZbKeh2SndpiU8EIQVrGo=; b=VspqJIcWX8AkZGkmxBV9y/fDVRzXVghPSYYf/GC7M6LGyY5YMtc5FfGox89A2ZDc8mrJOZ D5Ghyr8I3OiExShxUGSCvGhb5OC1cSflS5tdvkujSlaSO4uGXFv7FSvRPMOsShhtmemFEV kUUG191iFL3DJ235rCqvdB0M0q5XNowoFFoPQwnKzDvRrakq1t3Ti5ePTzcc83o6YCQ25q VSqUtHJZ5nBWAnw9q7jfyjWng/KbKu9pp9cDY1zhT7JtF/LyVn0tc774ZqP7rm2FqChPyd 9NL5XODGnHURGo8FfdVQG1wdmg10w9Bxdz3NbSqV90+LNG2cfsmQTXZAX8MIGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731667742; 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=Tw+vm8OdCtBFbrid/ghRKxcZbKeh2SndpiU8EIQVrGo=; b=tVkIjrarVM3tS4Jl4uTZ7gpg2DdbwS9TTap0UVvVVk0XpqfL2X1c6Xcbz6LJ8hIErfwOG4 C2ngMqr+J6Nq1mLWBum5fE63ikoXgtFayUYNwzhBoTqlqbGVgFHkt9vO9jePKhLgT+U6S7 wUXbLuyyruw4dIzaMkB7zYycUlhpcV4aM8ahOAdc3K+MScVtSI5EzpkcOfwy04wHUDCB3J Pyh/8j2jZzFWEMB2ZgWyc4llNiX7SX2lqN+3aMk7z+ig0q2n5h+O+eCeV+ogmq/p29UdeC W6kX8SAjs1WnjXchCqZL46uNG50wKRElwlYGHcqO241sYiA1F5ch2LfzU5Toeg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1731667742; a=rsa-sha256; cv=none; b=ojfkKut61GViVf/vfZY5iX268QZsFG3vsaA8uuc6WdRP6WGnmucBg43s7R0etJ8kWTCeQv pg81hw6gXHh0G9q6i0Lfh6DVniycDxCJw44Qodf3qbO9kJ+eXdBEWQ1s8glHQQEYwC/U6P oS7dOdgChjWjddbZjtmr7rc2dxptfy+dCVUtk7TbnFDncOEnKNpJUERzaBtHIMhPIq3aZH B6v5GFTHktHVnnsvnxCZY/noRj9gQL7S/9lufku74L4woqp4YopPvGHkV9JcbvGNa87oH3 O2XokDXaAerIJnC9bJ7kcbXaIepfKxiEBpHBsukceU3wEIwkFpEW351GnBoHHA== 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 4XqYfk2xy3zKSf; Fri, 15 Nov 2024 10:49:02 +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 4AFAn2EV018150; Fri, 15 Nov 2024 10:49:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AFAn2F1018147; Fri, 15 Nov 2024 10:49:02 GMT (envelope-from git) Date: Fri, 15 Nov 2024 10:49:02 GMT Message-Id: <202411151049.4AFAn2F1018147@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: 13784bf22df3 - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 13784bf22df357d2b944e719993f2d25d4324dd2 Auto-Submitted: auto-generated The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=13784bf22df357d2b944e719993f2d25d4324dd2 commit 13784bf22df357d2b944e719993f2d25d4324dd2 Author: Olivier Certner AuthorDate: 2024-10-02 14:16:20 +0000 Commit: Olivier Certner CommitDate: 2024-11-15 10:47: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 (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 1cc5ce46c3bf..db07c265dc13 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -2498,6 +2498,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 cd07ec3be445..e7f8d7328dda 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.