Skip to contentSkip to conversation

perf test: probe_vfs_getname add do_getname() probing fallback

PATCH New Thomas Richter 2 participants 3 messages Apr 16 – Apr 25

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

PATCH 1/1 perf test: probe_vfs_getname add do_getname() probing fallback

The following tests are skipped for some time now on platforms s390 and x86_64:

 # perf test vfs_getname
 138: Add vfs_getname probe to get syscall args filenames    : Skip
 140: Use vfs_getname probe to get syscall args filenames    : Skip
 154: Check open filename arg using perf trace + vfs_getname : Skip
 #

This is caused by a change in kernel code of function getname_flags(), see
commit 9fa3ec84587c ("allow incomplete imports of filenames")
This commit changed the function getname_flags() implementation.

Now the perf probe 'vfs_getname parameter=xxx' does not match any more. Extend the test logic to fall back to probing do_getname(). This reflects the updated kernel code.

Output after:

 # perf test vfs_getname
 138: Add vfs_getname probe to get syscall args filenames    : Ok
 140: Use vfs_getname probe to get syscall args filenames    : Ok
 154: Check open filename arg using perf trace + vfs_getname : Ok
 #
---
 tools/perf/tests/shell/lib/probe_vfs_getname.sh | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
tools/perf/tests/shell/lib/probe_vfs_getname.sh +15 -1
index 88cd0e26d5f6..9156a79212b9 100644
@@ -12,6 +12,8 @@ cleanup_probe_vfs_getname() {
 
 add_probe_vfs_getname() {
 	add_probe_verbose=$1
+	do_getname=0
+
 	if [ $had_vfs_getname -eq 1 ] ; then
 		result_initname_re="[[:space:]]+([[:digit:]]+)[[:space:]]+initname.*"
 		line=$(perf probe -L getname_flags 2>&1 | grep -E "$result_initname_re" | sed -r "s/$result_initname_re/\1/")
@@ -28,12 +30,24 @@ add_probe_vfs_getname() {
 			line=$(perf probe -L getname_flags 2>&1 | grep -E "$result_aname_re" | sed -r "s/$result_aname_re/\1/")
 		fi
 
+		if [ -z "$line" ] ; then
+			do_getname=1
+			result_iname_re="[[:space:]]+([[:digit:]]+)[[:space:]]+initname\(result\);"
+			line=$(perf probe -L do_getname 2>&1 | grep -E "$result_iname_re" | sed -r "s/$result_iname_re/\1/")
+		fi
+
 		if [ -z "$line" ] ; then
 			echo "Could not find probeable line"
 			return 2
 		fi
 
-		perf probe -q       "vfs_getname=getname_flags:${line} pathname=result->name:string" || \
+		if [ "$do_getname" -eq 1 ]
+		then
+			param="vfs_getname=do_getname:${line} pathname=result->iname:string"
+			perf probe -q "$param" || perf probe $add_probe_verbose "$param" || return 1
+			return 0
+		fi
+		perf probe -q "vfs_getname=getname_flags:${line} pathname=result->name:string" || \
 		perf probe $add_probe_verbose "vfs_getname=getname_flags:${line} pathname=filename:ustring" || return 1
 	fi
 }
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/1 perf test: probe_vfs_getname add do_getname() probing fallback

Friendly ping...

Quoted 70 lines · Thomas Richter

The following tests are skipped for some time now on platforms s390 and x86_64:

 # perf test vfs_getname
 138: Add vfs_getname probe to get syscall args filenames    : Skip
 140: Use vfs_getname probe to get syscall args filenames    : Skip
 154: Check open filename arg using perf trace + vfs_getname : Skip
 #

This is caused by a change in kernel code of function getname_flags(), see
commit 9fa3ec84587c ("allow incomplete imports of filenames")
This commit changed the function getname_flags() implementation.

Now the perf probe 'vfs_getname parameter=xxx' does not match any more. Extend the test logic to fall back to probing do_getname(). This reflects the updated kernel code.

Output after:

 # perf test vfs_getname
 138: Add vfs_getname probe to get syscall args filenames    : Ok
 140: Use vfs_getname probe to get syscall args filenames    : Ok
 154: Check open filename arg using perf trace + vfs_getname : Ok
 #
---
 tools/perf/tests/shell/lib/probe_vfs_getname.sh | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
tools/perf/tests/shell/lib/probe_vfs_getname.sh +15 -1
index 88cd0e26d5f6..9156a79212b9 100644
@@ -12,6 +12,8 @@ cleanup_probe_vfs_getname() {
 
 add_probe_vfs_getname() {
 	add_probe_verbose=$1
+	do_getname=0
+
 	if [ $had_vfs_getname -eq 1 ] ; then
 		result_initname_re="[[:space:]]+([[:digit:]]+)[[:space:]]+initname.*"
 		line=$(perf probe -L getname_flags 2>&1 | grep -E "$result_initname_re" | sed -r "s/$result_initname_re/\1/")
@@ -28,12 +30,24 @@ add_probe_vfs_getname() {
 			line=$(perf probe -L getname_flags 2>&1 | grep -E "$result_aname_re" | sed -r "s/$result_aname_re/\1/")
 		fi
 
+		if [ -z "$line" ] ; then
+			do_getname=1
+			result_iname_re="[[:space:]]+([[:digit:]]+)[[:space:]]+initname\(result\);"
+			line=$(perf probe -L do_getname 2>&1 | grep -E "$result_iname_re" | sed -r "s/$result_iname_re/\1/")
+		fi
+
 		if [ -z "$line" ] ; then
 			echo "Could not find probeable line"
 			return 2
 		fi
 
-		perf probe -q       "vfs_getname=getname_flags:${line} pathname=result->name:string" || \
+		if [ "$do_getname" -eq 1 ]
+		then
+			param="vfs_getname=do_getname:${line} pathname=result->iname:string"
+			perf probe -q "$param" || perf probe $add_probe_verbose "$param" || return 1
+			return 0
+		fi
+		perf probe -q "vfs_getname=getname_flags:${line} pathname=result->name:string" || \
 		perf probe $add_probe_verbose "vfs_getname=getname_flags:${line} pathname=filename:ustring" || return 1
 	fi
 }
Signature · 9 lines
Thomas Richter, Dept 3303, IBM s390 Linux Development, Boeblingen, Germany
--
IBM Deutschland Research & Development GmbH

Vorsitzender des Aufsichtsrats: Wolfgang Wendt

Geschäftsführung: David Faller

Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294
#2 lore raw
In reply to Thomas Richter
Sashiko AI review found 2 potential issue(s): - [Medium] Out-of-bounds kernel memory read in `do_getname` perf probe due to unterminated string. - [Medium] Missing user-space pointer fallback logic…

Sashiko AI review found 2 potential issue(s):
- [Medium] Out-of-bounds kernel memory read in do_getname perf probe due to unterminated string.
- [Medium] Missing user-space pointer fallback logic reduces test robustness.
--

commit 44caa018a80d8e3283b4eda7b6e0f0690afbe123
Author: Thomas Richter <[email protected]>

perf test: probe_vfs_getname add do_getname() probing fallback

This commit extends the vfs_getname perf test logic to fall back to probing do_getname() if getname_flags() does not match. This reflects updated kernel code where the getname_flags() implementation was changed.

Quoted 3 lines
tools/perf/tests/shell/lib/probe_vfs_getname.sh +0 -0

[ ... ]

Quoted 9 lines
tools/perf/tests/shell/lib/probe_vfs_getname.sh +5 -0
@@ -28,12 +30,24 @@ add_probe_vfs_getname() {
 			line=$(perf probe -L getname_flags 2>&1 | grep -E "$result_aname_re" | sed -r "s/$result_aname_re/\1/")
 		fi
 
+		if [ -z "$line" ] ; then
+			do_getname=1
+			result_iname_re="[[:space:]]+([[:digit:]]+)[[:space:]]+initname\(result\);"
+			line=$(perf probe -L do_getname 2>&1 | grep -E "$result_iname_re" | sed -r "s/$result_iname_re/\1/")
+		fi

tools/perf/tests/shell/lib/probe_vfs_getname.sh add_probe_vfs_getname() { · line 46

Quoted 10 lines
tools/perf/tests/shell/lib/probe_vfs_getname.sh +4 -1
+
 		if [ -z "$line" ] ; then
 			echo "Could not find probeable line"
 			return 2
 		fi
 
-		perf probe -q       "vfs_getname=getname_flags:${line} pathname=result->name:string" || \
+		if [ "$do_getname" -eq 1 ]
+		then
+			param="vfs_getname=do_getname:${line} pathname=result->iname:string"

Does this probe cause an out-of-bounds kernel memory read when the path exceeds EMBEDDED_NAME_MAX?

If a user provides a long file path, strncpy_from_user() completely fills the fixed-size result->iname array without appending a NUL terminator, while the actual NUL-terminated path is dynamically allocated and pointed to by result->name.

Because the probe explicitly instructs the kernel to read result->iname as a NUL-terminated string, could the kprobe fetcher read past the end of the iname array into adjacent slab memory? Should this use result->name:string instead?

tools/perf/tests/shell/lib/probe_vfs_getname.sh add_probe_vfs_getname() { · line 47

Quoted 1 line
tools/perf/tests/shell/lib/probe_vfs_getname.sh +1 -0
+			perf probe -q "$param" || perf probe $add_probe_verbose "$param" || return 1

Is the user-space pointer fallback missing here?

The original probe logic for getname_flags robustly handles compiler optimizations by falling back to probing the user-space function argument directly (pathname=filename:ustring) if reading the kernel result struct fails.

This new block for do_getname instead retries the exact same probe string, just adding a verbose flag. Since filename remains the first argument to do_getname(), would it be safer to include the filename:ustring fallback to prevent the test from failing on certain toolchains?

Quoted 6 lines
tools/perf/tests/shell/lib/probe_vfs_getname.sh +3 -0
+			return 0
+		fi
+		perf probe -q "vfs_getname=getname_flags:${line} pathname=result->name:string" || \
 		perf probe $add_probe_verbose "vfs_getname=getname_flags:${line} pathname=filename:ustring" || return 1
 	fi
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1