CVE-2025-22077: Revert "smb: client: fix TCP timers deadlock after rmmod"
In the Linux kernel, the following vulnerability has been resolved:
Revert "smb: client: fix TCP timers deadlock after rmmod"
This reverts commit e9f2517a3e18a54a3943c098d2226b245d488801.
Commit e9f2517a3e18 ("smb: client: fix TCP timers deadlock after rmmod") is intended to fix a null-ptr-deref in LOCKDEP, which is mentioned as CVE-2024-54680, but is actually did not fix anything; The issue can be reproduced on top of it. [0]
Also, it reverted the change by commit ef7134c7fc48 ("smb: client: Fix use-after-free of network namespace.") and introduced a real issue by reviving the kernel TCP socket.
When a reconnect happens for a CIFS connection, the socket state transitions to FINWAIT1. Then, inetcskclearxmittimerssync() in tcpclose() stops all timers for the socket.
If an incoming FIN packet is lost, the socket will stay at FINWAIT1 forever, and such sockets could be leaked up to net.ipv4.tcpmaxorphans.
Usually, FIN can be retransmitted by the peer, but if the peer aborts the connection, the issue comes into reality.
I warned about this privately by pointing out the exact report [1], but the bogus fix was finally merged.
So, we should not stop the timers to finally kill the connection on our side in that case, meaning we must not use a kernel socket for TCP whose sk->sknetrefcnt is 0.
The kernel socket does not have a reference to its netns to make it possible to tear down netns without cleaning up every resource in it.
For example, tunnel devices use a UDP socket internally, but we can destroy netns without removing such devices and let it complete during exit. Otherwise, netns would be leaked when the last application died.
However, this is problematic for TCP sockets because TCP has timers to close the connection gracefully even after the socket is close()d. The lifetime of the socket and its netns is different from the lifetime of the underlying connection.
If the socket user does not maintain the netns lifetime, the timer could be fired after the socket is close()d and its netns is freed up, resulting in use-after-free.
Actually, we have seen so many similar issues and converted such sockets to have a reference to netns.
That's why I converted the CIFS client socket to have a reference to netns (sk->sknetrefcnt == 1), which is somehow mentioned as out-of-scope of CIFS and technically wrong in e9f2517a3e18, but is in-scope and right fix.
Regarding the LOCKDEP issue, we can prevent the module unload by bumping the module refcount when switching the LOCKDDEP key in socklockinitclassandname(). [2]
For a while, let's revert the bogus fix.
Note that now we can use sknetrefcntupgrade() for the socket conversion, but I'll do so later separately to make backport easy.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Configuration
Ensure the CIFS client socket keeps a reference to its network namespace (netns) using sk_net_refcnt_upgrade(), rather than having no netns reference, to prevent netns leak and use-after-free when the socket is closed and its netns is freed.
CIFS client socket netns reference handling via sk_net_refcnt_upgrade() = use sk_net_refcnt_upgrade() so the socket references netns while timers/FIN_WAIT_1 handling can occur - Compensating control
Prevent module unload when encountering the LOCKDEP issue (the text references preventing module unload by sock_lock_init_class_and_name() and bumping module refcount when switching the LOCKDDEP key). Implement the stated LOCKDEP-related mitigation rather than relying on the reverted timer-stopping behavior.
Event History
Frequently Asked Questions
What is the severity of CVE-2025-22077?
CVE-2025-22077 has a medium severity rating due to the potential for resource leaks and use-after-free issues.
How do I fix CVE-2025-22077?
To fix CVE-2025-22077, update your Linux kernel to a version that includes the patches addressing this vulnerability.
Which versions of the Linux kernel are affected by CVE-2025-22077?
CVE-2025-22077 affects certain versions of the Linux kernel prior to the application of the relevant patches.
What types of systems are vulnerable to CVE-2025-22077?
Systems running affected versions of the Linux kernel that utilize SMB client functionalities are vulnerable to CVE-2025-22077.
Is CVE-2025-22077 exploitable remotely?
Yes, CVE-2025-22077 may be exploited remotely if an attacker has access to the SMB services running on the affected systems.