From nobody Thu Sep 18 10:13:41 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 4cSBLF4Jn6z687st; Thu, 18 Sep 2025 10:13:41 +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 4cSBLF3Zl0z46tQ; Thu, 18 Sep 2025 10:13:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758190421; 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=IgqlMVbFmcO3e8sITmkdNzmP05VZSQ79rTwPE8fFfhk=; b=Za/POngC1cyo2gj3fHjjGh4YSGG2z1KDP+qx1KHz5dOH846qedL9FEnQqfhPsyxG6cAt2O Z/1wy99brJrb7AEVgKLdcphQ81st4GX3ALunpTR82Z6Qo+jAFMQP9Gixb+LuBDDciHAfdy Y7OLxHZS3ku3WFSuDEPXIvz9LtGtdeWZBhHMJGA5KxvAW19r5VwVgIx7lXVtTgRGxNO5cP ghSJezbhUUVwuIboc+aInw4KzpTmarUWiwbDVaNb+XVHl4YlVCGJTiz/AuTSiHIyv4Uzmr YnPRVBuzBw1WKZthbqWxpidDNVxYwFiXloJbWtcdFPAiQPHjZgxON9YOqHUiSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758190421; 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=IgqlMVbFmcO3e8sITmkdNzmP05VZSQ79rTwPE8fFfhk=; b=Y2mWi6n/eXJ3Qr4drWU4QWiNSLL9lbWPjNeBAN+G9Apa96nNuDQx/YFFP3LBMAc9QdYOKq w7fIvcpaWPzxSdVUg+i1kjn6lCAlAXPsKqnPUUN166te3n7D3XtYzwC5ionSy6EHIHumuE EejYN4pCuW+clJCceFkmfuIpTgJTarZWwd3OZ5+KMJ6pcO7CMyCRKobRfAUfa7tOqh/uND xnKBxs8WT04EeByGrIO0DF/pY4fka4pvGEm5tzbujp4rFcfJU8BD/v6RwPG4w23zbpBGs7 Q21R5GTK2VeJBH4MDJ/NUZrjvu/fB9ldZDM1RotPxEqPNZjvxkyBrsQW60Obwg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1758190421; a=rsa-sha256; cv=none; b=wPLc/GTmnMA8WG0832BmNo0kh2NcEHMAn1anUQuzJiH8TEptDxDOeoK8/b8T/zW82TQ4UH aZftXL2VFtz6V8rNW0EWix8/KNebfxQwrjZKA873Aro/idyejFELMeT1myh0N5m8I/GiZX sj03Zu4jfiYJ9hkI8mQmB7YTJ7fySrc1DhaFUkLp8LYul+DSolW7Gkl+8CL6UzvyhY17iu B/LBBN/+PaCXKY/EBB29156As2yEqCtymtv9VoUAdizzBZZtfBNcaBMNhO6b5/bkW2qWjX h521fG90FvIxgdrPPnliS9jre+tHEAr8rEjA5yd+zqFys8MsZTKLrj6+1wi+1g== 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 4cSBLF37tSz16R8; Thu, 18 Sep 2025 10:13:41 +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 58IADfhM072638; Thu, 18 Sep 2025 10:13:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58IADfsj072635; Thu, 18 Sep 2025 10:13:41 GMT (envelope-from git) Date: Thu, 18 Sep 2025 10:13:41 GMT Message-Id: <202509181013.58IADfsj072635@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: 59a73e9a1fe3 - stable/14 - hwpmc: On attach, ensure owner is a target effective GID's member 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: 59a73e9a1fe33517393a18ff958ef8d05f550a56 Auto-Submitted: auto-generated The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=59a73e9a1fe33517393a18ff958ef8d05f550a56 commit 59a73e9a1fe33517393a18ff958ef8d05f550a56 Author: Olivier Certner AuthorDate: 2025-08-26 09:43:38 +0000 Commit: Olivier Certner CommitDate: 2025-09-18 10:13:05 +0000 hwpmc: On attach, ensure owner is a target effective GID's member This restores a check that existed prior to commit be1f7435ef218b1d ("kern: start tracking cr_gid outside of cr_groups[]"). While here, improve pmc_can_attach()'s style by changing the type of 'decline_attach' to 'bool', fixing tests on it, adding missing parentheses to 'return' statements, and by changing its return value type to 'bool'. Fixes: be1f7435ef218b1d ("kern: start tracking cr_gid outside of cr_groups[]") MFC after: 9 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D52252 (cherry picked from commit 1c3c698ba4c40485ebbbd157cb49172cfa7de9b2) MFC to 14 does not fix any bug, but just applies some style changes needed by next MFC. In pmc_can_attach(): Start index of the loop on groups was changed to 1 in order to avoid a (harmless) duplicated groupmember() call with 'tc->cr_gid', which in 14 is still an alias of 'tc->cr_groups[0]'. We chose to MFC the addition of that latter call to minimize differences with what is in -CURRENT and 15. --- sys/dev/hwpmc/hwpmc_mod.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c index 5dd8bc67d60a..21f416510d5e 100644 --- a/sys/dev/hwpmc/hwpmc_mod.c +++ b/sys/dev/hwpmc/hwpmc_mod.c @@ -211,7 +211,7 @@ static int pmc_attach_one_process(struct proc *p, struct pmc *pm); static bool pmc_can_allocate_row(int ri, enum pmc_mode mode); static bool pmc_can_allocate_rowindex(struct proc *p, unsigned int ri, int cpu); -static int pmc_can_attach(struct pmc *pm, struct proc *p); +static bool pmc_can_attach(struct pmc *pm, struct proc *p); static void pmc_capture_user_callchain(int cpu, int soft, struct trapframe *tf); static void pmc_cleanup(void); @@ -1030,19 +1030,19 @@ pmc_unlink_target_process(struct pmc *pm, struct pmc_process *pp) * Check if PMC 'pm' may be attached to target process 't'. */ -static int +static bool pmc_can_attach(struct pmc *pm, struct proc *t) { struct proc *o; /* pmc owner */ struct ucred *oc, *tc; /* owner, target credentials */ - int decline_attach, i; + bool decline_attach; /* * A PMC's owner can always attach that PMC to itself. */ if ((o = pm->pm_owner->po_owner) == t) - return 0; + return (false); PROC_LOCK(o); oc = o->p_ucred; @@ -1067,18 +1067,17 @@ pmc_can_attach(struct pmc *pm, struct proc *t) * Every one of the target's group ids, must be in the owner's * group list. */ - for (i = 0; !decline_attach && i < tc->cr_ngroups; i++) + for (int i = 1; !decline_attach && i < tc->cr_ngroups; i++) decline_attach = !groupmember(tc->cr_groups[i], oc); - - /* check the read and saved gids too */ - if (decline_attach == 0) - decline_attach = !groupmember(tc->cr_rgid, oc) || + if (!decline_attach) + decline_attach = !groupmember(tc->cr_gid, oc) || + !groupmember(tc->cr_rgid, oc) || !groupmember(tc->cr_svgid, oc); crfree(tc); crfree(oc); - return !decline_attach; + return (!decline_attach); } /* @@ -1413,7 +1412,7 @@ pmc_process_exec(struct thread *td, struct pmckern_procexec *pk) */ for (ri = 0; ri < md->pmd_npmc; ri++) { if ((pm = pp->pp_pmcs[ri].pp_pmc) != NULL) { - if (pmc_can_attach(pm, td->td_proc) != 0) { + if (pmc_can_attach(pm, td->td_proc)) { pmc_detach_one_process(td->td_proc, pm, PMC_FLAG_NONE); }