CVE-2025-38154: bpf, sockmap: Avoid using sk_socket after free when sending
In the Linux kernel, the following vulnerability has been resolved:
bpf, sockmap: Avoid using sksocket after free when sending
The sk->sksocket is not locked or referenced in backlog thread, and during the call to skbsendsock(), there is a race condition with the release of sksocket. All types of sockets(tcp/udp/unix/vsock) will be affected.
Race conditions: ''' CPU0 CPU1
backlog::skbsendsock sendmsgunlocked socksendmsg socksendmsgnosec close(fd): ... ops->release() -> sockmapclose() sksocket->ops = NULL free(socket) sock->ops->sendmsg ^ panic here '''
The ref of psock become 0 after sockmapclose() executed. ''' void sockmapclose() { ... if (likely(psock)) { ... // !! here we remove psock and the ref of psock become 0 sockmapremovelinks(sk, psock) psock = skpsockget(sk); if (unlikely(!psock)) goto nopsock; <=== Control jumps here via goto ... canceldelayedworksync(&psock->work); <=== not executed skpsockput(sk, psock); ... } '''
Based on the fact that we already wait for the workqueue to finish in sockmapclose() if psock is held, we simply increase the psock reference count to avoid race conditions.
With this patch, if the backlog thread is running, sockmapclose() will wait for the backlog thread to complete and cancel all pending work.
If no backlog running, any pending work that hasn't started by then will fail when invoked by skpsockget(), as the psock reference count have been zeroed, and skpsockdrop() will cancel all jobs via canceldelayedworksync().
In summary, we require synchronization to coordinate the backlog thread and close() thread.
The panic I catched: ''' Workqueue: events skpsockbacklog RIP: 0010:socksendmsg+0x21d/0x440 RAX: 0000000000000000 RBX: ffffc9000521fad8 RCX: 0000000000000001 ... Call Trace: <TASK> ? dieaddr+0x40/0xa0 ? excgeneralprotection+0x14c/0x230 ? asmexcgeneralprotection+0x26/0x30 ? socksendmsg+0x21d/0x440 ? socksendmsg+0x3e0/0x440 ? pfxsocksendmsg+0x10/0x10 skbsendsock+0x543/0xb70 skpsockbacklog+0x247/0xb80 ... '''
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
debian/linuxto a version that resolves this vulnerability.Fixed in 6.1.176-1Fixed in 6.1.190-1Fixed in 6.12.107-1Fixed in 6.12.113-1Fixed in 7.2.12-1Fixed in 7.2.13-1 - Compensating control
In the Linux kernel BPF sockmap close path, coordinate sock_map_close() with the backlog thread: when a psock is held, increment its reference count, wait for the backlog thread to complete, and cancel all pending work with cancel_delayed_work_sync(&psock->work) before releasing the socket.
Event History
Frequently Asked Questions
What is the severity of CVE-2025-38154?
The severity of CVE-2025-38154 is classified as high due to its potential to cause a race condition leading to denial of service.
How do I fix CVE-2025-38154?
To fix CVE-2025-38154, update your Linux kernel to the latest patched version provided by your distribution.
Which versions of the Linux kernel are affected by CVE-2025-38154?
CVE-2025-38154 affects multiple versions of the Linux kernel, particularly those before the fix was implemented in the stable releases.
Can CVE-2025-38154 lead to system compromise?
CVE-2025-38154 primarily can lead to denial of service rather than direct system compromise.
Is there a workaround for CVE-2025-38154 pending a patch?
Currently, there is no effective workaround for CVE-2025-38154; the best practice is to apply the security patch as soon as it becomes available.