mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-30 22:26:55 +00:00
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 <songmuchun@bytedance.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Song Liu <songliubraving@fb.com> Acked-by: Andrii Nakryiko <andriin@fb.com> Link: https://lore.kernel.org/bpf/20200917074453.20621-1-songmuchun@bytedance.com
This commit is contained in:
parent
70b971118e
commit
31f23a6a18
1 changed files with 2 additions and 6 deletions
|
@ -2345,12 +2345,8 @@ void bpf_link_put(struct bpf_link *link)
|
||||||
if (!atomic64_dec_and_test(&link->refcnt))
|
if (!atomic64_dec_and_test(&link->refcnt))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (in_atomic()) {
|
INIT_WORK(&link->work, bpf_link_put_deferred);
|
||||||
INIT_WORK(&link->work, bpf_link_put_deferred);
|
schedule_work(&link->work);
|
||||||
schedule_work(&link->work);
|
|
||||||
} else {
|
|
||||||
bpf_link_free(link);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bpf_link_release(struct inode *inode, struct file *filp)
|
static int bpf_link_release(struct inode *inode, struct file *filp)
|
||||||
|
|
Loading…
Reference in a new issue