From nobody Sat Sep 5 05:49:25 2026 Received: from relay.smtp-ext.broadcom.com (relay.smtp-ext.broadcom.com [192.19.144.205]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA1B24E1408 for ; Thu, 3 Sep 2026 17:49:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.19.144.205 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788457799; cv=none; b=Zwyw1VE3NVyAzvZL3wCdJHPXLRdLQd7HTlxYPVmFMIH29Qu32C5IHIGc4QFAmaQ9P8bJPiP73CFrejfJSJ2CpnDRCQMCHteio0CCiz63nIsHEe0tM96ySp+m7QCRgAglbNKDwtcIYZHjVWjOG7Cm4ryhCT0Y5Y2qjaZPbARIXRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788457799; c=relaxed/simple; bh=UuLIBGLM6kpyCorOzcsTXbcPsM7DrcwoF0cy7pxh2uQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=uLnjhZKD83/D0mqyhMf79xxzCqyaqLg6BMgbyYjiprZcQF3BlduG+sJtI7H82KkySZ2Z5dUMEDJYL3K9tY3FYVHgNLZLrWDVjRHXyCFOu5sWAB4EYKeob23/id35jtYW7aC3U7i0Z8srhiFU4M6v7SoKqy4OwGsncLzKJLiD6ME= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=Stc+UtvJ; arc=none smtp.client-ip=192.19.144.205 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="Stc+UtvJ" Received: from mail-acc-it-01.broadcom.com (mail-acc-it-01.acc.broadcom.net [10.35.36.83]) by relay.smtp-ext.broadcom.com (Postfix) with ESMTP id 79A2AC0000E2; Thu, 3 Sep 2026 10:40:19 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 relay.smtp-ext.broadcom.com 79A2AC0000E2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1788457219; bh=UuLIBGLM6kpyCorOzcsTXbcPsM7DrcwoF0cy7pxh2uQ=; h=From:To:Cc:Subject:Date:From; b=Stc+UtvJT41XsNSq+MvocCIFd7wfZ2sVXYbd2FlK8yWKNeKCGl0TgkF23F0PXjb8S hixkJYlyrnUk0wVODZ9YetZF7BIfHz8bRpug+m9ns58t0mzOlwRVC/6biqJ7G+/dwe qrzNb7gPln08MkDWXQC8y1zfnfqZRIq2szwaYtnM= Received: from stbirv-lnx-1.igp.broadcom.net (stbirv-lnx-1.igp.broadcom.net [10.67.48.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail-acc-it-01.broadcom.com (Postfix) with ESMTPSA id 5C5C0AEA2; Thu, 3 Sep 2026 13:40:18 -0400 (EDT) From: Florian Fainelli To: stable@vger.kernel.org Cc: Eric Dumazet , syzbot+937b5bbb6a815b3e5d0b@syzkaller.appspotmail.com, Kuniyuki Iwashima , Jakub Kicinski , Florian Fainelli , "David S. Miller" , Paolo Abeni , Simon Horman , Neal Cardwell , Matthieu Baerts , Mat Martineau , Geliang Tang , netdev@vger.kernel.org (open list:NETWORKING [GENERAL]), linux-kernel@vger.kernel.org (open list), mptcp@lists.linux.dev (open list:NETWORKING [MPTCP]), bcm-kernel-feedback-list@broadcom.com Subject: [PATCH stable 6.12] tcp: fix potential race in tcp_v6_syn_recv_sock() Date: Thu, 3 Sep 2026 10:40:16 -0700 Message-Id: <20260903174016.689839-1-florian.fainelli@broadcom.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Eric Dumazet Code in tcp_v6_syn_recv_sock() after the call to tcp_v4_syn_recv_sock() is done too late. After tcp_v4_syn_recv_sock(), the child socket is already visible from TCP ehash table and other cpus might use it. Since newinet->pinet6 is still pointing to the listener ipv6_pinfo bad things can happen as syzbot found. Move the problematic code in tcp_v6_mapped_child_init() and call this new helper from tcp_v4_syn_recv_sock() before the ehash insertion. This allows the removal of one tcp_sync_mss(), since tcp_v4_syn_recv_sock() will call it with the correct context. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: syzbot+937b5bbb6a815b3e5d0b@syzkaller.appspotmail.com Closes: https://lore.kernel.org/netdev/69949275.050a0220.2eeac1.0145.GAE@go= ogle.com/ Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20260217161205.2079883-1-edumazet@google.com Signed-off-by: Jakub Kicinski (cherry picked from commit 858d2a4f67ff69e645a43487ef7ea7f28f06deae) [florian: - net/ipv6/tcp_ipv6.c: - Set `newnp->ipv6_fl_list =3D NULL` instead of `newinet->ipv6_fl_list = =3D NULL`, as `ipv6_fl_list` is in `struct ipv6_pinfo`.] Assisted-by: Cursor:gemini-3.7-flash Signed-off-by: Florian Fainelli --- include/net/inet_connection_sock.h | 4 +- include/net/tcp.h | 4 +- net/ipv4/syncookies.c | 2 +- net/ipv4/tcp_fastopen.c | 2 +- net/ipv4/tcp_ipv4.c | 8 ++- net/ipv4/tcp_minisocks.c | 2 +- net/ipv6/tcp_ipv6.c | 97 +++++++++++++----------------- net/mptcp/subflow.c | 6 +- net/smc/af_smc.c | 6 +- 9 files changed, 66 insertions(+), 65 deletions(-) diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connecti= on_sock.h index bcc138ff087b..fe4f8261c443 100644 --- a/include/net/inet_connection_sock.h +++ b/include/net/inet_connection_sock.h @@ -42,7 +42,9 @@ struct inet_connection_sock_af_ops { struct request_sock *req, struct dst_entry *dst, struct request_sock *req_unhash, - bool *own_req); + bool *own_req, + void (*opt_child_init)(struct sock *newsk, + const struct sock *sk)); u16 net_header_len; u16 sockaddr_len; int (*setsockopt)(struct sock *sk, int level, int optname, diff --git a/include/net/tcp.h b/include/net/tcp.h index 1cc25e0b3bde..64c300659a8e 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -464,7 +464,9 @@ struct sock *tcp_v4_syn_recv_sock(const struct sock *sk= , struct sk_buff *skb, struct request_sock *req, struct dst_entry *dst, struct request_sock *req_unhash, - bool *own_req); + bool *own_req, + void (*opt_child_init)(struct sock *newsk, + const struct sock *sk)); int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb); int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len); int tcp_connect(struct sock *sk); diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index facf0fa7d659..66d5272c5abb 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -202,7 +202,7 @@ struct sock *tcp_get_cookie_sock(struct sock *sk, struc= t sk_buff *skb, bool own_req; =20 child =3D icsk->icsk_af_ops->syn_recv_sock(sk, skb, req, dst, - NULL, &own_req); + NULL, &own_req, NULL); if (child) { refcount_set(&req->rsk_refcnt, 1); sock_rps_save_rxhash(child, skb); diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c index 947109f01db6..5378ef3b6ab5 100644 --- a/net/ipv4/tcp_fastopen.c +++ b/net/ipv4/tcp_fastopen.c @@ -247,7 +247,7 @@ static struct sock *tcp_fastopen_create_child(struct so= ck *sk, bool own_req; =20 child =3D inet_csk(sk)->icsk_af_ops->syn_recv_sock(sk, skb, req, NULL, - NULL, &own_req); + NULL, &own_req, NULL); if (!child) return NULL; =20 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 40b73e97d5fb..2b7c580e3728 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1742,7 +1742,9 @@ struct sock *tcp_v4_syn_recv_sock(const struct sock *= sk, struct sk_buff *skb, struct request_sock *req, struct dst_entry *dst, struct request_sock *req_unhash, - bool *own_req) + bool *own_req, + void (*opt_child_init)(struct sock *newsk, + const struct sock *sk)) { struct inet_request_sock *ireq; bool found_dup_sk =3D false; @@ -1798,6 +1800,10 @@ struct sock *tcp_v4_syn_recv_sock(const struct sock = *sk, struct sk_buff *skb, } sk_setup_caps(newsk, dst); =20 +#if IS_ENABLED(CONFIG_IPV6) + if (opt_child_init) + opt_child_init(newsk, sk); +#endif tcp_ca_openreq_child(newsk, dst); =20 tcp_sync_mss(newsk, dst_mtu(dst)); diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index 7149ddb09840..f6657c571fb7 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -859,7 +859,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_b= uff *skb, * socket is created, wait for troubles. */ child =3D inet_csk(sk)->icsk_af_ops->syn_recv_sock(sk, skb, req, NULL, - req, &own_req); + req, &own_req, NULL); if (!child) goto listen_overflow; =20 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 085fc97c5a5b..84efaf846f07 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1341,11 +1341,48 @@ static void tcp_v6_restore_cb(struct sk_buff *skb) sizeof(struct inet6_skb_parm)); } =20 +/* Called from tcp_v4_syn_recv_sock() for v6_mapped children. */ +static void tcp_v6_mapped_child_init(struct sock *newsk, const struct sock= *sk) +{ + struct inet_sock *newinet =3D inet_sk(newsk); + struct ipv6_pinfo *newnp; + + newinet->pinet6 =3D newnp =3D tcp_inet6_sk(newsk); + + memcpy(newnp, tcp_inet6_sk(sk), sizeof(struct ipv6_pinfo)); + + newnp->saddr =3D newsk->sk_v6_rcv_saddr; + + inet_csk(newsk)->icsk_af_ops =3D &ipv6_mapped; + if (sk_is_mptcp(newsk)) + mptcpv6_handle_mapped(newsk, true); + newsk->sk_backlog_rcv =3D tcp_v4_do_rcv; +#if defined(CONFIG_TCP_MD5SIG) || defined(CONFIG_TCP_AO) + tcp_sk(newsk)->af_specific =3D &tcp_sock_ipv6_mapped_specific; +#endif + + newnp->ipv6_mc_list =3D NULL; + newnp->ipv6_ac_list =3D NULL; + newnp->ipv6_fl_list =3D NULL; + newnp->pktoptions =3D NULL; + newnp->opt =3D NULL; + + /* tcp_v4_syn_recv_sock() has initialized newinet->mc_{index,ttl} */ + newnp->mcast_oif =3D newinet->mc_index; + newnp->mcast_hops =3D newinet->mc_ttl; + + newnp->rcv_flowinfo =3D 0; + if (inet6_test_bit(REPFLOW, sk)) + newnp->flow_label =3D 0; +} + static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_= buff *skb, struct request_sock *req, struct dst_entry *dst, struct request_sock *req_unhash, - bool *own_req) + bool *own_req, + void (*opt_child_init)(struct sock *newsk, + const struct sock *sk)) { struct inet_request_sock *ireq; struct ipv6_pinfo *newnp; @@ -1361,60 +1398,10 @@ static struct sock *tcp_v6_syn_recv_sock(const stru= ct sock *sk, struct sk_buff * #endif struct flowi6 fl6; =20 - if (skb->protocol =3D=3D htons(ETH_P_IP)) { - /* - * v6 mapped - */ - - newsk =3D tcp_v4_syn_recv_sock(sk, skb, req, dst, - req_unhash, own_req); - - if (!newsk) - return NULL; - - inet_sk(newsk)->pinet6 =3D tcp_inet6_sk(newsk); - - newnp =3D tcp_inet6_sk(newsk); - newtp =3D tcp_sk(newsk); - - memcpy(newnp, np, sizeof(struct ipv6_pinfo)); - - newnp->saddr =3D newsk->sk_v6_rcv_saddr; - - inet_csk(newsk)->icsk_af_ops =3D &ipv6_mapped; - if (sk_is_mptcp(newsk)) - mptcpv6_handle_mapped(newsk, true); - newsk->sk_backlog_rcv =3D tcp_v4_do_rcv; -#if defined(CONFIG_TCP_MD5SIG) || defined(CONFIG_TCP_AO) - newtp->af_specific =3D &tcp_sock_ipv6_mapped_specific; -#endif - - newnp->ipv6_mc_list =3D NULL; - newnp->ipv6_ac_list =3D NULL; - newnp->ipv6_fl_list =3D NULL; - newnp->pktoptions =3D NULL; - newnp->opt =3D NULL; - newnp->mcast_oif =3D inet_iif(skb); - newnp->mcast_hops =3D ip_hdr(skb)->ttl; - newnp->rcv_flowinfo =3D 0; - if (inet6_test_bit(REPFLOW, sk)) - newnp->flow_label =3D 0; - - /* - * No need to charge this sock to the relevant IPv6 refcnt debug socks c= ount - * here, tcp_create_openreq_child now does this for us, see the comment = in - * that function for the gory details. -acme - */ - - /* It is tricky place. Until this moment IPv4 tcp - worked with IPv6 icsk.icsk_af_ops. - Sync it now. - */ - tcp_sync_mss(newsk, inet_csk(newsk)->icsk_pmtu_cookie); - - return newsk; - } - + if (skb->protocol =3D=3D htons(ETH_P_IP)) + return tcp_v4_syn_recv_sock(sk, skb, req, dst, + req_unhash, own_req, + tcp_v6_mapped_child_init); ireq =3D inet_rsk(req); =20 if (sk_acceptq_is_full(sk)) diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 26ea58691f79..4fc9a5a78876 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -812,7 +812,9 @@ static struct sock *subflow_syn_recv_sock(const struct = sock *sk, struct request_sock *req, struct dst_entry *dst, struct request_sock *req_unhash, - bool *own_req) + bool *own_req, + void (*opt_child_init)(struct sock *newsk, + const struct sock *sk)) { struct mptcp_subflow_context *listener =3D mptcp_subflow_ctx(sk); struct mptcp_subflow_request_sock *subflow_req; @@ -859,7 +861,7 @@ static struct sock *subflow_syn_recv_sock(const struct = sock *sk, =20 create_child: child =3D listener->icsk_af_ops->syn_recv_sock(sk, skb, req, dst, - req_unhash, own_req); + req_unhash, own_req, opt_child_init); =20 if (child && *own_req) { struct mptcp_subflow_context *ctx =3D mptcp_subflow_ctx(child); diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index 8e95839161aa..98b4449131d7 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -125,7 +125,9 @@ static struct sock *smc_tcp_syn_recv_sock(const struct = sock *sk, struct request_sock *req, struct dst_entry *dst, struct request_sock *req_unhash, - bool *own_req) + bool *own_req, + void (*opt_child_init)(struct sock *newsk, + const struct sock *sk)) { struct smc_sock *smc; struct sock *child; @@ -150,7 +152,7 @@ static struct sock *smc_tcp_syn_recv_sock(const struct = sock *sk, =20 /* passthrough to original syn recv sock fct */ child =3D smc->ori_af_ops->syn_recv_sock(sk, skb, req, dst, req_unhash, - own_req); + own_req, opt_child_init); /* child must not inherit smc or its ops */ if (child) { rcu_assign_sk_user_data(child, NULL); --=20 2.34.1