]> git.ipfire.org Git - thirdparty/linux.git/commit
selftests/ftrace: Convert ELF entry point to file offset in uprobe test
authorRui Qi <qirui.001@bytedance.com>
Fri, 7 Aug 2026 08:15:12 +0000 (16:15 +0800)
committerMasami Hiramatsu (Google) <mhiramat@kernel.org>
Fri, 7 Aug 2026 16:02:21 +0000 (01:02 +0900)
commit24aa630f6259e6a2107936c06fed72063f712b64
tree6689fd627905df46b23d97a08a94f2c0b49476e9
parentf9a2394a23482bfd330911e9c8295b71724feacd
selftests/ftrace: Convert ELF entry point to file offset in uprobe test

The add_remove_uprobe test uses readelf -h to obtain the ELF entry
point (e_entry) and passes it directly as the offset to uprobe_events.
However, uprobe_events expects a file offset, not a virtual address.

For PIE binaries, the virtual address happens to equal the file offset
because the first LOAD segment has p_vaddr == p_offset, so the test
works by coincidence. But for non-PIE executables, e_entry is an
absolute virtual address that can far exceed the file size. When the
probe is enabled, uprobe_register() checks offset > i_size_read(inode)
and rejects it with -EINVAL.

Fix this by converting the virtual address to a file offset using the
ELF program headers: scan readelf -lW output for the LOAD segment
containing the entry point, then compute file_offset = e_entry -
p_vaddr + p_offset. For PIE binaries the result is unchanged; for
non-PIE binaries the offset is correctly translated.

The conversion uses only POSIX shell primitives, with no dependency on
gawk or perl.

Link: https://lore.kernel.org/all/20260807081512.2974757-3-qirui.001@bytedance.com/
Fixes: dc4b165855f2 ("selftests/ftrace: Use readelf to find entry point in uprobe test")
Cc: stable@vger.kernel.org
Signed-off-by: Rui Qi <qirui.001@bytedance.com>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
tools/testing/selftests/ftrace/test.d/dynevent/add_remove_uprobe.tc