In the Linux kernel, the following vulnerability has been resolved:
net: restore refcount ordering for lockless socket access
Before commit fb041bb7c0a9 ("locking/refcount: Consolidate implementations
of refcount_t"), default builds implemented refcount_inc_not_zero() using
atomic_add_unless(), which provided full memory ordering on success. The
commit removed that ordering on weakly ordered architectures, allowing
accesses after a successful reference acquisition to be reordered before
it.
Use refcount_inc_not_zero_acquire() in the IPv4 and IPv6 established
lookups and in inet_twsk_purge(), where the socket is validated again
after taking a reference.
bpf_sk_assign() can receive a socket pointer obtained through BTF
without a reference. Use acquire ordering when it takes its own reference
for a refcounted socket.
Use refcount_set_release() when setting refcounts in the SYN cookie,
TCP Fast Open, request migration, and TIME_WAIT paths. Keep the existing
TIME_WAIT smp_wmb(), which separately orders the refcount store before
ehash publication.
CVSS Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
CVSS Score: 9.8
AV:N - A TCP segment enters __inet_lookup_established() from tcp_v4_rcv() through __inet_lookup_skb(), and from tcp_v4_early_demux() in ip_rcv_finish_core(); tcp_v6_rcv() does the same via __inet6_lookup_established(). The header 4-tuple is the lookup key, and that segment is delivered to whatever socket the unordered refcount_inc_not_zero() returns.
AC:L - The attacker produces the race by opening and closing connections and by completing SYN-cookie handshakes, so tcp_get_cookie_sock() and connect/close recycle SLAB_TYPESAFE_BY_RCU sockets while further segments enter the lookup. Relaxed refcount_inc_not_zero() does not order the following inet_match() or hlist_nulls_unhashed_lockless() recheck, and no victim action or hardware fault is required.
PR:N - tcp_v4_rcv() and tcp_v4_early_demux() run on every incoming TCP segment before TCP-MD5, TCP-AO, or application authentication. Sending the segment to a listening port performs no credential check on this path.
UI:N - The attacker both recycles the sockets and sends the racing segments. No local user must mount media, open a file, or accept a connection.
S:U - The lookup, the recycled tcp_sock or request_sock, and any dst_entry reached from sk_rx_dst all belong to the host kernel. The bug does not cross a guest-to-host or IOMMU boundary.
C:H - A load of sk_rx_dst after the relaxed refcount_inc_not_zero() can still observe the previous tcp_sock's route, which tcp_disconnect() already passed to dst_release(). tcp_v4_early_demux() and tcp_v4_do_rcv() then read dst->obsolete and call dst->ops->check on that freed dst_entry.
I:H - tcp_v4_do_rcv() dispatches through the stale sk_rx_dst via dst->ops->check and can dst_release() it, writing a freed dst_entry. It also passes the attacker's segment to tcp_rcv_established() on the recycled socket, updating that socket's sequence state and receive queue.
A:H - If reuse returns the unhashed SYN-cookie request published by tcp_get_cookie_sock(), its rsk_listener is NULL and tcp_v4_rcv() reads sk->sk_state at offset 0x12 through that NULL pointer in softirq, oopsing the host. The freed dst_entry dereference faults as well.
| Attack Vector |
Network |
Scope |
Unchanged |
| Attack Complexity |
Low |
Confidentiality Impact |
High |
| Privileges Required |
None |
Integrity Impact |
High |
| User Interaction |
None |
Availability Impact |
High |
AV:N - A TCP segment enters __inet_lookup_established() from tcp_v4_rcv() through __inet_lookup_skb(), and from tcp_v4_early_demux() in ip_rcv_finish_core(); tcp_v6_rcv() does the same via __inet6_lookup_established(). The header 4-tuple is the lookup key, and that segment is delivered to whatever socket the unordered refcount_inc_not_zero() returns.
AC:L - The attacker produces the race by opening and closing connections and by completing SYN-cookie handshakes, so tcp_get_cookie_sock() and connect/close recycle SLAB_TYPESAFE_BY_RCU sockets while further segments enter the lookup. Relaxed refcount_inc_not_zero() does not order the following inet_match() or hlist_nulls_unhashed_lockless() recheck, and no victim action or hardware fault is required.
PR:N - tcp_v4_rcv() and tcp_v4_early_demux() run on every incoming TCP segment before TCP-MD5, TCP-AO, or application authentication. Sending the segment to a listening port performs no credential check on this path.
UI:N - The attacker both recycles the sockets and sends the racing segments. No local user must mount media, open a file, or accept a connection.
S:U - The lookup, the recycled tcp_sock or request_sock, and any dst_entry reached from sk_rx_dst all belong to the host kernel. The bug does not cross a guest-to-host or IOMMU boundary.
C:H - A load of sk_rx_dst after the relaxed refcount_inc_not_zero() can still observe the previous tcp_sock's route, which tcp_disconnect() already passed to dst_release(). tcp_v4_early_demux() and tcp_v4_do_rcv() then read dst->obsolete and call dst->ops->check on that freed dst_entry.
I:H - tcp_v4_do_rcv() dispatches through the stale sk_rx_dst via dst->ops->check and can dst_release() it, writing a freed dst_entry. It also passes the attacker's segment to tcp_rcv_established() on the recycled socket, updating that socket's sequence state and receive queue.
A:H - If reuse returns the unhashed SYN-cookie request published by tcp_get_cookie_sock(), its rsk_listener is NULL and tcp_v4_rcv() reads sk->sk_state at offset 0x12 through that NULL pointer in softirq, oopsing the host. The freed dst_entry dereference faults as well.
CVSS 3.1