From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385105; b=yrLiGXDD64iGoMX9Q0cmOECHxUFE+UMzDX6iAlH83tym0CtZe9LtiBgGoNWd+O5nU+XD Fr8W8Fi7zARLNmCQHgLXQdA2hoKjRPyl7s6Q05nC6F0zwWDJnZZ5YK3EifwUSZXNU+63d F4oAcnUJhhfL2uF5JYyUSCxdDZhuvG0hfL3gHqmKZ8jwdc28GJWHf6oBz6yHshSPyX+6K RRSiPCmMm8hBHo8kvl0fwsalNi99+DiHjT5/34EwzorgCThqVov7mUA/BGPfd9DLE0RWF ak68ylBbuFcTAZ76z6pUAPqbuqeAOMt5T/QZpwyurxyVu+QXoPncVLZXyVxjojXDZ9w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385105; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=1jYrhec5rKynjrboYEQ/EvdtO+gmQc0mJL5DyP/MZi4=; b=cvlic819f2bHnqG+ASbefqRM9UB4cRwTIrBhKfXeyFRsTYVfdxQIcN+0H8XSRYVU+kS1 JIyCJm/lY4RFPfO91hazNPjnIIqSlW4M9f78Yz1Lj+7ywRQR2ymJlaNUOLxGHJEzz8TG1 XmpLWwfBIGJ9DvurRlgdmS57hFkps1nERzZ678ir2CphyVzZCaBEz7Iqg3b3faU1TBtdl odNtDLoRcIsX5UXu7o4ol9wYxdvf1lahk3lo3ejjCzwfJEhI9Y5VOLs/bkxm0NifVjiSb Jvo8W70FAmyZKJ1qcBVAd9zGce8n1EVSiAqZIimK1uxrIzv4JG7Blh7J9SBVAC64G8Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=yM2wm8Rq; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E26F6606A32C; Fri, 4 Dec 2026 11:51:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=yM2wm8Rq Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4466F1F000CE; Fri, 4 Dec 2026 11:51:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385104; bh=1jYrhec5rKynjrboYEQ/EvdtO+gmQc0mJL5DyP/MZi4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=yM2wm8RqA8dyyssag7eDJvIpPDqtyhHvPlXXUdo0rP7Ev4ecWQDvoccZ9pomFUdVG OSmFbBls/hblONnruijV4svDRVRQ6tjiD97PuIID38C3XqQH3zZzxp2ap9xBVxtqap E57cB6GRXV0wIFRDfKedF12GaLoPg/JOB+pjHbYA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Eric Dumazet , Kuniyuki Iwashima , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6 0421/1167] tcp: use the echoed source route in cookie_v4_check() Date: Fri, 4 Dec 2026 18:57:28 +0900 Message-ID: <20261204100712.986988909@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 54d574d4afd9de820c8a017665c8095f0f5fdbaa ] When the ACK carries a source route option, cookie_v4_check() routes the new socket to opt->faddr, where opt points to the options of the received packet. ip_options_compile() only fills faddr for options given by setsockopt() (when called without an skb), so on receive faddr is 0 and the lookup is done for daddr 0, which gives a local route. Use the options echoed by tcp_v4_save_options() instead, as inet_csk_route_req() and inet_csk_route_child_sock() do with ireq->ireq_opt. Read them after security_inet_conn_request(), since CIPSO can replace ireq->ireq_opt there. The route now goes to the first hop of the source route, so also refuse a strict source route through a gateway, as inet_csk_route_req() does. Found by sashiko while reviewing the sk_mc_loop() fix. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20261012101029.927296-3-edumazet@kernel.org Signed-off-by: Jakub Kicinski [ sashal: adapted cookie_v4_check() context to the older single-function layout, using reqsk_free(req); goto out; for the new strict-route error path instead of SKB_DR_SET/out_free. ] Signed-off-by: Sasha Levin --- net/ipv4/syncookies.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index 3140c7742b30f..ae79dd47f0fde 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -320,13 +320,13 @@ EXPORT_SYMBOL_GPL(cookie_tcp_reqsk_alloc); */ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) { - struct ip_options *opt = &TCP_SKB_CB(skb)->header.h4.opt; struct tcp_options_received tcp_opt; struct inet_request_sock *ireq; struct tcp_request_sock *treq; struct tcp_sock *tp = tcp_sk(sk); const struct tcphdr *th = tcp_hdr(skb); __u32 cookie = ntohl(th->ack_seq) - 1; + struct ip_options_rcu *opt; struct sock *ret = sk; struct request_sock *req; int full_space, mss; @@ -409,6 +409,8 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) reqsk_free(req); goto out; } + /* Load ireq->ireq_opt after the LSM hook, which can replace it. */ + opt = rcu_dereference_protected(ireq->ireq_opt, true); req->num_retrans = 0; @@ -421,7 +423,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) flowi4_init_output(&fl4, ireq->ir_iif, ireq->ir_mark, ip_sock_rt_tos(sk), ip_sock_rt_scope(sk), IPPROTO_TCP, inet_sk_flowi_flags(sk), - opt->srr ? opt->faddr : ireq->ir_rmt_addr, + (opt && opt->opt.srr) ? opt->opt.faddr : ireq->ir_rmt_addr, ireq->ir_loc_addr, th->source, th->dest, sk->sk_uid); security_req_classify_flow(req, flowi4_to_flowi_common(&fl4)); rt = ip_route_output_key(sock_net(sk), &fl4); @@ -429,6 +431,12 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) reqsk_free(req); goto out; } + /* Same check as in inet_csk_route_req(). */ + if (opt && opt->opt.is_strictroute && rt->rt_uses_gateway) { + ip_rt_put(rt); + reqsk_free(req); + goto out; + } /* Try to redo what tcp_v4_send_synack did. */ req->rsk_window_clamp = READ_ONCE(tp->window_clamp) ? : -- 2.53.0