CVE-2026-139313: bpf: Clear sk_refcnt of a clone before its storage is linked
In the Linux kernel, the following vulnerability has been resolved:
bpf: Clear skrefcnt of a clone before its storage is linked
skclone() sets skrefcnt of the new socket some lines behind bpfskstorageclone(). But the elements which that function copies are linked to their maps at once, and an element leads to its owner: the iterator over a skstorage map hands the owner to its program. bpfskstorageget() with BPFSKSTORAGEGETFCREATE and bpfskstoragedelete() rely on refcountincnotzero() to tell whether they may touch the socket.
skrefcnt is in the part of struct sock which sockcopy() leaves out, and skprotalloc() does not clear a clone unless initonalloc is on. It is zero in an object which has been a socket before, and anything in one which has not. If it is not zero, a helper gets a reference which refcountset() wipes out, and the helper's sockput() then drops one of the two references of the new socket, which is freed too early:
IPv4: Attempt to release TCP socket in state 1 BUG: KASAN: slab-use-after-free in rawspinlockinit+0x47/0x90
In the meantime the helper changes a storage which bpfskstorageclone() fills without taking its lock.
Nothing else can find the clone at this point. Say that it is not alive yet, before the first element is linked. Sockets whose parent has no storage are left alone.
Affected Software
Event History
Frequently Asked Questions
What activity is needed to trigger this issue?
The issue involves socket cloning while BPF socket-storage entries are being cloned and linked to their maps. A BPF program can be handed the socket through socket-storage map iteration and invoke bpf_sk_storage_get() with BPF_SK_STORAGE_GET_F_CREATE or bpf_sk_storage_delete() during that window.
How does memory initialization affect exposure?
The clone's sk_refcnt may contain a nonzero stale value because sock_copy() leaves that field out and sk_prot_alloc() does not clear a clone unless init_on_alloc is enabled. A nonzero value can allow a helper to take a reference that is later overwritten, leading to an early socket free.
What signs could indicate the issue has occurred?
Reported symptoms include an IPv4 attempt to release a TCP socket in state 1 and a KASAN slab-use-after-free report in __raw_spin_lock_init. The race can also allow a helper to modify socket storage while bpf_sk_storage_clone() populates it without taking the storage lock.