> diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c > index 69988af44b37..7b1903be6f69 100644 [ ... ] > @@ -307,12 +308,23 @@ static void cgroup_bpf_release(struct work_struct *work) > bpf.release_work); > struct bpf_prog_array *old_array; > struct list_head *storages = &cgrp->bpf.storages; > + struct bpf_struct_ops_link *st_link, *st_tmp; > struct bpf_cgroup_storage *storage, *stmp; > + LIST_HEAD(st_links); > > unsigned int atype; > > cgroup_lock(); > > + list_splice_init(&cgrp->bpf.struct_ops_links, &st_links); > + list_for_each_entry_safe(st_link, st_tmp, &st_links, list) { > + st_link->cgroup = NULL; > + st_link->cgroup_removed = true; > + cgroup_put(cgrp); > + if (IS_ERR(bpf_link_inc_not_zero(&st_link->link))) > + list_del(&st_link->list); > + } Can this code access st_link after it has been freed? Once st_link->cgroup is set to NULL, if another CPU concurrently closes the link FD, bpf_struct_ops_map_link_dealloc() will see st_link->cgroup as NULL, skip the cgroup_bpf_detach_struct_ops() call, and proceed to kfree(st_link). Then the bpf_link_inc_not_zero() call here would access freed memory. The race window is between setting st_link->cgroup = NULL and calling bpf_link_inc_not_zero(). During this window: CPU 0 (cgroup_bpf_release) CPU 1 (close link FD) --------------------------- --------------------- st_link->cgroup = NULL bpf_link_put_direct() bpf_link_free() bpf_struct_ops_map_link_dealloc() if (st_link->cgroup) // false kfree(st_link) // freed! bpf_link_inc_not_zero() // use-after-free Would it be safer to call bpf_link_inc_not_zero() before modifying st_link fields? That way, if the link is already at refcount zero, the loop would skip it; otherwise, the held reference would prevent the concurrent free. --- AI reviewed your patch. Please fix the bug or email reply why it's not a bug. See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md CI run summary: https://github.com/kernel-patches/bpf/actions/runs/21382620878 AI-authorship-score: low AI-authorship-explanation: The commit is authored by a known kernel maintainer with a consistent, human-like technical writing style and appropriate kernel development patterns. issues-found: 1 issue-severity-score: medium issue-severity-explanation: Use-after-free race condition in cgroup_bpf_release() that can cause kernel crash when link FD is closed concurrently with cgroup deletion.