Skip to content

Commit e8c6c80

Browse files
kkdwivediAlexei Starovoitov
authored andcommitted
selftests/bpf: Expand coverage of preempt tests to sleepable kfunc
For preemption-related kfuncs, we don't test their interaction with sleepable kfuncs (we do test helpers) even though the verifier has code to protect against such a pattern. Expand coverage of the selftest to include this case. Acked-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 cbd8730 commit e8c6c80

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "bpf_misc.h"
66
#include "bpf_experimental.h"
77

8+
extern int bpf_copy_from_user_str(void *dst, u32 dst__sz, const void *unsafe_ptr__ign, u64 flags) __weak __ksym;
9+
810
SEC("?tc")
911
__failure __msg("BPF_EXIT instruction in main prog cannot be used inside bpf_preempt_disable-ed region")
1012
int preempt_lock_missing_1(struct __sk_buff *ctx)
@@ -113,6 +115,18 @@ int preempt_sleepable_helper(void *ctx)
113115
return 0;
114116
}
115117

118+
SEC("?fentry.s/" SYS_PREFIX "sys_getpgid")
119+
__failure __msg("kernel func bpf_copy_from_user_str is sleepable within non-preemptible region")
120+
int preempt_sleepable_kfunc(void *ctx)
121+
{
122+
u32 data;
123+
124+
bpf_preempt_disable();
125+
bpf_copy_from_user_str(&data, sizeof(data), NULL, 0);
126+
bpf_preempt_enable();
127+
return 0;
128+
}
129+
116130
int __noinline preempt_global_subprog(void)
117131
{
118132
preempt_balance_subprog();

0 commit comments

Comments
 (0)