Skip to content

Commit b93ef08

Browse files
iamkafaiAlexei Starovoitov
authored andcommitted
bpf: Fix the irq and nmi check in bpf_sk_storage for tracing usage
The intention of the current check is to avoid using bpf_sk_storage in irq and nmi. Jakub pointed out that the current check cannot do that. For example, in_serving_softirq() returns true if the softirq handling is interrupted by hard irq. Fixes: 8e4597c ("bpf: Allow using bpf_sk_storage in FENTRY/FEXIT/RAW_TP") Suggested-by: Jakub Kicinski <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 024cd2c commit b93ef08

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/core/bpf_sk_storage.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ static bool bpf_sk_storage_tracing_allowed(const struct bpf_prog *prog)
415415
BPF_CALL_4(bpf_sk_storage_get_tracing, struct bpf_map *, map, struct sock *, sk,
416416
void *, value, u64, flags)
417417
{
418-
if (!in_serving_softirq() && !in_task())
418+
if (in_irq() || in_nmi())
419419
return (unsigned long)NULL;
420420

421421
return (unsigned long)____bpf_sk_storage_get(map, sk, value, flags);
@@ -424,7 +424,7 @@ BPF_CALL_4(bpf_sk_storage_get_tracing, struct bpf_map *, map, struct sock *, sk,
424424
BPF_CALL_2(bpf_sk_storage_delete_tracing, struct bpf_map *, map,
425425
struct sock *, sk)
426426
{
427-
if (!in_serving_softirq() && !in_task())
427+
if (in_irq() || in_nmi())
428428
return -EPERM;
429429

430430
return ____bpf_sk_storage_delete(map, sk);

0 commit comments

Comments
 (0)