CVE-2026-139250: tcp: tcp_metrics: use the socket netns, not the dst device netns
In the Linux kernel, the following vulnerability has been resolved:
tcp: tcpmetrics: use the socket netns, not the dst device netns
tcpgetmetrics(), tcpgetmetricsreq() and tcpmnew() look up and create metrics entries in the netns of the cached dst device rather than in the netns of the socket.
These usually match, but not after the device has been moved to another netns or unregistered: a socket can keep a stale dst in skdstcache until it is checked again, and tcpupdatemetrics() reads it with skdstget() without any dstcheck(). Once dstdevput() has run, the dst device is blackholenetdev and the entry is created in initnet. Before that, for instance for routes through nexthop objects whose cached dsts are released from a nested RCU callback, it is the netns the device has just been moved to.
A TCP socket of netns A that enters TIMEWAIT in that window then creates or updates an entry carrying A's addresses and RTT in another netns, where TCPMETRICSCMDGET can dump it and where new connections to the same peer inherit those metrics.
The metrics belong to the netns of the socket, so use socknet() for full sockets and request sockets, and pass it to tcpmnew().
Kernel sockets that do not hold a netns reference can still reach tcptimewait() after tcpnetmetricsexitbatch() has flushed the entries of their dismantling netns, and an entry created then would never be flushed and would keep a dangling tcpmnet. Make tcpmnew() refuse to create entries when checknet() fails. Its callers are in an RCU read-side section, and cleanupnet() waits for a grace period between the refcount reaching zero and the flush, so an entry added after a successful check is always seen by the flush.