Article View: linux.kernel.netdev
Article #10142Re: [PATCH net] tcp: ipv6: do not read ireq->pktopts from tcp_v6_send_synack()
From: Eric Dumazet
Date: Tue, 03 Nov 2026 08:52
Date: Tue, 03 Nov 2026 08:52
181 lines
15678 bytes
15678 bytes
Le mar. 3 nov. 2026 à 09:46, <netdev-bot+sashiko@kernel.org> a écrit :
>
> Thank you for your contribution! Sashiko AI review found 2 potential
> issue(s) to consider.
>
> Critical: 0 · High: 1 · Medium: 0 · Low: 1
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
>
> - [High] The patch fixes only half of the migration use-after-free (UAF)
> it describes.
> - [Low] Leftover from this patch: tcp_v6_init_req()
> (net/ipv6/tcp_ipv6.c:799-806) still keeps a reference to the SYN skb…
>
> --
>
> tcp: ipv6: do not read ireq->pktopts from tcp_v6_send_synack()
>
> This commit adds a syn_flowlabel field to tcp_request_sock. The field is
> filled from the SYN in tcp_v6_init_req(), and tcp_v6_send_synack() now
> uses it instead of reading ireq->pktopts. The old read could hit a freed
> skb when another cpu completed the 3WHS or migrated the request socket.
>
> Closes: https://lore.kernel.org/netdev/82c31e4d5043f3dbd11b44177cfba779d335aae3.1793599929.git.x-professor@outlook.com/
>
> > diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
> > index e006a30360eae..d406cd3c8ceab 100644
> > --- a/net/ipv6/tcp_ipv6.c
> > +++ b/net/ipv6/tcp_ipv6.c
> > @@ -578,8 +578,8 @@ static int tcp_v6_send_synack(const struct sock *sk, struct dst_entry *dst,
> > &ireq->ir_v6_rmt_addr);
> >
> > fl6->daddr = ireq->ir_v6_rmt_addr;
> > - if (inet6_test_bit(REPFLOW, sk) && ireq->pktopts)
> > - fl6->flowlabel = ip6_flowlabel(ipv6_hdr(ireq->pktopts));
> > + if (inet6_test_bit(REPFLOW, sk))
> > + fl6->flowlabel = tcp_rsk(req)->syn_flowlabel;
>
> [Severity: High]
> This removes the pktopts read. Does the migration race described in the
> commit message still apply to ireq->ipv6_opt, a few lines further down in
> the same function?
>
> net/ipv6/tcp_ipv6.c:tcp_v6_send_synack() {
> ...
> rcu_read_lock();
> opt = ireq->ipv6_opt;
> if (!opt)
> opt = rcu_dereference(np->opt);
> err = ip6_xmit(sk, skb, fl6, skb->mark ? : READ_ONCE(sk->sk_mark),
> opt, tclass, READ_ONCE(sk->sk_priority));
> ...
> }
>
> reqsk_migrate_reset() hands ipv6_opt over to the clone along with pktopts:
>
> net/ipv4/inet_connection_sock.c:reqsk_migrate_reset() {
> req->saved_syn = NULL;
> #if IS_ENABLED(CONFIG_IPV6)
> inet_rsk(req)->ipv6_opt = NULL;
> inet_rsk(req)->pktopts = NULL;
> ...
> }
>
> inet_reqsk_clone() memcpy()s the request socket. Until the reset runs, nreq
> and oreq both point at the same ipv6_txoptions. After the reset, nreq owns
> it. When nreq is freed, the destructor releases it without waiting for an
> RCU grace period:
>
> net/ipv6/tcp_ipv6.c:tcp_v6_reqsk_destructor() {
> kfree(inet_rsk(req)->ipv6_opt);
> consume_skb(inet_rsk(req)->pktopts);
> }
>
> So the rcu_read_lock() in tcp_v6_send_synack() does not protect opt. IPv4
> does this differently: tcp_v4_reqsk_destructor() frees ireq_opt with
> kfree_rcu().
>
> Could this sequence happen?
>
> CPU0 (holds a reference on oreq)
> tcp_v6_rcv()->tcp_check_req()->tcp_rtx_synack()->tcp_v6_send_synack()
> opt = ireq->ipv6_opt; /* still non-NULL */
>
> CPU1
> inet_csk_complete_hashdance() or reqsk_timer_handler()
> reqsk_migrate_reset(oreq);
> ...
> nreq is freed, on accept() of the child or after an RST leads to
> inet_csk_reqsk_queue_drop() and the last reqsk_put():
> tcp_v6_reqsk_destructor()
> kfree(inet_rsk(req)->ipv6_opt);
>
> CPU0
> ip6_xmit(..., opt, ...)
> /* reads opt->opt_nflen/opt_flen, pushes opt->hopopt etc. */
>
> Only calipso_req_setattr() sets ireq->ipv6_opt. It is reached through
> security_inet_conn_request()->netlbl_req_setattr() when a CALIPSO NetLabel
> mapping is configured. The race also needs:
>
> - SO_REUSEPORT listeners with request migration enabled
> (net.ipv4.tcp_migrate_req or a BPF sk_reuseport migrate program)
> - a listener being closed
>
> The patch carries Fixes: c905dee62232, and the commit message names
> reqsk_migrate_reset() as one of the causes. Should ipv6_opt be handled
> here too?
This is a different issue, which exists independently of this patch.
It is CALIPSO-only (ipv6_opt is only set by calipso_req_setattr()),
and was mentioned in the changelog of e3f33b0a1d89 ("ipv4: free
inet_opt and ireq_opt after an RCU grace period").
Both readers (tcp_v6_send_synack() and tcp_v6_syn_recv_sock()) already
run under RCU,
so freeing ipv6_opt with kfree_rcu() in tcp_v6_reqsk_destructor() is enough.
I will send a separate patch.
>
> [ ... ]
>
> > @@ -789,6 +789,7 @@ static void tcp_v6_init_req(struct request_sock *req,
> > ireq->ir_v6_loc_addr = ipv6_hdr(skb)->daddr;
> > ireq->ir_rmt_addr = LOOPBACK4_IPV6;
> > ireq->ir_loc_addr = LOOPBACK4_IPV6;
> > + tcp_rsk(req)->syn_flowlabel = ip6_flowlabel(ipv6_hdr(skb));
> >
> > /* So that link locals have meaning */
> > if ((!sk_listener->sk_bound_dev_if || l3_slave) &&
>
> [Severity: Low]
> This isn't a bug, but now that the flowlabel comes from syn_flowlabel, is
> the REPFLOW term still needed in the pktopts condition further down in
> tcp_v6_init_req()?
>
> if (!tw_isn &&
> (ipv6_opt_accepted(sk_listener, skb, &TCP_SKB_CB(skb)->header.h6) ||
> np->rxopt.bits.rxinfo ||
> np->rxopt.bits.rxoinfo || np->rxopt.bits.rxhlim ||
> np->rxopt.bits.rxohlim || inet6_test_bit(REPFLOW, sk_listener))) {
> refcount_inc(&skb->users);
> ireq->pktopts = skb;
> }
>
> On a REPFLOW listener with no rxopt bits set, every request socket still
> holds a reference to its SYN skb. cookie_v6_check() uses the same condition
> without the REPFLOW term, so the two places now differ.
>
> One reader is left: IPV6_2292PKTOPTIONS in do_ipv6_getsockopt(), through
> np->pktoptions on the child. It only produces cmsgs if rxopt bits are set
> on the child after accept(). Dropping the term would change behaviour
> slightly in that case.
>
> Could a follow-up remove the term so that tcp_v6_init_req() matches
> cookie_v6_check()?
Yes, I already mentioned this. I have a net-next patch for this.
Technical Details
Message-ID:
<CAL4WiiqU1bT+83m+fkJEftQE9iv+AgcBbFFMsGhw+s3qD-jDEw@mail.gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355299-linux-kernel-netdev=dewy.ruReferences:
<20261102075441.3771550-1-edumazet@kernel.org> <179369559062.488856.15441115725436277776@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355299-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] tcp: ipv6: do not read ireq->pktopts from tcp_v6_send_synack()
Date: Tue, 3 Nov 2026 09:52:10 +0100
Organization: Usenet Network
Message-ID: <CAL4WiiqU1bT+83m+fkJEftQE9iv+AgcBbFFMsGhw+s3qD-jDEw@mail.gmail.com>
References: <20261102075441.3771550-1-edumazet@kernel.org> <179369559062.488856.15441115725436277776@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="3130336"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:srmIhc6pXK5AhHjosL+fEtDdRA4= sha256:zNvztw4OnRgoCziUJq3l1aNiFwfQqAJI8gW5vd2BjDA=
sha1:s1m+nQOUkLEoEOR5V5QkwjDEGHQ= sha256:HSyDfdJQOzKw5rOYxfLfNPYgvvtU6IzOwvUIEsMJ/Xs=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 44B6211278E; Tue, 3 Nov 2026 12:20:15 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id dOyhY6vCMkEL;
Tue, 3 Nov 2026 12:20:12 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-355299-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
by mail.dewy.ru (Postfix) with ESMTPS id 834EC11275E; Tue, 3 Nov 2026 12:20:02 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sin.lore.kernel.org (Postfix) with ESMTP id 80C9A2AB60; Tue, 3 Nov 2026 08:52:24 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1793695943;
b=C/LagYP01BPH4VPX7JVuGTUd17MKGmgsQu9feAwmioLWGtD+pGufWcSh7mMQAi+uY9/t
2olqOj7U9OOU+dP+US2VCqRkQXq52HjeSw7dYq9FNZP940e8zyA7iNE/zWgOaGItoEf8B
/XYbgbcPR5kWuN8jY8yVPoTFXB4PQW/pq8k+HPoE7rDN4+e6up2ED9cFsftPQF4IjZojY
x2UFfjxJkgdCf/dAHjYLVFOTz1XIIqVivGJbMotRnQzKL+v8NK1L+Z6ojaHnddZbrOeIx
eCo53gNkIH5HFKaZfVs6zuWxY6CpJiKb3prTdAKiugpZMoXki7/H6yFt6cb/fFsVUQw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793695943;
h=X-Original-To:Received:Received:DKIM-Signature:Received:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:X-Mailing-List:
List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
List-Owner:Precedence:MIME-Version:References:In-Reply-To:From:Date:
X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=TdSJawfHJlt2CEvQuG6uB67CcZ37ivbLLLF//zSQtxs=;
b=mY7k2+RVcuxP1LzvQl4/gj4scOFOpdN7TVAR0xaXds977kvqeHGL2cSaj7o1TpLj5AJc
tCgpzh1Ie/OfeAOeT60cbX7ysLiBxzkbj+yg24B9sXw1v6uoaaRknkkVhO/0PQJTRDrZ7
zljfATL7MuXyPo6kJba5HbOQXXM50XHQql0qg64npyrtHH/0zISuzH26L0irXt+FWeYkE
uy0jkPzwixB+0IenNtOoP4mgv+hvel+w3b/zWgXAX5wk4ugazouoMzgP4q6AIdqYqizBB
mj9/f84x4PlsgyDpEwkF4HyzRvk86fs+DZ2f0Gk0QmgXXu6FiiufQbG68N9I/BZWDFg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Mxx7cF4s;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 92645606A330;
Tue, 3 Nov 2026 08:52:23 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Mxx7cF4s
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793695942;
b=ypQ2z3/4hdH9l7NKOp6xR8Y560EVXIbKoqOYHfjR9MWH9hqElhmhRgiy+NqIE8y++qFt
CYFDEDXFmUs8g9piWti98iP7GtJyw7pwD8pJwHYlyf4Do3j3hovaJZ47L4D01A3teQu+f
B3UbZGiSDidHxi7VxX4sS/dbQ+I2678IQfm1tbwjf95JPwKwBWCYGm0yZv8oexY0dZ4E5
EjIhwvWoCR+86AlZBlRaSAQcp7pZQ+ApqAEtcZgs+fRzU4D1MpvAUVVDpa1mBcMjC66Sy
zu9sX6kzxwTu8Qy7xvk3aqECZTV4ZB274Hpbghd3GNHQZKCWzXkAR36Ey/r2wp+RI9A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793695942;
h=Received:DKIM-Signature:Received:X-Forwarded-Encrypted:
X-Gm-Message-State:X-Received:MIME-Version:References:In-Reply-To:
From:Date:X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:
Subject:To:Cc:Content-Type:Content-Transfer-Encoding;
bh=TdSJawfHJlt2CEvQuG6uB67CcZ37ivbLLLF//zSQtxs=;
b=hDjhs4Z+CztKXAz7n/9v8C5vq6QS1cNVyXcheWfC+uvvBZrzYrHZmZOHnZNezctSi1MA
LHY9WaOubGAvdac96jSs0sn9otKy5J1JTndubN/9sxaeUKGraAj+WUs+ALe5yYhxSOEYc
tue0AwGiz8kyrqSN3m0fVQGnvFMcPDz5KV1GnFH579HazpmYtlDilaZOBu6JxE9GPN3/V
O2xXZU0pCxdq1QlcI+eAgHh0vm/+EX7dK8iJ1loBd4jWn9/359U1UfUk1oIa7bDe5HvAO
knpVaSSYPVImrToYucDsoxcl8VYjtdoDazvgbpFhDubiNkBwK+m6SGYmhMcaDPdYzrA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Mxx7cF4s;
arc=none smtp.remote-ip=100.103.45.18
X-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 6F729606A326
for <netdev@vger.kernel.org>; Tue, 3 Nov 2026 08:52:22 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4904F1F00A15
for <netdev@vger.kernel.org>; Tue, 3 Nov 2026 08:52:22 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
s=k20260515; t=1793695942;
bh=TdSJawfHJlt2CEvQuG6uB67CcZ37ivbLLLF//zSQtxs=;
h=References:In-Reply-To:From:Date:Subject:To:Cc;
b=Mxx7cF4sE3b5qXRX6s3hkMclpAWK0FGdd8M46TDcj8qZtN3XeFNK+xNWs8zyTwGxD
biQINWud5AzOz9SYdqinS8cpnbl8V0P7PQmcHeaznOflhzylFM3jn0INcRpHcvuzKS
4TjMpMbGKFp45I+xN86MPFHT2VrtEC5PEADCYmtAEDLDt8VEL78q0qJoMaeeRe0jQE
2kN/75FdxPEcaSZ1gHH0ZWV1kz309DZjlx/wDb7u8LILkcQxKzb1/Qsqj3h7Le4zDe
glbAIMURuHJt39T3yhLG+XJgbarJFeiYGBkyj9X7e0d9DmVi3uJyv4blM9f21H1aSq
BTxTK6zvKrLUg==
X-Received: by mail-oa1-f47.google.com with SMTP id 586e51a60fabf-4932b13c4ccso2539699fac.3
for <netdev@vger.kernel.org>; Tue, 03 Nov 2026 00:52:22 -0800 (PST)
X-Forwarded-Encrypted: i=1; AKwUvByBJVqyDjmHypU4IrZT9GgxqrdVMg+20R6woXKEhbd/ZVt/R3A0ZgnYjLryFi3aFYaOKby5Ews=@vger.kernel.org
X-Gm-Message-State: APuU4Z89GXSPjDbAMqDIY0e3i3tBYNhxMOlr3k3IT1lpv6ycZII9w6Z+
/q3vKlLMvKeh8HXvg3UL6WK6GrKrPw7N48i/SR9o0npjzYWFoWRbslZciFcelLNfMkDbgavhO3h
j+GynIlzJsKhYoJX1leyIsyKwKukQX7c=
X-Received: by 2002:a05:6871:4410:b0:494:73e0:eeb9 with SMTP id
586e51a60fabf-4a907744ae4mr8244206fac.47.1793695941578; Tue, 03 Nov 2026
00:52:21 -0800 (PST)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <179369559062.488856.15441115725436277776@kernel.org>
X-Gmail-Original-Message-ID: <CAL4WiiqU1bT+83m+fkJEftQE9iv+AgcBbFFMsGhw+s3qD-jDEw@mail.gmail.com>
X-Gm-Features: AclHuK_kWzjzr69EGKyEj_0N1KGhlKfklKatO3J29aWnxfwgG_MaiUZSuN-pe-c
X-Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
ncardwell@google.com, kuniyu@google.com, horms@kernel.org,
netdev@vger.kernel.org, permissiontogallop@gmail.com, x-professor@outlook.com