mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selftests: reject malformed uprobe sysfs values
@ 2026-11-05 21:11 Paul Dolan
  0 siblings, 0 replies; only message in thread
From: Paul Dolan @ 2026-11-05 21:11 UTC (permalink / raw)
  To: kees, shuah
  Cc: x86, eyal.birger, jolsa, mhiramat, linux-kselftest, linux-kernel,
	Paul Dolan

The uprobe helpers in the seccomp and x86 selftests parse integer values
from sysfs with fscanf(). A matching failure returns zero and does not
necessarily set errno, so malformed input can be returned as a valid
zero value.

Both callers treat non-negative values as successful parses, allowing
the failure to propagate as valid uprobe configuration.

Return -EINVAL for matching failures while preserving the existing
handling for successful parses and EOF.

Fixes: c2debdb8544f ("selftests/seccomp: validate uretprobe syscall passes through seccomp")
Fixes: 29edd8b003db ("selftests/x86: Add return uprobe shadow stack test")
Signed-off-by: Paul Dolan <paul.dolan.dev@gmail.com>
---
 tools/testing/selftests/seccomp/seccomp_bpf.c   | 3 +++
 tools/testing/selftests/x86/test_shadow_stack.c | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
index 66bb53bad93b..5671890f0b13 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -5752,6 +5752,9 @@ static int parse_uint_from_file(const char *file, const char *fmt)
 	if (f) {
 		err = fscanf(f, fmt, &ret);
 		fclose(f);
+
+		if (!err)
+			err = -EINVAL;
 	}
 	return err == 1 ? ret : err;
 }
diff --git a/tools/testing/selftests/x86/test_shadow_stack.c b/tools/testing/selftests/x86/test_shadow_stack.c
index 3d6ca33edba4..ab1232fbe523 100644
--- a/tools/testing/selftests/x86/test_shadow_stack.c
+++ b/tools/testing/selftests/x86/test_shadow_stack.c
@@ -748,7 +748,7 @@ static int parse_uint_from_file(const char *file, const char *fmt)
 	}
 	err = fscanf(f, fmt, &ret);
 	if (err != 1) {
-		err = err == EOF ? -EIO : -errno;
+		err = err == EOF ? -EIO : -EINVAL;
 		printf("failed to parse '%s': %d\n", file, err);
 		fclose(f);
 		return err;
-- 
2.56.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-05 21:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-05 21:11 [PATCH] selftests: reject malformed uprobe sysfs values Paul Dolan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®