Skip to content

Commit 31f23a6

Browse files
Muchun Songborkmann
authored andcommitted
bpf: Fix potential call bpf_link_free() in atomic context
The in_atomic() macro cannot always detect atomic context, in particular, it cannot know about held spinlocks in non-preemptible kernels. Although, there is no user call bpf_link_put() with holding spinlock now, be on the safe side, so we can avoid this in the future. Signed-off-by: Muchun Song <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Song Liu <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 70b9711 commit 31f23a6

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

kernel/bpf/syscall.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,12 +2345,8 @@ void bpf_link_put(struct bpf_link *link)
23452345
if (!atomic64_dec_and_test(&link->refcnt))
23462346
return;
23472347

2348-
if (in_atomic()) {
2349-
INIT_WORK(&link->work, bpf_link_put_deferred);
2350-
schedule_work(&link->work);
2351-
} else {
2352-
bpf_link_free(link);
2353-
}
2348+
INIT_WORK(&link->work, bpf_link_put_deferred);
2349+
schedule_work(&link->work);
23542350
}
23552351

23562352
static int bpf_link_release(struct inode *inode, struct file *filp)

0 commit comments

Comments
 (0)