From nobody Tue Aug 25 16:01:17 2026 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 4hTsvy29Lzz6pbyg for ; Tue, 25 Aug 2026 16:01: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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hTsvy0Pbgz4457 for ; Tue, 25 Aug 2026 16:01:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1787673678; 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=jUBdszKnys/csX4XFCByx67h1BDkCeTuOR3uqTKK2Dc=; b=JlwHxTSSjFLy7Fm+HY/YJ1oIZvF+Lnf7Exg/Of3U5nDEDDjQ/TeNVtffkQS9FPDsKq+tOw qXy9Vu9fS+96GGP58pA3xAVxAtAN/m87lfE1AWiwS7B6iUEmgG4DHikAiN99mKNlWBK54y IHO8/Ju7P/hQ9E63GjGgwPoWJ7cvbpc+mrmvMAUCm6fiqPxdDv9K/3s8dVVTwxRUAc/j/m YB6LpUii0GTUnr3eduyk1bCWqa8wSyLT7NJQvX5ET4wmxXUhKeUOth8hAkHzSTHA8UAhSS i088rjRhf3KnTpHy24hoVPU1CSBHiMmOliIsvrtnQ+vy0CkXjiHNhYtBRCpZHQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1787673678; a=rsa-sha256; cv=none; b=r8Y6tb7pHs3TIYQpXz1gV9S7GpBdyon5CgrWMztUKm68jjerjzIoq78dD/+98ObQ6BFNSb jvkNq/SHIFL7dj1H4ScJm/W1HMz5TwU4xf+bG3mrYdahHvgfAVrpo5X6ILm5ElfEfKDTaj fUrHoMZnZDoTwIHctYc00pxOT+PvID7cOkjEoWY13Nx6w5KL9kPr+0Z+jyumj0ucsFNs7M Nn/TCZugnMOAVJ94p05DAIe1aF7R4mdFBEeQlXmAMOA2omfosFgtgBYAw5Fhs8Xqg6N4T2 HkmLjzWmbh5WEq8G6QP3VGlba01RGNqfIJrHb/7XD5mKTkt9bhHUR8rbZKyPlA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1787673678; 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=jUBdszKnys/csX4XFCByx67h1BDkCeTuOR3uqTKK2Dc=; b=VaHd1Zfb1Le3TFlrtd2hjlLPa70Ko2f5IxADsjGOwNiY7BDWxkGDPknoJuP1R3oAU52E9/ rs2g1WdKYTGyIbkG2pTbq42b2sbVuHs48kKptFkPKjMWRuqjjHYXVsjCXceW5S9wnNfqqb helnpS/ZTrNqifjEVIEaMGdNzPnnyv/5TkV3XXme3rIVea9+5zo0NAsoHtzRc/2CLI8hf8 yaxWjRTwKN9F2lcm1Xxio0jNOekfJhDJ6liM78jCm22Ynz1L9IRYKyuGXiSdftjZempEFK X+GLu7eaqHhf35UVdSyoxZU2p5z1GI/bfrAe3ZoveCxJPrduFRFan4xoCLDLqA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hTsvx6CKRzy9y for ; Tue, 25 Aug 2026 16:01:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 33a11 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 25 Aug 2026 16:01:17 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: e034ae898328 - releng/15.1 - hwpmc: Fix the execve handler 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 List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/releng/15.1 X-Git-Reftype: branch X-Git-Commit: e034ae898328ad30bdbc0abb75d5f6d661e74e8b Auto-Submitted: auto-generated Date: Tue, 25 Aug 2026 16:01:17 +0000 Message-Id: <6a8dbc4d.33a11.6d923ac9@gitrepo.freebsd.org> The branch releng/15.1 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=e034ae898328ad30bdbc0abb75d5f6d661e74e8b commit e034ae898328ad30bdbc0abb75d5f6d661e74e8b Author: Mark Johnston AuthorDate: 2026-08-24 14:57:16 +0000 Commit: Mark Johnston CommitDate: 2026-08-24 19:33:12 +0000 hwpmc: Fix the execve handler When a process execve()s, pmc_process_exec() is supposed to evaluate whether the new image is setuid/setgid and if so, whether to detach PMCs. This was handled by pmc_can_attach(), which is effectively an open-coded copy of cr_xids_subset(). Unfortunately, the test of the result of this function was inverted, with the result that we'd detach PMCs only if the predicate said it was okay to do so. It appears the bug has always been there; it seems the intent was to return 0 on "success", i.e., it is okay to attach the PMCs, much like p_candebug(). Commits 1c3c698ba4c4 and 1c40b15971f0 obscured this a bit. I think this check is trying to be too clever. Let's make it simpler: simply do not attach PMCs unless the owner is privileged. This is how, e.g., ktrace works. I do not think it's worth trying to be more sophisticated than this unless we can generalize the policy in a way that's applicable to other subsystems. Also fix a bug at the end of pmc_process_exec(): pmc_detach_one_process() will call pmc_remove_process_descriptor() for us. Approved by: so Security: FreeBSD-SA-26:56.hwpmc Security: CVE-2026-58089 Reported by: netchild Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D59102 --- sys/dev/hwpmc/hwpmc_mod.c | 72 ++++++++--------------------------------------- sys/kern/kern_exec.c | 2 +- 2 files changed, 13 insertions(+), 61 deletions(-) diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c index 04e23ae24c31..5b70252fc7e7 100644 --- a/sys/dev/hwpmc/hwpmc_mod.c +++ b/sys/dev/hwpmc/hwpmc_mod.c @@ -210,7 +210,6 @@ 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 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); @@ -1023,60 +1022,6 @@ pmc_unlink_target_process(struct pmc *pm, struct pmc_process *pp) } } -/* - * Check if PMC 'pm' may be attached to target process 't'. - */ - -static bool -pmc_can_attach(struct pmc *pm, struct proc *t) -{ - struct proc *o; /* pmc owner */ - struct ucred *oc, *tc; /* owner, target credentials */ - bool decline_attach; - - /* - * A PMC's owner can always attach that PMC to itself. - */ - - if ((o = pm->pm_owner->po_owner) == t) - return (true); - - PROC_LOCK(o); - oc = o->p_ucred; - crhold(oc); - PROC_UNLOCK(o); - - PROC_LOCK(t); - tc = t->p_ucred; - crhold(tc); - PROC_UNLOCK(t); - - /* - * The effective uid of the PMC owner should match at least one - * of the {effective,real,saved} uids of the target process. - */ - - decline_attach = oc->cr_uid != tc->cr_uid && - oc->cr_uid != tc->cr_svuid && - oc->cr_uid != tc->cr_ruid; - - /* - * Every one of the target's group ids, must be in the owner's - * group list. - */ - for (int i = 0; !decline_attach && i < tc->cr_ngroups; i++) - decline_attach = !groupmember(tc->cr_groups[i], 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); -} - /* * Attach a process to a PMC. */ @@ -1409,10 +1354,19 @@ 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)) { + struct proc *owner; + struct ucred *cred; + + owner = pm->pm_owner->po_owner; + PROC_LOCK(owner); + cred = crhold(owner->p_ucred); + PROC_UNLOCK(owner); + + if (priv_check_cred(cred, PRIV_DEBUG_DIFFCRED) != 0) pmc_detach_one_process(td->td_proc, pm, PMC_FLAG_NONE); - } + + crfree(cred); } } @@ -1425,10 +1379,8 @@ pmc_process_exec(struct thread *td, struct pmckern_procexec *pk) * PMCs, we can remove the process entry and free * up space. */ - if (pp->pp_refcnt == 0) { - pmc_remove_process_descriptor(pp); + if (pp->pp_refcnt == 0) pmc_destroy_process_descriptor(pp); - } } /* diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index c75354a4ffa6..b5af417708d1 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1008,7 +1008,7 @@ interpret: */ if (PMC_SYSTEM_SAMPLING_ACTIVE() || PMC_PROC_IS_USING_PMCS(p)) { VOP_UNLOCK(imgp->vp); - pe.pm_credentialschanged = credential_changing; + pe.pm_credentialschanged = imgp->credential_setid; pe.pm_baseaddr = imgp->reloc_base; pe.pm_dynaddr = imgp->et_dyn_addr;