Article View: linux.kernel.netdev
Article #25368Re: [PATCH net v3] net: avoid clobbering active cork flowi union on datagram connect
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 16:50
Date: Tue, 01 Dec 2026 16:50
252 lines
17042 bytes
17042 bytes
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 3
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).
- [Medium] In udp_cork_restore_connected() (include/net/udp.h), the IPv6
branch rebuilds inet->cork.fl.u.ip6 with ip6_datagram_flow_key_init()…
- [Low] The new condition in l2tp_xmit_core() (net/l2tp/l2tp_core.c)
drops every L2TP session data packet (kfree_skb + NET_XMIT_DROP)…
- [Low] On the connected cached-route path, udp_sendmsg()
(net/ipv4/udp.c) now builds the lockless fl4_stack from live socket…
- [Low] The patch changes routing-cache behaviour in ways the commit
message does not mention.
--
net: avoid clobbering active cork flowi union on datagram connect
When corked frames are queued, datagram connect now uses stack flow keys
so it no longer overwrites the shared inet->cork.fl union. The patch also
restores the connected IPv4 or IPv6 flow when a UDP cork finishes, and
builds the lockless cached-route UDP send flow from socket fields. L2TP
transmit is skipped while the tunnel socket has corked frames.
> diff --git a/include/net/udp.h b/include/net/udp.h
> index 5bc25dcf25fba..921d2a32431b8 100644
> --- a/include/net/udp.h
> +++ b/include/net/udp.h
[ ... ]
> @@ -417,6 +418,36 @@ INDIRECT_CALLABLE_DECLARE(int udp_recvmsg(struct sock *sk, struct msghdr *msg,
> size_t len, int flags));
> void udp_splice_eof(struct socket *sock);
> int udp_push_pending_frames(struct sock *sk);
> +static inline void udp_cork_restore_connected(struct sock *sk)
> +{
> + struct inet_sock *inet = inet_sk(sk);
> + struct flowi4 *fl4 = &inet->cork.fl.u.ip4;
> +
> + if (sk->sk_state != TCP_ESTABLISHED)
> + return;
> +
> +#if IS_ENABLED(CONFIG_IPV6)
> + if (sk->sk_family == AF_INET6 &&
> + !ipv6_addr_v4mapped(&sk->sk_v6_daddr)) {
> + struct ipv6_pinfo *np = inet6_sk(sk);
> + struct flowi6 *fl6 = &inet->cork.fl.u.ip6;
> +
> + ip6_datagram_flow_key_init(fl6, sk);
> + rcu_read_lock();
> + fl6_update_dst(fl6, rcu_dereference(np->opt), &np->final);
[Severity: Medium]
Can this leave inet->cork.fl.u.ip6.daddr set to the first routing header
hop instead of the connected peer?
If np->opt has a sticky routing header (set with IPV6_RTHDR),
fl6_update_dst() replaces fl6->daddr with the first segment and returns
&np->final. Here the return value is ignored, and nothing puts
sk->sk_v6_daddr back afterwards.
Other code that builds this flow restores the final destination after the
lookup:
net/ipv6/ip6_output.c:ip6_dst_lookup_flow() {
...
if (final_dst)
fl6->daddr = *final_dst;
...
}
inet6_csk_xmit() does the same with "fl6->daddr = sk->sk_v6_daddr" when it
has to reroute.
This path only resets the cached dst when SNDFLOW is set with a flow
label. For an L2TPv6 tunnel on a natively IPv6-connected UDP socket, the
next transmit after a cork completes would go:
l2tp_xmit_core()
l2tp_xmit_queue()
inet6_csk_xmit()
__sk_dst_check() succeeds, so daddr is not restored
ip6_xmit(sk, skb, fl6, ...)
ip6_xmit() treats fl6->daddr as the final destination. That means
ipv6_push_rthdr0() or ipv6_push_rthdr4() writes the first hop as the last
segment, and the real peer address never makes it into the packet.
Before this patch, the flow left behind after a cork or a connect had been
through ip6_dst_lookup_flow(), which restored daddr.
Should the helper set fl6->daddr = sk->sk_v6_daddr again after
fl6_update_dst()?
> + rcu_read_unlock();
> + if (inet6_test_bit(SNDFLOW, sk) &&
> + (fl6->flowlabel & IPV6_FLOWLABEL_MASK))
> + sk_dst_reset(sk);
[Severity: Low]
This isn't a bug, but the patch changes routing cache behaviour in ways
the commit message doesn't mention.
udp_cork_restore_connected() runs on every cork completion on a
TCP_ESTABLISHED socket. That covers push, flush, and the corkreq with an
empty queue branch in both udp_sendmsg() and udpv6_sendmsg(). It runs even
when no connect happened while the socket was corked.
On natively IPv6-connected sockets this re-runs
ip6_datagram_flow_key_init(), including security_sk_classify_flow(), and
fl6_update_dst() each time. With IPV6_FLOWINFO_SEND and a flow label, it
also drops the cached dst on every completion, so the next send has to do
a fresh route lookup.
The corked connect helpers also throw away the dst that connect just
installed, for every non-UDP datagram socket (raw, ping, l2tp_ip,
l2tp_ip6):
net/ipv4/datagram.c:__ip4_datagram_connect_corked() {
...
err = ____ip4_datagram_connect(sk, uaddr, addr_len, &fl4);
if (!err && !sk_is_udp(sk))
sk_dst_reset(sk);
...
}
ip6_datagram_dst_update_corked() does the same thing.
Could the restore run only when a connect actually happened during the
cork? Could the commit message also describe these dst resets?
> + return;
> + }
> +#endif
[ ... ]
> diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
> index d784faf939c3b..09f1fd412c816 100644
> --- a/net/ipv4/udp.c
> +++ b/net/ipv4/udp.c
[ ... ]
> @@ -1459,6 +1461,14 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
> goto out;
> if (connected)
> sk_dst_set(sk, dst_clone(&rt->dst));
> + } else {
> + fl4 = &fl4_stack;
> + flowi4_init_output(fl4, ipc.oif, ipc.sockc.mark,
> + ipc.tos & INET_DSCP_MASK, scope,
> + IPPROTO_UDP, inet_sk_flowi_flags(sk),
> + faddr, saddr ? : READ_ONCE(inet->inet_saddr),
> + dport, READ_ONCE(inet->inet_sport),
> + sk_uid(sk));
> }
[Severity: Low]
Could this lockless path now send a datagram with source port 0, or with
a 0.0.0.0 source or destination, if connect(AF_UNSPEC) runs at the same
time?
The non-corked sender does not take lock_sock(), and __udp_disconnect()
clears the address fields before it drops the cached route:
net/ipv4/udp.c:__udp_disconnect() {
sk->sk_state = TCP_CLOSE;
WRITE_ONCE(inet->inet_daddr, 0);
...
inet_reset_saddr(sk);
...
inet->inet_sport = 0;
...
sk_dst_reset(sk);
}
Suppose the sender sees TCP_ESTABLISHED and gets a valid rt from
sk_dst_check() before sk_dst_reset() runs, but reads inet_daddr,
inet_saddr or inet_sport after they were cleared. The flow built here then
contains zeros. No route lookup runs to repair it, and this later line
copies the zero:
if (!ipc.addr)
daddr = ipc.addr = fl4->daddr;
The packet then goes out through the old peer's dst.
Before this patch, the cached path used the connect-time
inet->cork.fl.u.ip4, which disconnect doesn't clear. The packet could be
stale, but it was well formed. The uncached branch already read
inet->inet_sport locklessly, so a sport 0 form of this race existed
before. This change extends the window to the cached path.
Separately, the writers in ____ip4_datagram_connect() and
__udp_disconnect() use plain stores for inet_saddr and inet_sport, while
the new readers use READ_ONCE(). The annotations don't pair up.
[ ... ]
> diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c
> index 0cd3e38bf662f..af94c5056f149 100644
> --- a/net/l2tp/l2tp_core.c
> +++ b/net/l2tp/l2tp_core.c
> @@ -1273,7 +1273,8 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, uns
> */
> spin_lock_nested(&sk->sk_lock.slock, L2TP_DEPTH_NESTING);
>
> - if (sock_owned_by_user(sk)) {
> + if (sock_owned_by_user(sk) ||
> + unlikely(!skb_queue_empty(&sk->sk_write_queue))) {
> kfree_skb(skb);
> ret = NET_XMIT_DROP;
> goto out_unlock;
[Severity: Low]
Is it intended that l2tp_xmit_core() drops every session data packet for
as long as userspace keeps the tunnel socket corked?
Before this patch, transmit was dropped only while sock_owned_by_user(),
which is a short syscall window. Frames queued under lock_sock() are
already covered by that check. So the new test only matters when a cork
is held across syscalls: UDP_CORK, or MSG_MORE on the UDP or l2tp_ip6
tunnel socket.
A cork like that can be held indefinitely. Meanwhile every session on the
tunnel loses its data traffic, even when the corked data is for the
connected peer, which used to transmit correctly.
The commit message only says "skip L2TP transmit while frames are
corked". It doesn't mention that pseudowire/PPP data is discarded for as
long as userspace keeps the cork.
For IPv4, l2tp_xmit_queue() already passes a flow to ip_queue_xmit():
err = ip_queue_xmit(tunnel->sock, skb, fl);
Could a private flow built from socket fields, like the one now used in
udp_sendmsg(), avoid both reading and clobbering the cork without dropping
traffic? inet6_csk_xmit() ignores its fl argument, so IPv6 would need a
different approach.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130160427.2653731-1-dmnk%40google.com
Technical Details
Message-ID:
<179614383945.3146.14922794471906658590@kernel.org>Path:
mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375217-linux-kernel-netdev=dewy.ruReferences:
<20261130160427.2653731-1-dmnk@google.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375217-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v3] net: avoid clobbering active cork flowi union on datagram connect Date: Tue, 01 Dec 2026 16:50:39 +0000 Organization: Usenet Network Message-ID: <179614383945.3146.14922794471906658590@kernel.org> References: <20261130160427.2653731-1-dmnk@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1769898"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:tcMNB2cG4eKmyQ/Tkq0uCciMCmc= sha256:r4akrFCUdiyAqFiFR+cPZsEWiWpxk94eJZGBuXW6Nso= sha1:i00Q4maexfV8kC17NLMuBMwnEDM= sha256:tFNr8H4gcPwCbZStAZE5I0/iq9B9O8Cphh6iB1eKLLs= 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 530EA11741E; Tue, 1 Dec 2026 19:50:59 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.5 X-Spam-Status: No, score=-3.5 tagged_above=-9999 required=6.31 tests=[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, URIBL_BLOCKED=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 dZClqN_ID8t0; Tue, 1 Dec 2026 19:50:55 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-375217-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 0707C117419; Tue, 1 Dec 2026 19:50:46 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id BCA69602792; Tue, 1 Dec 2026 16:50:45 +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=1796143842; b=1XKvjm0e0Vz/aZVWFlI0cXh3yinPD0tLVyRpgRKbEXPIFkYvviaWJwkCeePaIcECnC2X qfUoSuK4jVNnx6aWuSmTnKzltvFopBcoqA1vJAgjMAC+ny6TJ6Ko/4L4SbOkPocXwwhY6 GYVmoZBOfJiUwbGXIfKWjql9g032oRVO76ScA/+pecDGJj0gMrmSF7JvD1aD5XC6LSXWN gUm6a/v2cNSF5nFRBIJndKowyQXHNoTmT7U9fHKoTUv3vF3gLqSoXpxlseRIfRKdIXJlt hcSEs8O+Mh4MFdqVgxfeDHEM2ZTwl+aWG1g52A8OvNOdyzNynFhA9hIyxoCjIu2SMhQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796143842; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=nHPhdQJP4fnvglkdUYJqzBLChPlJhVwJ7UPfm7Lj86c=; b=rdLwJLiw7fXDXGNEhgSjbjv6ywo/lCUtCsqGhcmGttuRYShKveLLYBxLuULj1GrVqAlR 2eg2IC9NtambcRnJjugU8t7BM4swi8wQnujeLp+pNGptkZfVHAQbwsB1dJYKqodez1mrg 5hPE1b7sXnExE66epx/AizOQCEsoYUW95D8lEY4lxNLLCRZcRFl00KsNQBjtbcvkdnTkv hhSWgkLS645lB1NG84rzfmISNjZgX01BtEKMLhj89Fh7ZC+OA66hpDmabAz+u89H43dEb 1+YOFV+EMgPirmkzY++iw0ET72I/Uq1tpjsccouGEgjXE3ZF/yCmrAFbUyQAnrknHiA== 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=NcDagjC2; 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 68546606A32C; Tue, 1 Dec 2026 16:50:42 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NcDagjC2 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=1796143841; b=mnY7KOZ8NLj8fO9zmOIQ4XZmybrMrAPnODdqrzU01nqRnEqBlvCHy5l0Jf3HnfgrLDUv xoUcsO50nEF/RzcE6KV92PlL9mbrD1qJplUYHV0VZRc71ea2j0BslPinXH7XHF66ER4Mo EstWvePVe5dQ7ulLI9U5kU92isw8LT9Ec9b8uMylIVuyq+gxZDk1RP5FR68Ux2Az68bx1 vM0ZkejO0bP6gWuE9BQEnMWriNE1esqp4uO2d8EP/ehllnKcGvpApVByLi4IzPeOY+cFy 1joT8EGdwM8arrJKr3u7fcxFS4kTI8rUBaq3fw7UYapiz5u5lgC1rfCiyoyqtUExi2g== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796143841; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=nHPhdQJP4fnvglkdUYJqzBLChPlJhVwJ7UPfm7Lj86c=; b=mo8TC6/GuBb23OKSDRio94hXLlyixEhjlngQX7X+IuzuEghJSSeP5IiNr3gqk8cMgX3B NfFgEtzlq/CzVJjfZJT95RxWeriIsJaLLxgEJtE3TQZQVbYDaFIaBG/gh6RkQJvRMqEOE t8ZJo3+puOwWMB2KroJUuHAuePFpDpJwW//jSuWeo72d+WP+dLN/IehlVgxRgE8wfUvoe IVC9mqNz4PNuwTHB9aIq41FHqvfy1OSQKB5pDUQKfX5pNmJJ3x3qRkfLKd/C1vbQQJeUu 9jCOkI6vfOYn4hdlf7tLvBAFSAO6EKGERhpiFWqlFIyRGBponVQIXQongTTNZ0D9EyQ== 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=NcDagjC2; 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 847EC606A31A for <netdev@vger.kernel.org>; Tue, 1 Dec 2026 16:50:41 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC31C1F00898; Tue, 1 Dec 2026 16:50:39 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796143840; bh=nHPhdQJP4fnvglkdUYJqzBLChPlJhVwJ7UPfm7Lj86c=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=NcDagjC2P/ng7V4urW/YQ/lRYYLfJVfuP3i6dxNJCIBquAEzP1sMDTYh3GJr8fYfq rPfBShSZpKHhXcWwnM723CDc/lXrqpYva5tfNBB+Pgo5PFIQNNIXR20GjnoczfobDz LbXNWub3ZtklcwwkhmQ+yVMJ9+uIOy5q3y3vwSryQRlz4kwEZ/j9sr+pyF6ZWwXEMU JhFC9QqdGpDZye7D1yRklZeMHiu4F4AAXAcsq6iVPfnKrNwHsjv/8HOwsEXb5yzSfm 1u0+4MDV/jRafrIv/Wa2oU9GM5ZdecKfXTDuDMVnbV+3w1MKmyMJpDO6eQukvgAOFt HPUnmuLiHM3Kw== X-Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, dsahern@kernel.org, idosch@nvidia.com, horms@kernel.org, willemdebruijn.kernel@gmail.com, kuniyu@google.com, jchapman@katalix.com, tparkin@katalix.com, netdev@vger.kernel.org, dmnk+artist@google.com X-In-Reply-To: <20261130160427.2653731-1-dmnk@google.com> X-sashiko-severity: Medium 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