* [PATCH bpf-next v4 0/4] bpf: Show precise rejected function when attaching to __noreturn and deny list functions
@ 2025-07-24 15:14 KaFai Wan
2025-07-24 15:14 ` [PATCH bpf-next v4 1/4] bpf: Show precise rejected function when attaching fexit/fmod_ret to __noreturn functions KaFai Wan
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: KaFai Wan @ 2025-07-24 15:14 UTC (permalink / raw)
To: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
yonghong.song, kpsingh, sdf, haoluo, jolsa, mykolal, shuah,
kafai.wan, laoar.shao, linux-kernel, bpf, linux-kselftest,
leon.hwang
Show precise rejected function when attaching fexit/fmod_ret to __noreturn
functions.
Add log for attaching tracing programs to functions in deny list.
Add selftest for attaching tracing programs to functions in deny list.
Migrate fexit_noreturns case into tracing_failure test suite.
changes:
v4:
- change tracing_deny case attaching function (Yonghong Song)
- add Acked-by: Yafang Shao and Yonghong Song
v3:
- add tracing_deny case into existing files (Alexei)
- migrate fexit_noreturns into tracing_failure
- change SOB
https://lore.kernel.org/bpf/20250722153434.20571-1-kafai.wan@linux.dev/
v2:
- change verifier log message (Alexei)
- add missing Suggested-by
https://lore.kernel.org/bpf/20250714120408.1627128-1-mannkafai@gmail.com/
v1:
https://lore.kernel.org/all/20250710162717.3808020-1-mannkafai@gmail.com/
---
KaFai Wan (4):
bpf: Show precise rejected function when attaching fexit/fmod_ret to
__noreturn functions
bpf: Add log for attaching tracing programs to functions in deny list
selftests/bpf: Add selftest for attaching tracing programs to
functions in deny list
selftests/bpf: Migrate fexit_noreturns case into tracing_failure test
suite
kernel/bpf/verifier.c | 5 +-
.../bpf/prog_tests/fexit_noreturns.c | 9 ----
.../bpf/prog_tests/tracing_failure.c | 52 +++++++++++++++++++
.../selftests/bpf/progs/fexit_noreturns.c | 15 ------
.../selftests/bpf/progs/tracing_failure.c | 12 +++++
5 files changed, 68 insertions(+), 25 deletions(-)
delete mode 100644 tools/testing/selftests/bpf/prog_tests/fexit_noreturns.c
delete mode 100644 tools/testing/selftests/bpf/progs/fexit_noreturns.c
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH bpf-next v4 1/4] bpf: Show precise rejected function when attaching fexit/fmod_ret to __noreturn functions
2025-07-24 15:14 [PATCH bpf-next v4 0/4] bpf: Show precise rejected function when attaching to __noreturn and deny list functions KaFai Wan
@ 2025-07-24 15:14 ` KaFai Wan
2025-07-24 15:14 ` [PATCH bpf-next v4 2/4] bpf: Add log for attaching tracing programs to functions in deny list KaFai Wan
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: KaFai Wan @ 2025-07-24 15:14 UTC (permalink / raw)
To: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
yonghong.song, kpsingh, sdf, haoluo, jolsa, mykolal, shuah,
kafai.wan, laoar.shao, linux-kernel, bpf, linux-kselftest,
leon.hwang
With this change, we know the precise rejected function name when
attaching fexit/fmod_ret to __noreturn functions from log.
$ ./fexit
libbpf: prog 'fexit': BPF program load failed: -EINVAL
libbpf: prog 'fexit': -- BEGIN PROG LOAD LOG --
Attaching fexit/fmod_ret to __noreturn function 'do_exit' is rejected.
Suggested-by: Leon Hwang <leon.hwang@linux.dev>
Signed-off-by: KaFai Wan <kafai.wan@linux.dev>
Acked-by: Yafang Shao <laoar.shao@gmail.com>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
---
kernel/bpf/verifier.c | 3 ++-
tools/testing/selftests/bpf/progs/fexit_noreturns.c | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index e2fcea860755..00d287814f12 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -23946,7 +23946,8 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
} else if ((prog->expected_attach_type == BPF_TRACE_FEXIT ||
prog->expected_attach_type == BPF_MODIFY_RETURN) &&
btf_id_set_contains(&noreturn_deny, btf_id)) {
- verbose(env, "Attaching fexit/fmod_ret to __noreturn functions is rejected.\n");
+ verbose(env, "Attaching fexit/fmod_ret to __noreturn function '%s' is rejected.\n",
+ tgt_info.tgt_name);
return -EINVAL;
}
diff --git a/tools/testing/selftests/bpf/progs/fexit_noreturns.c b/tools/testing/selftests/bpf/progs/fexit_noreturns.c
index 54654539f550..b1c33d958ae2 100644
--- a/tools/testing/selftests/bpf/progs/fexit_noreturns.c
+++ b/tools/testing/selftests/bpf/progs/fexit_noreturns.c
@@ -8,7 +8,7 @@
char _license[] SEC("license") = "GPL";
SEC("fexit/do_exit")
-__failure __msg("Attaching fexit/fmod_ret to __noreturn functions is rejected.")
+__failure __msg("Attaching fexit/fmod_ret to __noreturn function 'do_exit' is rejected.")
int BPF_PROG(noreturns)
{
return 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH bpf-next v4 2/4] bpf: Add log for attaching tracing programs to functions in deny list
2025-07-24 15:14 [PATCH bpf-next v4 0/4] bpf: Show precise rejected function when attaching to __noreturn and deny list functions KaFai Wan
2025-07-24 15:14 ` [PATCH bpf-next v4 1/4] bpf: Show precise rejected function when attaching fexit/fmod_ret to __noreturn functions KaFai Wan
@ 2025-07-24 15:14 ` KaFai Wan
2025-07-24 15:14 ` [PATCH bpf-next v4 3/4] selftests/bpf: Add selftest " KaFai Wan
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: KaFai Wan @ 2025-07-24 15:14 UTC (permalink / raw)
To: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
yonghong.song, kpsingh, sdf, haoluo, jolsa, mykolal, shuah,
kafai.wan, laoar.shao, linux-kernel, bpf, linux-kselftest,
leon.hwang
Show the rejected function name when attaching tracing programs to
functions in deny list.
With this change, we know why tracing programs can't attach to functions
like __rcu_read_lock() from log.
$ ./fentry
libbpf: prog '__rcu_read_lock': BPF program load failed: -EINVAL
libbpf: prog '__rcu_read_lock': -- BEGIN PROG LOAD LOG --
Attaching tracing programs to function '__rcu_read_lock' is rejected.
Suggested-by: Leon Hwang <leon.hwang@linux.dev>
Signed-off-by: KaFai Wan <kafai.wan@linux.dev>
Acked-by: Yafang Shao <laoar.shao@gmail.com>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
---
kernel/bpf/verifier.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 00d287814f12..c24c0d57e595 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -23942,6 +23942,8 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
return ret;
} else if (prog->type == BPF_PROG_TYPE_TRACING &&
btf_id_set_contains(&btf_id_deny, btf_id)) {
+ verbose(env, "Attaching tracing programs to function '%s' is rejected.\n",
+ tgt_info.tgt_name);
return -EINVAL;
} else if ((prog->expected_attach_type == BPF_TRACE_FEXIT ||
prog->expected_attach_type == BPF_MODIFY_RETURN) &&
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH bpf-next v4 3/4] selftests/bpf: Add selftest for attaching tracing programs to functions in deny list
2025-07-24 15:14 [PATCH bpf-next v4 0/4] bpf: Show precise rejected function when attaching to __noreturn and deny list functions KaFai Wan
2025-07-24 15:14 ` [PATCH bpf-next v4 1/4] bpf: Show precise rejected function when attaching fexit/fmod_ret to __noreturn functions KaFai Wan
2025-07-24 15:14 ` [PATCH bpf-next v4 2/4] bpf: Add log for attaching tracing programs to functions in deny list KaFai Wan
@ 2025-07-24 15:14 ` KaFai Wan
2025-07-24 15:14 ` [PATCH bpf-next v4 4/4] selftests/bpf: Migrate fexit_noreturns case into tracing_failure test suite KaFai Wan
2025-07-29 2:50 ` [PATCH bpf-next v4 0/4] bpf: Show precise rejected function when attaching to __noreturn and deny list functions patchwork-bot+netdevbpf
4 siblings, 0 replies; 6+ messages in thread
From: KaFai Wan @ 2025-07-24 15:14 UTC (permalink / raw)
To: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
yonghong.song, kpsingh, sdf, haoluo, jolsa, mykolal, shuah,
kafai.wan, laoar.shao, linux-kernel, bpf, linux-kselftest,
leon.hwang
The result:
$ tools/testing/selftests/bpf/test_progs -t tracing_failure/tracing_deny
#468/3 tracing_failure/tracing_deny:OK
#468 tracing_failure:OK
Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: KaFai Wan <kafai.wan@linux.dev>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
---
.../bpf/prog_tests/tracing_failure.c | 33 +++++++++++++++++++
.../selftests/bpf/progs/tracing_failure.c | 6 ++++
2 files changed, 39 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_failure.c b/tools/testing/selftests/bpf/prog_tests/tracing_failure.c
index a222df765bc3..39b59276884a 100644
--- a/tools/testing/selftests/bpf/prog_tests/tracing_failure.c
+++ b/tools/testing/selftests/bpf/prog_tests/tracing_failure.c
@@ -28,10 +28,43 @@ static void test_bpf_spin_lock(bool is_spin_lock)
tracing_failure__destroy(skel);
}
+static void test_tracing_deny(void)
+{
+ struct tracing_failure *skel;
+ char log_buf[256];
+ int btf_id, err;
+
+ /* __rcu_read_lock depends on CONFIG_PREEMPT_RCU */
+ btf_id = libbpf_find_vmlinux_btf_id("__rcu_read_lock", BPF_TRACE_FENTRY);
+ if (btf_id <= 0) {
+ test__skip();
+ return;
+ }
+
+ skel = tracing_failure__open();
+ if (!ASSERT_OK_PTR(skel, "tracing_failure__open"))
+ return;
+
+ bpf_program__set_autoload(skel->progs.tracing_deny, true);
+ bpf_program__set_log_buf(skel->progs.tracing_deny, log_buf, sizeof(log_buf));
+
+ err = tracing_failure__load(skel);
+ if (!ASSERT_ERR(err, "tracing_failure__load"))
+ goto out;
+
+ ASSERT_HAS_SUBSTR(log_buf,
+ "Attaching tracing programs to function '__rcu_read_lock' is rejected.",
+ "log_buf");
+out:
+ tracing_failure__destroy(skel);
+}
+
void test_tracing_failure(void)
{
if (test__start_subtest("bpf_spin_lock"))
test_bpf_spin_lock(true);
if (test__start_subtest("bpf_spin_unlock"))
test_bpf_spin_lock(false);
+ if (test__start_subtest("tracing_deny"))
+ test_tracing_deny();
}
diff --git a/tools/testing/selftests/bpf/progs/tracing_failure.c b/tools/testing/selftests/bpf/progs/tracing_failure.c
index d41665d2ec8c..58d2777014e1 100644
--- a/tools/testing/selftests/bpf/progs/tracing_failure.c
+++ b/tools/testing/selftests/bpf/progs/tracing_failure.c
@@ -18,3 +18,9 @@ int BPF_PROG(test_spin_unlock, struct bpf_spin_lock *lock)
{
return 0;
}
+
+SEC("?fentry/__rcu_read_lock")
+int BPF_PROG(tracing_deny)
+{
+ return 0;
+}
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH bpf-next v4 4/4] selftests/bpf: Migrate fexit_noreturns case into tracing_failure test suite
2025-07-24 15:14 [PATCH bpf-next v4 0/4] bpf: Show precise rejected function when attaching to __noreturn and deny list functions KaFai Wan
` (2 preceding siblings ...)
2025-07-24 15:14 ` [PATCH bpf-next v4 3/4] selftests/bpf: Add selftest " KaFai Wan
@ 2025-07-24 15:14 ` KaFai Wan
2025-07-29 2:50 ` [PATCH bpf-next v4 0/4] bpf: Show precise rejected function when attaching to __noreturn and deny list functions patchwork-bot+netdevbpf
4 siblings, 0 replies; 6+ messages in thread
From: KaFai Wan @ 2025-07-24 15:14 UTC (permalink / raw)
To: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
yonghong.song, kpsingh, sdf, haoluo, jolsa, mykolal, shuah,
kafai.wan, laoar.shao, linux-kernel, bpf, linux-kselftest,
leon.hwang
Delete fexit_noreturns.c files and migrate the cases into
tracing_failure.c files.
The result:
$ tools/testing/selftests/bpf/test_progs -t tracing_failure/fexit_noreturns
#467/4 tracing_failure/fexit_noreturns:OK
#467 tracing_failure:OK
Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: KaFai Wan <kafai.wan@linux.dev>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
---
.../bpf/prog_tests/fexit_noreturns.c | 9 ----
.../bpf/prog_tests/tracing_failure.c | 47 +++++++++++++------
.../selftests/bpf/progs/fexit_noreturns.c | 15 ------
.../selftests/bpf/progs/tracing_failure.c | 6 +++
4 files changed, 39 insertions(+), 38 deletions(-)
delete mode 100644 tools/testing/selftests/bpf/prog_tests/fexit_noreturns.c
delete mode 100644 tools/testing/selftests/bpf/progs/fexit_noreturns.c
diff --git a/tools/testing/selftests/bpf/prog_tests/fexit_noreturns.c b/tools/testing/selftests/bpf/prog_tests/fexit_noreturns.c
deleted file mode 100644
index 568d3aa48a78..000000000000
--- a/tools/testing/selftests/bpf/prog_tests/fexit_noreturns.c
+++ /dev/null
@@ -1,9 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <test_progs.h>
-#include "fexit_noreturns.skel.h"
-
-void test_fexit_noreturns(void)
-{
- RUN_TESTS(fexit_noreturns);
-}
diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_failure.c b/tools/testing/selftests/bpf/prog_tests/tracing_failure.c
index 39b59276884a..10e231965589 100644
--- a/tools/testing/selftests/bpf/prog_tests/tracing_failure.c
+++ b/tools/testing/selftests/bpf/prog_tests/tracing_failure.c
@@ -28,37 +28,54 @@ static void test_bpf_spin_lock(bool is_spin_lock)
tracing_failure__destroy(skel);
}
-static void test_tracing_deny(void)
+static void test_tracing_fail_prog(const char *prog_name, const char *exp_msg)
{
struct tracing_failure *skel;
+ struct bpf_program *prog;
char log_buf[256];
- int btf_id, err;
-
- /* __rcu_read_lock depends on CONFIG_PREEMPT_RCU */
- btf_id = libbpf_find_vmlinux_btf_id("__rcu_read_lock", BPF_TRACE_FENTRY);
- if (btf_id <= 0) {
- test__skip();
- return;
- }
+ int err;
skel = tracing_failure__open();
if (!ASSERT_OK_PTR(skel, "tracing_failure__open"))
return;
- bpf_program__set_autoload(skel->progs.tracing_deny, true);
- bpf_program__set_log_buf(skel->progs.tracing_deny, log_buf, sizeof(log_buf));
+ prog = bpf_object__find_program_by_name(skel->obj, prog_name);
+ if (!ASSERT_OK_PTR(prog, "bpf_object__find_program_by_name"))
+ goto out;
+
+ bpf_program__set_autoload(prog, true);
+ bpf_program__set_log_buf(prog, log_buf, sizeof(log_buf));
err = tracing_failure__load(skel);
if (!ASSERT_ERR(err, "tracing_failure__load"))
goto out;
- ASSERT_HAS_SUBSTR(log_buf,
- "Attaching tracing programs to function '__rcu_read_lock' is rejected.",
- "log_buf");
+ ASSERT_HAS_SUBSTR(log_buf, exp_msg, "log_buf");
out:
tracing_failure__destroy(skel);
}
+static void test_tracing_deny(void)
+{
+ int btf_id;
+
+ /* __rcu_read_lock depends on CONFIG_PREEMPT_RCU */
+ btf_id = libbpf_find_vmlinux_btf_id("__rcu_read_lock", BPF_TRACE_FENTRY);
+ if (btf_id <= 0) {
+ test__skip();
+ return;
+ }
+
+ test_tracing_fail_prog("tracing_deny",
+ "Attaching tracing programs to function '__rcu_read_lock' is rejected.");
+}
+
+static void test_fexit_noreturns(void)
+{
+ test_tracing_fail_prog("fexit_noreturns",
+ "Attaching fexit/fmod_ret to __noreturn function 'do_exit' is rejected.");
+}
+
void test_tracing_failure(void)
{
if (test__start_subtest("bpf_spin_lock"))
@@ -67,4 +84,6 @@ void test_tracing_failure(void)
test_bpf_spin_lock(false);
if (test__start_subtest("tracing_deny"))
test_tracing_deny();
+ if (test__start_subtest("fexit_noreturns"))
+ test_fexit_noreturns();
}
diff --git a/tools/testing/selftests/bpf/progs/fexit_noreturns.c b/tools/testing/selftests/bpf/progs/fexit_noreturns.c
deleted file mode 100644
index b1c33d958ae2..000000000000
--- a/tools/testing/selftests/bpf/progs/fexit_noreturns.c
+++ /dev/null
@@ -1,15 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <linux/bpf.h>
-#include <bpf/bpf_helpers.h>
-#include <bpf/bpf_tracing.h>
-#include "bpf_misc.h"
-
-char _license[] SEC("license") = "GPL";
-
-SEC("fexit/do_exit")
-__failure __msg("Attaching fexit/fmod_ret to __noreturn function 'do_exit' is rejected.")
-int BPF_PROG(noreturns)
-{
- return 0;
-}
diff --git a/tools/testing/selftests/bpf/progs/tracing_failure.c b/tools/testing/selftests/bpf/progs/tracing_failure.c
index 58d2777014e1..65e485c4468c 100644
--- a/tools/testing/selftests/bpf/progs/tracing_failure.c
+++ b/tools/testing/selftests/bpf/progs/tracing_failure.c
@@ -24,3 +24,9 @@ int BPF_PROG(tracing_deny)
{
return 0;
}
+
+SEC("?fexit/do_exit")
+int BPF_PROG(fexit_noreturns)
+{
+ return 0;
+}
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH bpf-next v4 0/4] bpf: Show precise rejected function when attaching to __noreturn and deny list functions
2025-07-24 15:14 [PATCH bpf-next v4 0/4] bpf: Show precise rejected function when attaching to __noreturn and deny list functions KaFai Wan
` (3 preceding siblings ...)
2025-07-24 15:14 ` [PATCH bpf-next v4 4/4] selftests/bpf: Migrate fexit_noreturns case into tracing_failure test suite KaFai Wan
@ 2025-07-29 2:50 ` patchwork-bot+netdevbpf
4 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-07-29 2:50 UTC (permalink / raw)
To: KaFai Wan
Cc: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
yonghong.song, kpsingh, sdf, haoluo, jolsa, mykolal, shuah,
laoar.shao, linux-kernel, bpf, linux-kselftest, leon.hwang
Hello:
This series was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Thu, 24 Jul 2025 23:14:50 +0800 you wrote:
> Show precise rejected function when attaching fexit/fmod_ret to __noreturn
> functions.
> Add log for attaching tracing programs to functions in deny list.
> Add selftest for attaching tracing programs to functions in deny list.
> Migrate fexit_noreturns case into tracing_failure test suite.
>
> changes:
> v4:
> - change tracing_deny case attaching function (Yonghong Song)
> - add Acked-by: Yafang Shao and Yonghong Song
>
> [...]
Here is the summary with links:
- [bpf-next,v4,1/4] bpf: Show precise rejected function when attaching fexit/fmod_ret to __noreturn functions
https://git.kernel.org/bpf/bpf-next/c/a5a6b29a700f
- [bpf-next,v4,2/4] bpf: Add log for attaching tracing programs to functions in deny list
https://git.kernel.org/bpf/bpf-next/c/863aab3d4dcd
- [bpf-next,v4,3/4] selftests/bpf: Add selftest for attaching tracing programs to functions in deny list
https://git.kernel.org/bpf/bpf-next/c/a32f6f17a74d
- [bpf-next,v4,4/4] selftests/bpf: Migrate fexit_noreturns case into tracing_failure test suite
https://git.kernel.org/bpf/bpf-next/c/51d3750aba79
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-07-29 2:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-24 15:14 [PATCH bpf-next v4 0/4] bpf: Show precise rejected function when attaching to __noreturn and deny list functions KaFai Wan
2025-07-24 15:14 ` [PATCH bpf-next v4 1/4] bpf: Show precise rejected function when attaching fexit/fmod_ret to __noreturn functions KaFai Wan
2025-07-24 15:14 ` [PATCH bpf-next v4 2/4] bpf: Add log for attaching tracing programs to functions in deny list KaFai Wan
2025-07-24 15:14 ` [PATCH bpf-next v4 3/4] selftests/bpf: Add selftest " KaFai Wan
2025-07-24 15:14 ` [PATCH bpf-next v4 4/4] selftests/bpf: Migrate fexit_noreturns case into tracing_failure test suite KaFai Wan
2025-07-29 2:50 ` [PATCH bpf-next v4 0/4] bpf: Show precise rejected function when attaching to __noreturn and deny list functions patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).