mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paul Dolan <paul.dolan.dev@gmail.com>
To: kees@kernel.org, shuah@kernel.org
Cc: x86@kernel.org, eyal.birger@gmail.com, jolsa@kernel.org,
	mhiramat@kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Paul Dolan <paul.dolan.dev@gmail.com>
Subject: [PATCH] selftests: reject malformed uprobe sysfs values
Date: Thu,  5 Nov 2026 21:11:50 +0000	[thread overview]
Message-ID: <20261105211150.9964-1-paul.dolan.dev@gmail.com> (raw)

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


                 reply	other threads:[~2026-11-05 21:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261105211150.9964-1-paul.dolan.dev@gmail.com \
    --to=paul.dolan.dev@gmail.com \
    --cc=eyal.birger@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=shuah@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®