From nobody Mon Oct 28 18:58:29 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 4XcjMn5qbnz5bfK2; Mon, 28 Oct 2024 18:58:29 +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 4XcjMn4fR2z4PrK; Mon, 28 Oct 2024 18:58:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730141909; 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=52SbUZ5sUqy4ub3uOQIr/FThes+tvNyBAR15D81VikM=; b=OEs7oUwSS9DVVbZ7+6h52R4AZQ2XS41QApkCbOhrQBsbR60n3V/Q2Fz3PviilE1HlKh4QR qB4cFOv17u6YJmOh63v4/2+DUsuTr8EBJuKYEnWwLO0IheCkgulGYl5RmSVzXHR3JquKbX oc9cC4VrXtRMVBe50CEiYFvUvUgsKj4Gb+u61b1qIaFTE21O7jRbYuuOyGDOe15r2rQmHQ oN2aziC1iS52UCALvkeYKNJWcayzFTiTSF3Hz47ovIUDYGefqIt9Zm/nSys+l058rY+Nwy 29fjcBvZnfk5VTUPzDCVF8llh6C04QnxkVDz0vVIEdMhTWkCZJKM9GOKbgoMkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730141909; 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=52SbUZ5sUqy4ub3uOQIr/FThes+tvNyBAR15D81VikM=; b=p/V9M0ZHcN//yWsVUdobeOAsPF86Ty21aLUGhXJFxjrrYjz1tTwvIMkqLFbFPjMb7rmXEm ej1HZAXKeGH/tXQX9wixmt+BQEsFGSUKTL08RYvQDCeF6M3WypMCegBsG7crObOkMND08u Tjc8GwqnuapKOPzDSPJDlD1+1vWSKZSlAj45QLrmB96kb07sSMQ8H3Ai7ytSLMmyzLP324 MNwAMRgk3WyNUiAAEttu71jzyo6X23Cptfc9GJghyA8BBGANKZRxM5l3rt5oDD0IcDw7f0 qOmdIqrSKmaohUCjMbB0P03KKTm57jsrNudGLTU5NPaIbHKCqmlTWRZpmDCdaA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730141909; a=rsa-sha256; cv=none; b=NOXFEurkU9/GATh13u2UIygdNU9OYl3AYhyZWbScre8AxX1A5v39Z9TSODWOZigAD7vqMT xIist/cLbP2Z/uSAMuoxeCUJ7mXoBZWrOiLPUSz79/t1w3WpRH6f7kB5l7vpXl0TedKDDS 0Yv/OjsccsiD5UaQ1uuduix4UhY3g5L7OCpX0nOTbjwtNBtMUIlZYcdomdIcOMz1iX/jEZ h3UJs/ruoNDoduABaMZtVWu00Ahwt8knLwcW7lP3vLA0S4IPj+b/Fk9A1mjO+cB5fWzIws bszSU5MJQZ0TcZNlv0/2z1hilEZkDUEXRYE2BRW/8rxkBXAtwE65G6Lm2tnj7w== 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 4XcjMn47KVzqs0; Mon, 28 Oct 2024 18:58:29 +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 49SIwT4K061251; Mon, 28 Oct 2024 18:58:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49SIwTuF061249; Mon, 28 Oct 2024 18:58:29 GMT (envelope-from git) Date: Mon, 28 Oct 2024 18:58:29 GMT Message-Id: <202410281858.49SIwTuF061249@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Li-Wen Hsu Subject: git: 7937bfbc0ca5 - main - mac_do(4): Enhance GID rule validation to check all groups in cr_groups 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: lwhsu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7937bfbc0ca53fe7cdd0d54414f9296e273a518e Auto-Submitted: auto-generated The branch main has been updated by lwhsu: URL: https://cgit.FreeBSD.org/src/commit/?id=7937bfbc0ca53fe7cdd0d54414f9296e273a518e commit 7937bfbc0ca53fe7cdd0d54414f9296e273a518e Author: Li-Wen Hsu AuthorDate: 2024-10-28 18:58:12 +0000 Commit: Li-Wen Hsu CommitDate: 2024-10-28 18:58:12 +0000 mac_do(4): Enhance GID rule validation to check all groups in cr_groups Previously, the rule validation only checked the primary GID (cr_gid). This caused issues when applying GID-based rules, as users with matching secondary groups were not considered valid. This patch modifies both functions to iterate through all groups in cr_groups to ensure all group memberships are considered when validating GID-based rules. For example, a user's primary group is staff (20) and they are also in the wheel (0) group, this change allows the rule gid=0:any to enable them to run commands as any user. Reviewed by: delphij (earlier version), bapt Differential Revision: https://reviews.freebsd.org/D47304 --- sys/security/mac_do/mac_do.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/security/mac_do/mac_do.c b/sys/security/mac_do/mac_do.c index 507e64ea0175..1aad37f549bc 100644 --- a/sys/security/mac_do/mac_do.c +++ b/sys/security/mac_do/mac_do.c @@ -411,7 +411,7 @@ rule_is_valid(struct ucred *cred, struct rule *r) { if (r->from_type == RULE_UID && r->f_uid == cred->cr_uid) return (true); - if (r->from_type == RULE_GID && r->f_gid == cred->cr_gid) + if (r->from_type == RULE_GID && groupmember(r->f_gid, cred)) return (true); return (false); } @@ -516,7 +516,7 @@ check_setuid(struct ucred *cred, uid_t uid) } } if (r->from_type == RULE_GID) { - if (cred->cr_gid != r->f_gid) + if (!groupmember(r->f_gid, cred)) continue; if (r->to_type == RULE_ANY) { error = 0;