BPF List
 help / color / mirror / Atom feed
From: Anton Protopopov <a.s.protopopov@gmail.com>
To: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Alan Maguire <almagui@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	bpf@vger.kernel.org
Subject: Re: [PATCH v1 bpf-next 4/7] selftests/bpf: Test fmod_ret on a declared function that returns a pointer
Date: Wed, 25 Nov 2026 13:34:12 +0000	[thread overview]
Message-ID: <awbj1OVca5Ep-wuN@mail.gmail.com> (raw)
In-Reply-To: <20261125102810.699464-5-a.s.protopopov@gmail.com>

On 26/11/25 10:28AM, Anton Protopopov wrote:
> Add bpf_testmod_modify_return_ptr() to the error injection list.
> Check that a program on it may return an error pointer but not
> another value, and that an extension of a global function of such a
> program loads.

Once the https://lore.kernel.org/bpf/20261125032938.670542-1-alexei.starovoitov@gmail.com/
series loads this selftest will fail. So I will send v2 later. Just
in case, the new patch is (after removing freplace piece):

selftests/bpf: Test fmod_ret on a declared function that returns a pointer

Add bpf_testmod_modify_return_ptr() to the error injection list.
Check that a program on it may return an error pointer but not
another value.

Signed-off-by: Anton Protopopov <a.s.protopopov@gmail.com>

diff --git a/tools/testing/selftests/bpf/prog_tests/modify_return.c b/tools/testing/selftests/bpf/prog_tests/modify_return.c
index 2417030f104a..91f810319e87 100644
--- a/tools/testing/selftests/bpf/prog_tests/modify_return.c
+++ b/tools/testing/selftests/bpf/prog_tests/modify_return.c
@@ -8,6 +8,7 @@
 #include <unistd.h>
 #include "modify_return.skel.h"
 #include "modify_return_width.skel.h"
+#include "modify_return_ptr.skel.h"
 
 #define LOWER(x) ((x) & 0xffff)
 #define UPPER(x) ((x) >> 16)
@@ -144,3 +145,9 @@ void test_modify_return_graph(void)
 out:
 	ASSERT_OK(rmdir(instance), "rmdir");
 }
+
+/* NULL or an error from a declared function that returns a pointer */
+void test_modify_return_ptr(void)
+{
+	RUN_TESTS(modify_return_ptr);
+}
diff --git a/tools/testing/selftests/bpf/progs/err.h b/tools/testing/selftests/bpf/progs/err.h
index 38529779a236..be3100752d35 100644
--- a/tools/testing/selftests/bpf/progs/err.h
+++ b/tools/testing/selftests/bpf/progs/err.h
@@ -25,4 +25,9 @@ static inline long PTR_ERR(const void *ptr)
 	return (long) ptr;
 }
 
+static inline void *ERR_PTR(long error)
+{
+	return (void *) error;
+}
+
 #endif /* __ERR_H__ */
diff --git a/tools/testing/selftests/bpf/progs/modify_return_ptr.c b/tools/testing/selftests/bpf/progs/modify_return_ptr.c
new file mode 100644
index 000000000000..dfc6f0185caf
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/modify_return_ptr.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <vmlinux.h>
+#include <errno.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+#include "bpf_misc.h"
+#include "err.h"
+
+char _license[] SEC("license") = "GPL";
+
+SEC("fmod_ret/bpf_testmod_modify_return_ptr")
+__load_if_JITed()
+__success
+void *BPF_PROG(error)
+{
+	return ERR_PTR(-EINVAL);
+}
+
+SEC("fmod_ret/bpf_testmod_modify_return_ptr")
+__failure __msg("should have been in [-4095, 0]")
+void *BPF_PROG(not_an_error)
+{
+	return (void *)1;
+}
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
index 1fbc0061cc24..73d5992cc17a 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
@@ -774,6 +774,13 @@ noinline bool bpf_testmod_modify_return_bool(void)
 }
 ALLOW_ERROR_INJECTION(bpf_testmod_modify_return_bool, TRUE);
 
+noinline void *bpf_testmod_modify_return_ptr(void)
+{
+	asm volatile ("");
+	return NULL;
+}
+ALLOW_ERROR_INJECTION(bpf_testmod_modify_return_ptr, ERRNO);
+
 noinline ssize_t
 bpf_testmod_test_read(struct file *file, struct kobject *kobj,
 		      const struct bin_attribute *bin_attr,


  reply	other threads:[~2026-11-25 13:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 10:27 [PATCH v1 bpf-next 0/7] Tag fmod_ret functions that return ERR_PTR() Anton Protopopov
2026-11-25 10:27 ` [PATCH v1 bpf-next 1/7] bpf: Require the JIT for fmod_ret programs on 64-bit functions Anton Protopopov
2026-11-25 10:27 ` [PATCH v1 bpf-next 2/7] bpf: Remove a wrong comment about fmod_ret targets Anton Protopopov
2026-11-25 10:28 ` [PATCH v1 bpf-next 3/7] bpf: Allow only NULL or ERR_PTR() from fmod_ret on pointer functions Anton Protopopov
2026-11-25 10:47   ` bot+bpf-ci
2026-11-25 13:14     ` Anton Protopopov
2026-11-25 13:38   ` Anton Protopopov
2026-11-25 10:28 ` [PATCH v1 bpf-next 4/7] selftests/bpf: Test fmod_ret on a declared function that returns a pointer Anton Protopopov
2026-11-25 13:34   ` Anton Protopopov [this message]
2026-11-25 10:28 ` [PATCH v1 bpf-next 5/7] bpf: Check fmod_ret return values of tagged pointer targets in 64 bits Anton Protopopov
2026-11-25 10:28 ` [PATCH v1 bpf-next 6/7] resolve_btfids: Tag the functions that return ERR_PTR() Anton Protopopov
2026-11-25 10:28 ` [PATCH v1 bpf-next 7/7] selftests/bpf: Test fmod_ret on functions that return a pointer Anton Protopopov

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=awbj1OVca5Ep-wuN@mail.gmail.com \
    --to=a.s.protopopov@gmail.com \
    --cc=almagui@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=john.fastabend@gmail.com \
    --cc=memxor@gmail.com \
    /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