From: netdev-bot+sashiko@kernel.org
To: dmnk@google.com
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
Subject: Re: [PATCH net v3] net: avoid clobbering active cork flowi union on datagram connect
Date: Tue, 01 Dec 2026 16:50:39 +0000 [thread overview]
Message-ID: <179614383945.3146.14922794471906658590@kernel.org> (raw)
In-Reply-To: <20261130160427.2653731-1-dmnk@google.com>
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
prev parent reply other threads:[~2026-12-01 16:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 16:04 [PATCH net v3] net: avoid clobbering active cork flowi union on datagram connect Dominik Maier
2026-12-01 16:50 ` netdev-bot+sashiko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179614383945.3146.14922794471906658590@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=davem@davemloft.net \
--cc=dmnk+artist@google.com \
--cc=dmnk@google.com \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=jchapman@katalix.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tparkin@katalix.com \
--cc=willemdebruijn.kernel@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox