From: "Jérémy Jean" <Jeremy.Jean@oss.cyber.gouv.fr>
To: Steffen Klassert <steffen.klassert@secunet.com>,
Herbert Xu <herbert@gondor.apana.org.au>
Cc: "David S . Miller" <davem@davemloft.net>,
"Sabrina Dubroca" <sd@queasysnail.net>,
"Saeed Mahameed" <saeedm@nvidia.com>,
"Leon Romanovsky" <leon@kernel.org>,
"Tariq Toukan" <tariqt@nvidia.com>,
"Mark Bloch" <mbloch@nvidia.com>,
"Boris Pismenny" <borisp@nvidia.com>,
netdev@vger.kernel.org,
"Jérémy Jean" <Jeremy.Jean@oss.cyber.gouv.fr>,
stable@vger.kernel.org
Subject: [PATCH ipsec 6/7] xfrm: segment untrusted GSO packets before sequence allocation
Date: Wed, 30 Sep 2026 14:45:23 +0000 [thread overview]
Message-ID: <20260930144523.435271-8-Jeremy.Jean@oss.cyber.gouv.fr> (raw)
In-Reply-To: <20260930144523.435271-2-Jeremy.Jean@oss.cyber.gouv.fr>
Packets received through TUN or virtio-net can have gso_segs == 0,
with SKB_GSO_DODGY set until the segmentation metadata is checked.
When ESP defers segmentation, gso_segs is still zero, so the SA
sequence counter is not advanced. The segments receive sequence
numbers starting at oseq + 1, which subsequent packets can reuse,
causing AES-GCM nonce reuse.
This affects IPv4 and IPv6, with or without ESN, when the ESP offload
type is registered. Hardware encryption is not required.
Segment SKB_GSO_DODGY packets in xfrm_output() before allocating
sequence numbers, so each segment gets its own number. Set the ESP
encapsulation flag in xfrm_output_one(), after early segmentation, so
UFO fragment offsets and flags are filled in correctly.
Fixes: d7dbefc45cf5 ("xfrm: Add xfrm_replay_overflow functions for offloading")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Jérémy Jean <Jeremy.Jean@oss.cyber.gouv.fr>
---
net/xfrm/xfrm_output.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/net/xfrm/xfrm_output.c b/net/xfrm/xfrm_output.c
index f6644daa68ba..30b95aba10f0 100644
--- a/net/xfrm/xfrm_output.c
+++ b/net/xfrm/xfrm_output.c
@@ -505,6 +505,9 @@ static int xfrm_output_one(struct sk_buff *skb, int err)
if (err <= 0 || x->xso.type == XFRM_DEV_OFFLOAD_PACKET)
goto resume;
+ if (xfrm_offload(skb))
+ skb->encapsulation = 1;
+
do {
err = xfrm_skb_check_space(skb);
if (err) {
@@ -812,10 +815,10 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb)
xfrm_state_hold(x);
xfrm_get_inner_ipproto(skb, x);
- skb->encapsulation = 1;
if (skb_is_gso(skb)) {
- if (skb->inner_protocol && x->props.mode == XFRM_MODE_TUNNEL)
+ if ((skb_shinfo(skb)->gso_type & SKB_GSO_DODGY) ||
+ (skb->inner_protocol && x->props.mode == XFRM_MODE_TUNNEL))
return xfrm_output_gso(net, sk, skb);
skb_shinfo(skb)->gso_type |= SKB_GSO_ESP;
--
2.47.3
next prev parent reply other threads:[~2026-09-30 14:46 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 14:45 [PATCH ipsec 0/7] xfrm: fix ESP IV generation and ESN authentication Jérémy Jean
2026-09-30 14:45 ` [PATCH ipsec 1/7] xfrm: esp6: use the current sequence number for the IV Jérémy Jean
2026-09-30 14:45 ` [PATCH ipsec 2/7] xfrm: esp4: " Jérémy Jean
2026-09-30 14:45 ` [PATCH ipsec 3/7] xfrm: esp: use the current sequence number for AAD and offload Jérémy Jean
2026-09-30 14:45 ` [PATCH ipsec 4/7] xfrm: prevent AES-GCM nonce reuse after early GSO Jérémy Jean
2026-10-01 13:31 ` Sabrina Dubroca
2026-10-01 21:07 ` Jérémy Jean
2026-09-30 14:45 ` [PATCH ipsec 5/7] net/mlx5e: Use the packet sequence number for the IPsec IV Jérémy Jean
2026-10-01 11:42 ` Sabrina Dubroca
2026-10-01 19:33 ` Jérémy Jean
2026-10-05 13:06 ` Tariq Toukan
2026-10-05 13:50 ` Jérémy Jean
2026-10-05 18:28 ` Jérémy Jean
2026-10-06 6:49 ` Tariq Toukan
2026-10-06 8:51 ` Jérémy Jean
2026-09-30 14:45 ` Jérémy Jean [this message]
2026-09-30 14:45 ` [PATCH ipsec 7/7] xfrm: leave the sequence counter unchanged on ESN overflow Jérémy Jean
2026-10-01 11:24 ` Sabrina Dubroca
2026-10-01 11:37 ` Jérémy Jean
2026-10-01 11:45 ` Sabrina Dubroca
2026-10-01 11:48 ` Jérémy Jean
2026-09-30 14:48 ` [PATCH ipsec 0/7] xfrm: fix ESP IV generation and ESN authentication netdev-bot+sinfo
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=20260930144523.435271-8-Jeremy.Jean@oss.cyber.gouv.fr \
--to=jeremy.jean@oss.cyber.gouv.fr \
--cc=borisp@nvidia.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=leon@kernel.org \
--cc=mbloch@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=saeedm@nvidia.com \
--cc=sd@queasysnail.net \
--cc=stable@vger.kernel.org \
--cc=steffen.klassert@secunet.com \
--cc=tariqt@nvidia.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