Skip to contentSkip to conversation

selftests/ftrace: Use readelf to find entry point in uprobe test

PATCH In review Heiko Carstens 3 participants 3 messages Feb 20, 2025 – Feb 26, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/ftrace: Use readelf to find entry point in uprobe test

The uprobe events test fails on s390, but also on x86 (Fedora 41). The problem appears to be that there is an assumption that adding a uprobe to the beginning of the executable mapping of /bin/sh is sufficient to trigger a uprobe event when /bin/sh is executed.

This assumption is not necessarily true. Therefore use "readelf -h" to find the entry point address of /bin/sh and use this address when adding the uprobe event.

This adds a dependency to readelf which is not always installed. Therefore add a check and exit with exit_unresolved if it is not installed.

---
 .../ftrace/test.d/dynevent/add_remove_uprobe.tc        | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
tools/testing/selftests/ftrace/test.d/dynevent/add_remove_uprobe.tc +7 -3
index 86c76679c56e..f2048c244526 100644
@@ -3,14 +3,18 @@
 # description: Generic dynamic event - add/remove/test uprobe events
 # requires: uprobe_events
 
+if ! which readelf > /dev/null 2>&1 ; then
+  echo "No readelf found. skipped."
+  exit_unresolved
+fi
+
 echo 0 > events/enable
 echo > dynamic_events
 
 REALBIN=`readlink -f /bin/sh`
+ENTRYPOINT=`readelf -h ${REALBIN} | grep Entry | sed -e 's/[^0]*//'`
 
-echo 'cat /proc/$$/maps' | /bin/sh | \
-	grep "r-xp .*${REALBIN}$" | \
-	awk '{printf "p:myevent %s:0x%s\n", $6,$3 }' >> uprobe_events
+echo "p:myevent ${REALBIN}:${ENTRYPOINT}" >> uprobe_events
 
 grep -q myevent uprobe_events
 test -d events/uprobes/myevent
Signature · 1 line
2.45.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · On Thu, 20 Feb 2025 14:01:02 +0100 Heiko Carstens <[email protected]> wrote:

The uprobe events test fails on s390, but also on x86 (Fedora 41). The problem appears to be that there is an assumption that adding a uprobe to the beginning of the executable mapping of /bin/sh is sufficient to trigger a uprobe event when /bin/sh is executed.

Quoted 8 lines

This assumption is not necessarily true. Therefore use "readelf -h" to find the entry point address of /bin/sh and use this address when adding the uprobe event.

This adds a dependency to readelf which is not always installed. Therefore add a check and exit with exit_unresolved if it is not installed.

Shuah,

Can you take this in your tree?

-- Steve

Quoted 30 lines
---
 .../ftrace/test.d/dynevent/add_remove_uprobe.tc        | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
tools/testing/selftests/ftrace/test.d/dynevent/add_remove_uprobe.tc +7 -3
index 86c76679c56e..f2048c244526 100644
@@ -3,14 +3,18 @@
 # description: Generic dynamic event - add/remove/test uprobe events
 # requires: uprobe_events
 
+if ! which readelf > /dev/null 2>&1 ; then
+  echo "No readelf found. skipped."
+  exit_unresolved
+fi
+
 echo 0 > events/enable
 echo > dynamic_events
 
 REALBIN=`readlink -f /bin/sh`
+ENTRYPOINT=`readelf -h ${REALBIN} | grep Entry | sed -e 's/[^0]*//'`
 
-echo 'cat /proc/$$/maps' | /bin/sh | \
-	grep "r-xp .*${REALBIN}$" | \
-	awk '{printf "p:myevent %s:0x%s\n", $6,$3 }' >> uprobe_events
+echo "p:myevent ${REALBIN}:${ENTRYPOINT}" >> uprobe_events
 
 grep -q myevent uprobe_events
 test -d events/uprobes/myevent
maintainer
#2 lore raw
Quoted 17 lines · Steven Rostedt
Quoted 5 lines · On Thu, 20 Feb 2025 14:01:02 +0100 Heiko Carstens <[email protected]> wrote:

The uprobe events test fails on s390, but also on x86 (Fedora 41). The problem appears to be that there is an assumption that adding a uprobe to the beginning of the executable mapping of /bin/sh is sufficient to trigger a uprobe event when /bin/sh is executed.

Quoted 8 lines

This assumption is not necessarily true. Therefore use "readelf -h" to find the entry point address of /bin/sh and use this address when adding the uprobe event.

This adds a dependency to readelf which is not always installed. Therefore add a check and exit with exit_unresolved if it is not installed.

Quoted 7 lines

Shuah,

Can you take this in your tree?

-- Steve

Applied to linux_kselftest next for Linux 6.15-rc1.

thanks,
-- Shuah