When a process transforms after an execve() call, we call into a hwpmc
hook to handle a few things. In particular, if the process had PMCs
attached to it, we need to evaluate whether the owning process has
sufficient privilege to re-attach its PMCs to the (new) target process.
In particular, we handle the case where the process credentials have
changed due to setuid on the exec'ed program.
Previously, we were evaluating this using a set of hand-rolled
credential checks, that partially duplicate the logic found in
p_candebug(). In the initial PMC attachment path (PMC_OP_PMCATTACH via
syscall), we call p_candebug() to determine if the thread owning the PMC
has sufficient privileges to attach it to the target process. So, change
pmc_process_exec() to use p_candebug() for the re-attachment checks as
well.
As a result, pmc_can_attach() is removed completely, and so is the
pm_credentialschanged member of struct pmckern_procexec.
This change ends up handling an additional case where the exec'ed
process now has the 'P2_NOTRACE' flag set, and re-attachment will not
proceed. This is a niche edge-case, but demonstrates why it is more
appropriate to use the core p_candebug() routine.
Some additional cleanup: specify PMC_FLAG_REMOVE for the call to the
detach routine; this will handle ref counting and process descriptor
cleanup for us. It will also clear the P_HWPMC flag when appropriate,
where before seem to have been leaking this.