Skip to content

Commit ca6d9e6

Browse files
xu-langopsiff
authored andcommitted
bpf: fix: Race condition in bpf_trampoline_unlink_cgroup_shim
bug-url: https://lore.kernel.org/all/3c4ebb0b.46ff8.19abab8abe2.Coremail.kaiyanm@hust.edu.cn/ Signed-off-by: xulang <xulang@uniontech.com>
1 parent 12113d8 commit ca6d9e6

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

kernel/bpf/trampoline.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,10 +701,8 @@ int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog,
701701
mutex_lock(&tr->mutex);
702702

703703
shim_link = cgroup_shim_find(tr, bpf_func);
704-
if (shim_link) {
704+
if (shim_link && atomic64_inc_not_zero(&shim_link->link.link.refcnt)) {
705705
/* Reusing existing shim attached by the other program. */
706-
bpf_link_inc(&shim_link->link.link);
707-
708706
mutex_unlock(&tr->mutex);
709707
bpf_trampoline_put(tr); /* bpf_trampoline_get above */
710708
return 0;

0 commit comments

Comments
 (0)