Skip to content

Commit cbd8730

Browse files
kkdwivediAlexei Starovoitov
authored andcommitted
bpf: Improve verifier log for resource leak on exit
The verifier log when leaking resources on BPF_EXIT may be a bit confusing, as it's a problem only when finally existing from the main prog, not from any of the subprogs. Hence, update the verifier error string and the corresponding selftests matching on it. Acked-by: Eduard Zingerman <[email protected]> Suggested-by: Eduard Zingerman <[email protected]> Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent c8e2ee1 commit cbd8730

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

kernel/bpf/verifier.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19102,7 +19102,7 @@ static int do_check(struct bpf_verifier_env *env)
1910219102
* match caller reference state when it exits.
1910319103
*/
1910419104
err = check_resource_leak(env, exception_exit, !env->cur_state->curframe,
19105-
"BPF_EXIT instruction");
19105+
"BPF_EXIT instruction in main prog");
1910619106
if (err)
1910719107
return err;
1910819108

tools/testing/selftests/bpf/progs/exceptions_fail.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ int reject_subprog_with_lock(void *ctx)
131131
}
132132

133133
SEC("?tc")
134-
__failure __msg("BPF_EXIT instruction cannot be used inside bpf_rcu_read_lock-ed region")
134+
__failure __msg("BPF_EXIT instruction in main prog cannot be used inside bpf_rcu_read_lock-ed region")
135135
int reject_with_rcu_read_lock(void *ctx)
136136
{
137137
bpf_rcu_read_lock();
@@ -147,7 +147,7 @@ __noinline static int throwing_subprog(struct __sk_buff *ctx)
147147
}
148148

149149
SEC("?tc")
150-
__failure __msg("BPF_EXIT instruction cannot be used inside bpf_rcu_read_lock-ed region")
150+
__failure __msg("BPF_EXIT instruction in main prog cannot be used inside bpf_rcu_read_lock-ed region")
151151
int reject_subprog_with_rcu_read_lock(void *ctx)
152152
{
153153
bpf_rcu_read_lock();

tools/testing/selftests/bpf/progs/preempt_lock.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
#include "bpf_experimental.h"
77

88
SEC("?tc")
9-
__failure __msg("BPF_EXIT instruction cannot be used inside bpf_preempt_disable-ed region")
9+
__failure __msg("BPF_EXIT instruction in main prog cannot be used inside bpf_preempt_disable-ed region")
1010
int preempt_lock_missing_1(struct __sk_buff *ctx)
1111
{
1212
bpf_preempt_disable();
1313
return 0;
1414
}
1515

1616
SEC("?tc")
17-
__failure __msg("BPF_EXIT instruction cannot be used inside bpf_preempt_disable-ed region")
17+
__failure __msg("BPF_EXIT instruction in main prog cannot be used inside bpf_preempt_disable-ed region")
1818
int preempt_lock_missing_2(struct __sk_buff *ctx)
1919
{
2020
bpf_preempt_disable();
@@ -23,7 +23,7 @@ int preempt_lock_missing_2(struct __sk_buff *ctx)
2323
}
2424

2525
SEC("?tc")
26-
__failure __msg("BPF_EXIT instruction cannot be used inside bpf_preempt_disable-ed region")
26+
__failure __msg("BPF_EXIT instruction in main prog cannot be used inside bpf_preempt_disable-ed region")
2727
int preempt_lock_missing_3(struct __sk_buff *ctx)
2828
{
2929
bpf_preempt_disable();
@@ -33,7 +33,7 @@ int preempt_lock_missing_3(struct __sk_buff *ctx)
3333
}
3434

3535
SEC("?tc")
36-
__failure __msg("BPF_EXIT instruction cannot be used inside bpf_preempt_disable-ed region")
36+
__failure __msg("BPF_EXIT instruction in main prog cannot be used inside bpf_preempt_disable-ed region")
3737
int preempt_lock_missing_3_minus_2(struct __sk_buff *ctx)
3838
{
3939
bpf_preempt_disable();
@@ -55,15 +55,15 @@ static __noinline void preempt_enable(void)
5555
}
5656

5757
SEC("?tc")
58-
__failure __msg("BPF_EXIT instruction cannot be used inside bpf_preempt_disable-ed region")
58+
__failure __msg("BPF_EXIT instruction in main prog cannot be used inside bpf_preempt_disable-ed region")
5959
int preempt_lock_missing_1_subprog(struct __sk_buff *ctx)
6060
{
6161
preempt_disable();
6262
return 0;
6363
}
6464

6565
SEC("?tc")
66-
__failure __msg("BPF_EXIT instruction cannot be used inside bpf_preempt_disable-ed region")
66+
__failure __msg("BPF_EXIT instruction in main prog cannot be used inside bpf_preempt_disable-ed region")
6767
int preempt_lock_missing_2_subprog(struct __sk_buff *ctx)
6868
{
6969
preempt_disable();
@@ -72,7 +72,7 @@ int preempt_lock_missing_2_subprog(struct __sk_buff *ctx)
7272
}
7373

7474
SEC("?tc")
75-
__failure __msg("BPF_EXIT instruction cannot be used inside bpf_preempt_disable-ed region")
75+
__failure __msg("BPF_EXIT instruction in main prog cannot be used inside bpf_preempt_disable-ed region")
7676
int preempt_lock_missing_2_minus_1_subprog(struct __sk_buff *ctx)
7777
{
7878
preempt_disable();

tools/testing/selftests/bpf/progs/verifier_spin_lock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ l0_%=: r6 = r0; \
187187

188188
SEC("cgroup/skb")
189189
__description("spin_lock: test6 missing unlock")
190-
__failure __msg("BPF_EXIT instruction cannot be used inside bpf_spin_lock-ed region")
190+
__failure __msg("BPF_EXIT instruction in main prog cannot be used inside bpf_spin_lock-ed region")
191191
__failure_unpriv __msg_unpriv("")
192192
__naked void spin_lock_test6_missing_unlock(void)
193193
{

0 commit comments

Comments
 (0)