aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/dev/hwpmc/hwpmc_mod.c72
-rw-r--r--sys/kern/kern_exec.c2
2 files changed, 13 insertions, 61 deletions
diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c
index 70c974857f5c..98ef14885c10 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);
@@ -1026,60 +1025,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.
*/
static int
@@ -1442,10 +1387,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);
}
}
@@ -1458,10 +1412,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 5f7adae8df03..a109871d7673 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -1037,7 +1037,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;