CVE-2026-139310: bpf: Hold the socket in the sk_storage map iterator
In the Linux kernel, the following vulnerability has been resolved:
bpf: Hold the socket in the skstorage map iterator
The iterator over a skstorage map passes the owner of an element to its program as ctx->sk, without a reference. All that it holds is the RCU read lock, which keeps the element and the storage, not the socket.
An element is unlinked by bpfskstoragefree(), which skdestruct() calls right before it frees the socket. That is no better for a socket with SOCKRCUFREE: the grace period comes in front of skdestruct(), so a reader which starts behind callrcu() still finds the element. The program and the helpers it hands ctx->sk to, such as bpfskstorageget() or bpfskstoragedelete(), use a socket which is being freed on another CPU. It takes nothing but reading the iterator while sockets with an element in the map are closed, by whomever.
Take a reference for the time of the program, and skip the element if there is none to be had. To look at the owner at all, do what bpfselemunlinknofail() does for bpflocalstoragemapfree(): as long as the element is linked under the lock of the storage, bpflocalstoragedestroy() has not got past it, unless it has given up on the lock, and then it waits for ownerrefcnt.
The last reference may now be dropped by the iterator. The end of a socket may want process context: rfcommsockdestruct() takes a mutex. So only drop the reference under RCU, and free a socket whose last one it was when the RCU read lock has been released, which is at the end of a bucket and of every read() at the latest.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
In the sk_storage map iterator, hold a reference to the socket for the duration of the BPF program so the socket remains alive while its owner is accessed.
Event History
Frequently Asked Questions
Which systems are exposed to this issue?
Systems are exposed when a BPF program reads an iterator over an sk_storage map while sockets that have elements in that map are being closed. The issue concerns the iterator passing the socket owner to the program without holding a socket reference.
Does an attacker need to be the party closing the sockets?
No. The described race requires only that the iterator is read while relevant sockets are closed, and those sockets may be closed by any party. The vulnerable program or helpers can then use a socket that is being freed on another CPU.
How can I assess whether my environment uses the affected path?
Review deployed BPF programs for iteration over sk_storage maps and for use of ctx->sk or helpers such as bpf_sk_storage_get() and bpf_sk_storage_delete() from that iterator. The risk is present if those iterations can overlap with closure of sockets that have associated sk_storage elements.
What does the fix change?
The fix takes a reference to the socket for the duration of the iterator program's execution and skips an element when a reference cannot be obtained. This prevents the iterator program and related helpers from operating on a socket that is being freed.