mirror of
https://github.com/torvalds/linux.git
synced 2026-09-14 16:10:02 +02:00
Probes fixes for v7.2-rc7:
- selftests/ftrace: Convert ELF entry point to file offset in uprobe test Convert the ELF entry point address (e_entry) to a file offset using LOAD segment headers in add_remove_uprobe test. This fixes uprobe registration failures (-EINVAL) on non-PIE executables where vaddr exceeds file size. -----BEGIN PGP SIGNATURE----- iQFPBAABCgA5FiEEh7BulGwFlgAOi5DV2/sHvwUrPxsFAmp63LIbHG1hc2FtaS5o aXJhbWF0c3VAZ21haWwuY29tAAoJENv7B78FKz8bDDMIAKEY/q+W2mOy44zPVbVD Sbs9j4GvoprWTkJcAv2eXfA43264xoc9wn+49LzQLEaT8Jgw7gpWyIi3/2A4pPR9 aQjZGZmHwjeJ3ewq/2fEdNfA3VKJjMgg/6c5H7inVIc+YDF1m2eSI8svFDEn2qDR xJHqF6c350ZGFi04ejB2AefW8JX2KGbIdqiCNlvhJzjDgRLBNR5cfblUX/JST6QT H4ZddjX3YDcbcX50KR6Z7Y+Y+og1vwZ8XJ2N6gLCPI8owwm4NgJ5IdewLbpTI7wX Yon66cDtbKBJoT0SA1DFnho58iKLKZx1MCz09z9Gg2FBsRhg0hKHe5RhJq40VQYb 1+k= =4dpN -----END PGP SIGNATURE----- Merge tag 'probes-fixes-v7.2-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace Pull probes fix from Masami Hiramatsu: - Convert ELF entry point to file offset in uprobe test Convert the ELF entry point address (e_entry) to a file offset using LOAD segment headers in add_remove_uprobe test. This fixes uprobe registration failures (-EINVAL) on non-PIE executables where vaddr exceeds file size. * tag 'probes-fixes-v7.2-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: selftests/ftrace: Convert ELF entry point to file offset in uprobe test
This commit is contained in:
commit
f5bbbfec59
|
|
@ -12,9 +12,32 @@ echo 0 > events/enable
|
|||
echo > dynamic_events
|
||||
|
||||
REALBIN=`readlink -f /bin/sh`
|
||||
ENTRYPOINT=`readelf -h ${REALBIN} | grep Entry | sed -e 's/[^0]*//'`
|
||||
|
||||
echo "p:myevent ${REALBIN}:${ENTRYPOINT}" >> uprobe_events
|
||||
# Get the entry point virtual address from ELF header
|
||||
ENTRY=`readelf -hW ${REALBIN} | grep "Entry point" | awk '{print $NF}'`
|
||||
|
||||
# Convert virtual address to file offset: find the LOAD segment containing
|
||||
# the entry point, then compute file_offset = e_entry - p_vaddr + p_offset.
|
||||
# For PIE binaries this is a no-op (vaddr == file offset), but for non-PIE
|
||||
# executables the virtual address is much larger than the file size and
|
||||
# must be converted, otherwise uprobe_register() rejects it with -EINVAL.
|
||||
ENTRY_DEC=$(printf '%d' "$ENTRY")
|
||||
OFFSET=$ENTRY
|
||||
while IFS= read -r line; do
|
||||
set -- $line
|
||||
[ "$1" = "LOAD" ] || continue
|
||||
VA_DEC=$(printf '%d' "$3")
|
||||
OFF_DEC=$(printf '%d' "$2")
|
||||
FSZ_DEC=$(printf '%d' "$5")
|
||||
if [ "$ENTRY_DEC" -ge "$VA_DEC" ] && [ "$ENTRY_DEC" -lt "$((VA_DEC + FSZ_DEC))" ]; then
|
||||
OFFSET=$(printf '0x%x' "$((ENTRY_DEC - VA_DEC + OFF_DEC))")
|
||||
break
|
||||
fi
|
||||
done << EOF
|
||||
$(readelf -lW ${REALBIN} | grep LOAD)
|
||||
EOF
|
||||
|
||||
echo "p:myevent ${REALBIN}:${OFFSET}" >> uprobe_events
|
||||
|
||||
grep -q myevent uprobe_events
|
||||
test -d events/uprobes/myevent
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user