aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/kern_exec.c
diff options
context:
space:
mode:
authorJessica Clarke <jrtc27@FreeBSD.org>2023-05-30 23:20:36 +0000
committerJessica Clarke <jrtc27@FreeBSD.org>2023-05-30 23:20:36 +0000
commit94426d21bf62f2b36dc9b556ab27c401a412a026 (patch)
tree4e572e20812111ab119660330516c89115b35b07 /sys/kern/kern_exec.c
parent659a0041dd06355704f1bce0c5d7cbcb0b32c0a4 (diff)
downloadsrc-94426d21bf62f2b36dc9b556ab27c401a412a026.tar.gz
src-94426d21bf62f2b36dc9b556ab27c401a412a026.zip
pmc: Rework PROCEXEC event to support PIEs
Currently the PROCEXEC event only reports a single address, entryaddr, which is the entry point of the interpreter in the typical dynamic case, and used solely to calculate the base address of the interpreter. For PDEs this is fine, since the base address is known from the program headers, but for PIEs the base address varies at run time based on where the kernel chooses to load it, and so pmcstat has no way of knowing the real address ranges for the executable. This was less of an issue in the past since PIEs were rare, but now they're on by default on 64-bit architectures it's more of a problem. To solve this, pass through what was picked for et_dyn_addr by the kernel, and use that as the offset for the executable's start address just as is done for everything in the kernel. Since we're changing this interface, sanitise the way we determine the interpreter's base address by passing it through directly rather than indirectly via the entry point and having to subtract off whatever the ELF header's e_entry is (and anything that wants the entry point in future can still add that back on as needed; this merely changes the interface to directly provide the underlying variables involved). This will be followed up by a bump to the pmc major version. Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D39595
Diffstat (limited to 'sys/kern/kern_exec.c')
-rw-r--r--sys/kern/kern_exec.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index 14aac3f374d2..a779aa11b4c3 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -919,7 +919,8 @@ interpret:
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;
+ pe.pm_baseaddr = imgp->reloc_base;
+ pe.pm_dynaddr = imgp->et_dyn_addr;
PMC_CALL_HOOK_X(td, PMC_FN_PROCESS_EXEC, (void *) &pe);
vn_lock(imgp->vp, LK_SHARED | LK_RETRY);