Skip to contentSkip to conversation

tcp: Fix out-of-bounds access for twsk in tcp_ao_established_key().

PATCH Applied Kuniyuki Iwashima 3 participants 3 messages May 8 – May 12

Subsystems (3)
lore
Share & tools
lore

Kuniyuki Iwashima

author reviewer
#0 lore raw

PATCH v2 1/1 tcp: Fix out-of-bounds access for twsk in tcp_ao_established_key().

lockdep_sock_is_held() was added in tcp_ao_established_key() by the cited commit.

It can be called from tcp_v[46]_timewait_ack() with twsk.

Since it does not have sk->sk_lock, the lockdep annotation results in out-of-bound access.

  $ pahole -C tcp_timewait_sock vmlinux | grep size
  	/* size: 288, cachelines: 5, members: 8 */
  $ pahole -C sock vmlinux | grep sk_lock
  	socket_lock_t              sk_lock;              /*   440   192 */

Let's not use lockdep_sock_is_held() for TCP_TIME_WAIT.

Fixes 6b2d11e2d8fc ("net/tcp: Add missing lockdep annotations for TCP-AO hlist traversals")

---
v2: Ensure that TCP_TIME_WAIT does not evade RCU lockdep check
v1: https://lore.kernel.org/netdev/[email protected]/

---
 net/ipv4/tcp_ao.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/tcp_ao.c +2 -1
index a97cdf3e6af4..0a4b38b315fe 100644
@@ -116,7 +116,8 @@ struct tcp_ao_key *tcp_ao_established_key(const struct sock *sk,
 {
 	struct tcp_ao_key *key;
 
-	hlist_for_each_entry_rcu(key, &ao->head, node, lockdep_sock_is_held(sk)) {
+	hlist_for_each_entry_rcu(key, &ao->head, node,
+				 sk_fullsock(sk) && lockdep_sock_is_held(sk)) {
 		if ((sndid >= 0 && key->sndid != sndid) ||
 		    (rcvid >= 0 && key->rcvid != rcvid))
 			continue;
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
Reviewed-by on v2 1/1
#1 lore raw
Quoted 14 lines · Kuniyuki Iwashima

lockdep_sock_is_held() was added in tcp_ao_established_key() by the cited commit.

It can be called from tcp_v[46]_timewait_ack() with twsk.

Since it does not have sk->sk_lock, the lockdep annotation results in out-of-bound access.

  $ pahole -C tcp_timewait_sock vmlinux | grep size
        /* size: 288, cachelines: 5, members: 8 */
  $ pahole -C sock vmlinux | grep sk_lock
        socket_lock_t              sk_lock;              /*   440   192 */
Quoted 5 lines

Let's not use lockdep_sock_is_held() for TCP_TIME_WAIT.

Fixes 6b2d11e2d8fc ("net/tcp: Add missing lockdep annotations for TCP-AO hlist traversals")
#2 lore raw
In reply to Kuniyuki Iwashima
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Fri, 8 May 2026 12:08:46 +0000 you wrote:

lockdep_sock_is_held() was added in tcp_ao_established_key() by the cited commit.

It can be called from tcp_v[46]_timewait_ack() with twsk.

Since it does not have sk->sk_lock, the lockdep annotation results in out-of-bound access.

[...]

Here is the summary with links:
- [v2,net] tcp: Fix out-of-bounds access for twsk in tcp_ao_established_key().

    https://git.kernel.org/netdev/net/c/03cb001ef87b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html