CVE-2026-143292: tcp: wait for TIME_WAIT teardown before freeing per-netns ehash
In the Linux kernel, the following vulnerability has been resolved:
tcp: wait for TIMEWAIT teardown before freeing per-netns ehash
inettwskkill() removes a TIMEWAIT socket from the established hash before it finishes using the ehash lock, hashinfo and bind tables, and before it drops the death-row reference. A running timer can therefore unhash its socket before inettwskpurge() reaches it. The purge cannot synchronize with that timer, and tcpskexitbatch() can free the private ehash and hashinfo while inettwskkill() is still using them.
An unprivileged reproducer using user and network namespaces, a private TCP ehash and a FINWAIT2 timer triggers a KASAN slab-use-after-free in inettwskkill(). The allocation and free stacks point to inetpernethashinfoalloc() and inetpernethashinfofree().
Wait for an RCU grace period after purging the whole batch, if one netns in the batch uses a private ehash. TIMEWAIT removal runs with bottom halves disabled, so this also waits for removers that were already invisible to the purge. Keep the wait under tcpexitbatchmutex, before freeing any private hashinfo.
The same window exists with the shared tcphashinfo. There, the hashinfo memory stays valid, but tcpskexitbatch() can decrement tcpdeathrow.twrefcount from 2 to 1 before inettwskkill() drops its own reference. This triggers the WARNONONCE() in tcpskexitbatch(), then a refcountt "decrement hit 0" warning from inettwskkill().
Adding a grace period for the shared case would be costly on busy hosts. It is not needed: struct net is freed by a later cleanupnet(), after the synchronizercu() in opsundolist(), so inettwskkill() can safely drop the last twrefcount reference itself. Use refcountdecifone() and only warn if twrefcount is not 1 after a grace period.
[edumazet: only call synchronizenet() if one netns in the batch uses a private ehash, use refcountdecifone() to avoid a false WARN with the shared ehash]
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
After purging the whole batch, wait for an RCU grace period before freeing private per-netns ehash/hashinfo; call synchronize_net() when a netns in the batch uses a private ehash.
- Compensating control
In tcp_sk_exit_batch(), use refcount_dec_if_one() and warn only if tw_refcount is not 1.
Event History
Frequently Asked Questions
What conditions are needed to trigger the use-after-free?
The described reproducer is unprivileged and uses user and network namespaces, a private TCP ehash, and a FIN_WAIT2 timer. The race occurs when a TIME_WAIT timer removes a socket while network-namespace TCP teardown is purging sockets and freeing hash structures.
Are systems using the shared TCP hash information also affected?
Yes. The description states that the same race window exists when using the shared tcp_hashinfo, although the explicitly described reproducer uses a private TCP ehash.
How can administrators determine whether the fault has occurred?
The reported manifestation is a KASAN slab-use-after-free in inet_twsk_kill(). The allocation and free stacks point to inet_pernet_hashinfo_alloc() and inet_pernet_hashinfo_free(), respectively.