]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tcp: Fix out-of-bounds access for twsk in tcp_ao_established_key().
authorKuniyuki Iwashima <kuniyu@google.com>
Fri, 8 May 2026 12:08:46 +0000 (12:08 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 1 Jun 2026 15:46:26 +0000 (17:46 +0200)
[ Upstream commit 03cb001ef87b3f8d859cf7f96329acf3d6235d29 ]

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")
Reported-by: Damiano Melotti <melotti@google.com>
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260508120853.4098365-1-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/ipv4/tcp_ao.c

index 72957523c2eca424e460301254b2f620cdfa49c6..be38712265c37c1298d5b4f6eb9df47897a64ffc 100644 (file)
@@ -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;