From nobody Fri Oct 10 17:16:18 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 4cjtgk4vnTz6Bd0s; Fri, 10 Oct 2025 17:16:18 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cjtgk35vPz3gBQ; Fri, 10 Oct 2025 17:16:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1760116578; 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=qEv9G34iWB192XAtALwkSRCiaSBMJzSaf/7oJgzv33Q=; b=f7wyOf3qkvLlIDhNoF0+nRUi38YwjfOxevXDoHDxbMvYyJ+BdhTI0YaSpcHTnhSNbGU2Bj Ue9Jioy8Jfd2dzvVX54ddUdgivs6g84dGpALgY+Dx9Qmh1JrwYeBaJhX6KR1ugcBnPQSim DupRJGPqJMwWvgrAoc6U1JrMtQo2FUy72MS7KGvEWTdWzVG3Hb4iDt+SUDfucrS2Cbqk0l cHWQgLksuZmF9Gf0+dySDHWDILwrlzGxOE6O43/l2uXz+10lniAWPMKEr/ENsTeXsz1igE gbbrYPB1GUHWkhZEeDU3mm0VeEoaaHwITOLJL1OSeOG0KQL7N3fjaCczae6l/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1760116578; 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=qEv9G34iWB192XAtALwkSRCiaSBMJzSaf/7oJgzv33Q=; b=ag7OS0GNjx9SD255E6DkHKrQJGkpffLdtqK8MLN9byEbLGFq3JxPb8O8nvMuqC+9sUSOcs B6Nu9wupZvwV1DQg41XXPsbzFxdXeaGhpEaae7ymTuUxE7XMCvQhhKNjMMqR9DbXkuiSuc wX+6yynUZaY2bzVxe86xb5kJMSAcS1VD4TmCnfI4QYtD2K15Gfj4CBN4ZvIppBJRLRY7g8 kypbeOiCrQnXX59Drj3S5lABzjFNW0reEZ7RV02lfXRorTNcKgZm1NerxCJ6EGtkOd1Phe vCVldCW9mO0YuK8G+zKAkl01fdw421Si7Issl3kOlHFOOIrXTBd2Kuuof9XDyA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1760116578; a=rsa-sha256; cv=none; b=XLxfwFvT5kKC6gW8Ii4EkfwT0HzNO+Bp8fPQfLjPHNOMLQaoBM0ziq0f1O1+Ym+Af79N09 N6K3aafCrzFhlIz3p2GK2vtu2jQxFok54ytLcNrLIeGiCJ1gVtjNoAZkQDqwls73CmyfPe glEW3/O6N1nvm9F4/YliZV2Gh3zaKI1ydxXjR91h9ziCqTQ1skmUS6mpEOL8Y+3QuWkBLL W3xGYrKPvPhXewoHjS7rB9f02QWmPmWOkBCD1IEVYznKnOLKE9bMSKsgVg9af1ANZfC+5c eVjbML1KS13jfuDXnsaZtjP25uWK93QcmfaguEDkHI07JF9JC6IrOYZt5hJekg== 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 4cjtgk1xKKz1Br3; Fri, 10 Oct 2025 17:16:18 +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 59AHGIgp009144; Fri, 10 Oct 2025 17:16:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 59AHGI0m009141; Fri, 10 Oct 2025 17:16:18 GMT (envelope-from git) Date: Fri, 10 Oct 2025 17:16:18 GMT Message-Id: <202510101716.59AHGI0m009141@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: 560c1bb21fe2 - stable/14 - cr_canseeothergids(): Make the logic easier to grasp 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: 560c1bb21fe2da4fe5c9a1186262c035b2ece9c5 Auto-Submitted: auto-generated The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=560c1bb21fe2da4fe5c9a1186262c035b2ece9c5 commit 560c1bb21fe2da4fe5c9a1186262c035b2ece9c5 Author: Olivier Certner AuthorDate: 2025-08-27 16:53:14 +0000 Commit: Olivier Certner CommitDate: 2025-10-10 17:15:56 +0000 cr_canseeothergids(): Make the logic easier to grasp Invert the initial test on whether the policy is in force so that, if there are no restrictions, the function bails out early, allowing to de-indent the rest of the code and have it finish with a non-zero (deny) 'return'. No functional change (intended). MFC after: 5 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D52272 (cherry picked from commit f75d0dc533923345c653dcdcd5ebd1e53377a7c5) --- sys/kern/kern_prot.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index d0f4c8cd6992..8ce75c6297e3 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -1843,19 +1843,22 @@ SYSCTL_INT(_security_bsd, OID_AUTO, see_other_gids, CTLFLAG_RW, static int cr_canseeothergids(struct ucred *u1, struct ucred *u2) { - if (!see_other_gids) { - if (realgroupmember(u1->cr_rgid, u2)) - return (0); + if (see_other_gids) + return (0); - for (int i = 1; i < u1->cr_ngroups; i++) - if (realgroupmember(u1->cr_groups[i], u2)) - return (0); + /* Restriction in force. */ - if (priv_check_cred(u1, PRIV_SEEOTHERGIDS) != 0) - return (ESRCH); - } + if (realgroupmember(u1->cr_rgid, u2)) + return (0); - return (0); + for (int i = 1; i < u1->cr_ngroups; i++) + if (realgroupmember(u1->cr_groups[i], u2)) + return (0); + + if (priv_check_cred(u1, PRIV_SEEOTHERGIDS) == 0) + return (0); + + return (ESRCH); } /*