selftests: reject malformed uprobe sysfs values
Subsystems (3)
PATCH 1/1 selftests: reject malformed uprobe sysfs values
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 <[email protected]>
--- tools/testing/selftests/seccomp/seccomp_bpf.c | 3 +++ tools/testing/selftests/x86/test_shadow_stack.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/seccomp/seccomp_bpf.c +3 -0
@@ -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; }
tools/testing/selftests/x86/test_shadow_stack.c +1 -1
@@ -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;
Signature · 1 line
2.56.0