Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Willem de Bruijn
Thu, 08 Oct 2026 18:37
Re: [PATCH net] udp_tunnel: drop packets when hibernating
Author: Willem de Bruijn
Date: Thu, 08 Oct 2026 18:37
Date: Thu, 08 Oct 2026 18:37
174 lines
13521 bytes
13521 bytes
Jason A. Donenfeld wrote:
> The kernel's various networking applications keep churning away after
> userspace is frozen during hibernation, even as a memory snapshot is
> being made. This can lead many network applications to an inconsistent
> state, replaying packets and cryptographic state changes. For example,
> on wireguard, there's the possibility of this sequence:
>
> 1) hibernating begins
> 2) handshake state cleared
> 3) keypairs cleared
> 4) new handshake round trip completes
> 5) machine memory is snapshotted
> 6) packet is sent using new keypair
> 7) machine is restored to state (5)
> 8) packet is sent using new keypair
>
> The idea is to prevent (6) from happening, especially if (6) and (8)
> contain different data, but the same key and nonce. Presumably the same
> issue applies to other users of udp_tunnel too.
>
> Fix this by just dropping sending and receiving packets during the
> hibernation sequence.
A few high level questions:
If the issue is reuse of key + nonce during send, why include receive
side functions? Specifically tunnel (encap_rcv) functions.
Is this a problem specific to UDP tunnels?
> Cc: stable@vger.kernel.org
> Reported-by: Jérémy Jean <jeremy.jean@oss.cyber.gouv.fr>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
> I wrote this patch in response to the issue Jérémy raised, but I'm not
> actually super familiar with all of the hibernation mechanics. If
> somebody working on PM would think about this matter too, I'd be much
> obliged.
>
> include/linux/freezer.h | 1 +
> net/ipv4/udp.c | 5 +++++
> net/ipv4/udp_tunnel_core.c | 5 +++++
> net/ipv6/ip6_udp_tunnel.c | 5 +++++
> net/ipv6/udp.c | 5 +++++
> 5 files changed, 21 insertions(+)
>
> diff --git a/include/linux/freezer.h b/include/linux/freezer.h
> index 0a8c6c4d1a82..21d708dc4092 100644
> --- a/include/linux/freezer.h
> +++ b/include/linux/freezer.h
> @@ -76,6 +76,7 @@ static inline bool cgroup1_freezing(struct task_struct *task)
> #endif /* !CONFIG_CGROUP_FREEZER */
>
> #else /* !CONFIG_FREEZER */
> +#define pm_freezing (false)
> static inline bool frozen(struct task_struct *p) { return false; }
> static inline bool freezing(struct task_struct *p) { return false; }
> static inline void __thaw_task(struct task_struct *t) {}
> diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
> index b090bd1f59e8..5021932ad9f1 100644
> --- a/net/ipv4/udp.c
> +++ b/net/ipv4/udp.c
> @@ -95,6 +95,7 @@
> #include <linux/netdevice.h>
> #include <linux/slab.h>
> #include <linux/sock_diag.h>
> +#include <linux/freezer.h>
> #include <net/tcp_states.h>
> #include <linux/skbuff.h>
> #include <linux/proc_fs.h>
> @@ -2425,6 +2426,10 @@ static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb)
> if (encap_rcv) {
> int ret;
>
> + /* Drop if we're hibernating */
> + if (unlikely(pm_freezing))
> + goto drop;
> +
> /* Verify checksum before giving to encap */
> if (udp_lib_checksum_complete(skb))
> goto csum_error;
> diff --git a/net/ipv4/udp_tunnel_core.c b/net/ipv4/udp_tunnel_core.c
> index a128fe85620d..e3666ed96af7 100644
> --- a/net/ipv4/udp_tunnel_core.c
> +++ b/net/ipv4/udp_tunnel_core.c
> @@ -3,6 +3,7 @@
> #include <linux/errno.h>
> #include <linux/socket.h>
> #include <linux/kernel.h>
> +#include <linux/freezer.h>
> #include <net/dst_metadata.h>
> #include <net/flow.h>
> #include <net/udp.h>
> @@ -172,6 +173,10 @@ void udp_tunnel_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *skb
> {
> struct udphdr *uh;
>
> + /* Drop if we're hibernating */
> + if (unlikely(pm_freezing))
> + return;
> +
> __skb_push(skb, sizeof(*uh));
> skb_reset_transport_header(skb);
> uh = udp_hdr(skb);
> diff --git a/net/ipv6/ip6_udp_tunnel.c b/net/ipv6/ip6_udp_tunnel.c
> index 32525a051a6f..4a31e8cc8887 100644
> --- a/net/ipv6/ip6_udp_tunnel.c
> +++ b/net/ipv6/ip6_udp_tunnel.c
> @@ -7,6 +7,7 @@
> #include <linux/types.h>
> #include <linux/kernel.h>
> #include <linux/in6.h>
> +#include <linux/freezer.h>
> #include <net/udp.h>
> #include <net/udp_tunnel.h>
> #include <net/net_namespace.h>
> @@ -86,6 +87,10 @@ void udp_tunnel6_xmit_skb(struct dst_entry *dst, struct sock *sk,
> struct udphdr *uh;
> struct ipv6hdr *ip6h;
>
> + /* Drop if we're hibernating */
> + if (unlikely(pm_freezing))
> + return;
> +
> __skb_push(skb, sizeof(*uh));
> skb_reset_transport_header(skb);
> uh = udp_hdr(skb);
> diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
> index 93478d1ad576..db9c2050887d 100644
> --- a/net/ipv6/udp.c
> +++ b/net/ipv6/udp.c
> @@ -34,6 +34,7 @@
> #include <linux/slab.h>
> #include <linux/uaccess.h>
> #include <linux/indirect_call_wrapper.h>
> +#include <linux/freezer.h>
> #include <trace/events/udp.h>
>
> #include <net/addrconf.h>
> @@ -848,6 +849,10 @@ static int udpv6_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb)
> if (encap_rcv) {
> int ret;
>
> + /* Drop if we're hibernating */
> + if (unlikely(pm_freezing))
> + goto drop;
> +
> /* Verify checksum before giving to encap */
> if (udp_lib_checksum_complete(skb))
> goto csum_error;
> --
> 2.56.0
>
Re: [PATCH net] udp_tunnel: drop packets when hibernating
Author: Willem de Bruijn
Date: Thu, 08 Oct 2026 21:03
Date: Thu, 08 Oct 2026 21:03
56 lines
11591 bytes
11591 bytes
On Thu, Oct 8, 2026 at 3:58 PM Jason A. Donenfeld <Jason@zx2c4.com> wrote: > > Hi Willem, > > On Thu, Oct 8, 2026 at 8:37 PM Willem de Bruijn > <willemdebruijn.kernel@gmail.com> wrote: > > Jason A. Donenfeld wrote: > > > The kernel's various networking applications keep churning away after > > > userspace is frozen during hibernation, even as a memory snapshot is > > > being made. This can lead many network applications to an inconsistent > > > state, replaying packets and cryptographic state changes. For example, > > > on wireguard, there's the possibility of this sequence: > > > > > > 1) hibernating begins > > > 2) handshake state cleared > > > 3) keypairs cleared > > > 4) new handshake round trip completes > > > 5) machine memory is snapshotted > > > 6) packet is sent using new keypair > > > 7) machine is restored to state (5) > > > 8) packet is sent using new keypair > > > > > > The idea is to prevent (6) from happening, especially if (6) and (8) > > > contain different data, but the same key and nonce. Presumably the same > > > issue applies to other users of udp_tunnel too. > > > > > > Fix this by just dropping sending and receiving packets during the > > > hibernation sequence. > > > > A few high level questions: > > > > If the issue is reuse of key + nonce during send, why include receive > > side functions? Specifically tunnel (encap_rcv) functions. > > Because I suppose (4) probably shouldn't be possible after (1). I > explicitly clear the result of (4) in a PM notifier. It seems wrong > for that to then be violated after. Similarly, userspace doesn't get > packets after that point either. Since this is an issue specific with security protocols and reuse of their state across freeze and restore, is that the more suitable location for this check? Drop transmit of packets with that risk (unique for that connection nonce) only, if freezing. > > Is this a problem specific to UDP tunnels? > > The stateless nature makes it more poignant there. udp_queue_rcv_one_skb is the UDP hot path. Since it touches all packets, the last resort for adding checks that are relevant too only a small subset of packets.
Re: [PATCH net] udp_tunnel: drop packets when hibernating
Author: Willem de Bruijn
Date: Sun, 11 Oct 2026 16:28
Date: Sun, 11 Oct 2026 16:28
53 lines
11066 bytes
11066 bytes
Jason A. Donenfeld wrote: > On Thu, Oct 8, 2026 at 11:03 PM Willem de Bruijn > <willemdebruijn.kernel@gmail.com> wrote: > > Since this is an issue specific with security protocols and reuse of > > their state across freeze and restore, is that the more suitable > > location for this check? Drop transmit of packets with that risk > > (unique for that connection nonce) only, if freezing. > > I was thinking this is a pretty common problem to UDP apps in general, > and it's confusing to have these sorts of replays due to hibernation > that userspace doesn't have. It's an odd problem to expect every > in-kernel user to fix independently, so maybe it'd be more clever to > do this all in one place. I can put it in only wireguard, instead, if > you feel really strongly about it. But I was thinking this just seemed > like an odd behavior difference that could be easily fixed for > everyone. When it comes to security protocols, this does not cover many of them, such as IPSec, MACSec, kTLS or PSP. Independent of security protocols, is there a replay on thaw issue? Your example points out that 6 and 8 can have different data, so this is not a replay because of thaw, but a second transmission by the security protocol, correct? If so, then other UDP protocols are not necessarily affected: only the nonce reuse is the problematic aspect. To avoid across UDP, udp_tunnel_xmit_skb would also be too narrow, capturing only tunnel packets. Blocking transmission post snapshot entirely may require quiescing at the device layer, something like QUEUE_STATE_STACK_XOFF (if that isn't done yet, I don't know this freeze process well). > > udp_queue_rcv_one_skb is the UDP hot path. Since it touches all > > packets, the last resort for adding checks that are relevant too only > > a small subset of packets. > > Is there another way you'd suggest doing this? Some other trick for > disabling the socket? I also am not keen on adding branches to hot > paths. At this layer or another, making pm_freezing a static_branch toggled by freeze_processes() / thaw_processes() would make the branch a NOOP in het hot path. So far, most promising I see is blocking the new handshake in Wireguard itself to avoid this from being possible. But that would indeed require all other protocols to be warned and review for individual fixes. A single choke point would be preferable, but I do not think they share a single such code path.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads