Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F108594651
D40290.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D40290.diff
View Options
diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c
--- a/sys/dev/hwpmc/hwpmc_mod.c
+++ b/sys/dev/hwpmc/hwpmc_mod.c
@@ -212,7 +212,6 @@
static int pmc_attach_one_process(struct proc *p, struct pmc *pm);
static int pmc_can_allocate_rowindex(struct proc *p, unsigned int ri,
int cpu);
-static int 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);
@@ -1029,61 +1028,6 @@
}
}
-/*
- * Check if PMC 'pm' may be attached to target process 't'.
- */
-
-static int
-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;
-
- /*
- * A PMC's owner can always attach that PMC to itself.
- */
-
- if ((o = pm->pm_owner->po_owner) == t)
- return 0;
-
- 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 (i = 0; !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) ||
- !groupmember(tc->cr_svgid, oc);
-
- crfree(tc);
- crfree(oc);
-
- return !decline_attach;
-}
-
/*
* Attach a process to a PMC.
*/
@@ -1401,38 +1345,26 @@
if (freepath != NULL)
free(freepath, M_TEMP);
- PMCDBG4(PRC,EXC,1, "exec proc=%p (%d, %s) cred-changed=%d",
- p, p->p_pid, p->p_comm, pk->pm_credentialschanged);
-
- if (pk->pm_credentialschanged == 0) /* no change */
- return;
+ PMCDBG3(PRC,EXC,1, "exec proc=%p (%d, %s)", p, p->p_pid, p->p_comm);
/*
- * If the newly exec()'ed process has a different credential
- * than before, allow it to be the target of a PMC only if
- * the PMC's owner has sufficient privilege.
+ * For each PMC attached to the newly exec()'ed target process, the
+ * owning process must have sufficient privilege to re-attach. If the
+ * target process has different credentials than before the exec, or is
+ * otherwise not considered 'debuggable' by the owner in question (e.g.
+ * P2_NOTRACE is set for the process), then we may be forced to detach
+ * one or more PMCs.
+ *
+ * This is analogous to the call to p_candebug() in the
+ * PMC_OP_PMCATTACH path.
*/
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) {
- pmc_detach_one_process(td->td_proc, pm,
- PMC_FLAG_NONE);
- }
- }
- }
-
- KASSERT(pp->pp_refcnt >= 0 && pp->pp_refcnt <= md->pmd_npmc,
- ("[pmc,%d] Illegal ref count %u on pp %p", __LINE__,
- pp->pp_refcnt, pp));
+ if ((pm = pp->pp_pmcs[ri].pp_pmc) == NULL)
+ continue;
- /*
- * If this process is no longer the target of any
- * PMCs, we can remove the process entry and free
- * up space.
- */
- if (pp->pp_refcnt == 0) {
- pmc_remove_process_descriptor(pp);
- pmc_destroy_process_descriptor(pp);
+ po = pm->pm_owner;
+ if (p_candebug(FIRST_THREAD_IN_PROC(po->po_owner), p) != 0)
+ pmc_detach_one_process(p, pm, PMC_FLAG_REMOVE);
}
}
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -918,7 +918,6 @@
*/
if (PMC_SYSTEM_SAMPLING_ACTIVE() || PMC_PROC_IS_USING_PMCS(p)) {
VOP_UNLOCK(imgp->vp);
- pe.pm_credentialschanged = credential_changing;
pe.pm_entryaddr = imgp->entry_addr;
PMC_CALL_HOOK_X(td, PMC_FN_PROCESS_EXEC, (void *) &pe);
diff --git a/sys/sys/pmckern.h b/sys/sys/pmckern.h
--- a/sys/sys/pmckern.h
+++ b/sys/sys/pmckern.h
@@ -75,7 +75,6 @@
} ring_type_t;
struct pmckern_procexec {
- int pm_credentialschanged;
uintfptr_t pm_entryaddr;
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jan 27, 6:20 PM (7 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16203885
Default Alt Text
D40290.diff (4 KB)
Attached To
Mode
D40290: hwpmc: Improve re-attachment logic in pmc_process_exec()
Attached
Detach File
Event Timeline
Log In to Comment