Article View: linux.kernel.netdev
Article #12766[PATCH ipsec v2 3/7] xfrm: esp: use the current sequence number for AAD and offload
From: Jérémy Jean
Date: Sun, 08 Nov 2026 14:26
Date: Sun, 08 Nov 2026 14:26
138 lines
14868 bytes
14868 bytes
When a GSO packet is split in software, esp_xmit() and esp6_xmit()
advance xo->seq before software encryption or the handoff to the NIC.
If the 64-bit sequence number of the segment is (H, 0xffffffff), the
counter becomes (H+1, 0). Both the software ESN helpers and drivers
such as Chelsio then use H+1 instead of H as part of the associated
data that is authenticated.
However, the ESN 32 high bits are not present in the ESP header: the
receiver reconstructs the 64-bit value from the received 32 low bits
and its own replay state, and uses it to check cryptographic
integrity. It uses H for this packet at the boundary, so the GCM tag
computed by the sender with H+1 fails verification, as it is different
from the one obtained by the receiver using H.
Use the high bits saved in esp->seqno for the software AAD. For
hardware encryption, restore the current sequence after skb_ext_add()
makes the secpath private, leaving the shared counter advanced for
the remaining segments. Restore both halves because drivers can also
use xo->seq to generate the IV.
Fixes: 3dca3f38cfb8 ("xfrm: Separate ESP handling from segmentation for GRO packets.")
Fixes: 4b549ccce941 ("xfrm: replay: Fix ESN wrap around for GSO")
Cc: stable@vger.kernel.org
Signed-off-by: Jérémy Jean <Jeremy.Jean@oss.cyber.gouv.fr>
---
net/ipv4/esp4.c | 13 ++++---------
net/ipv4/esp4_offload.c | 4 ++++
net/ipv6/esp6.c | 13 ++++---------
net/ipv6/esp6_offload.c | 4 ++++
4 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
index 111bea0bd2601..df4857beca02c 100644
--- a/net/ipv4/esp4.c
+++ b/net/ipv4/esp4.c
@@ -271,20 +271,15 @@ static void esp_output_restore_header(struct sk_buff *skb)
static struct ip_esp_hdr *esp_output_set_extra(struct sk_buff *skb,
struct xfrm_state *x,
struct ip_esp_hdr *esph,
- struct esp_output_extra *extra)
+ struct esp_output_extra *extra,
+ __be64 seqno)
{
/* For ESN we move the header forward by 4 bytes to
* accommodate the high bits. We will move it back after
* encryption.
*/
if ((x->props.flags & XFRM_STATE_ESN)) {
- __u32 seqhi;
- struct xfrm_offload *xo = xfrm_offload(skb);
-
- if (xo)
- seqhi = xo->seq.hi;
- else
- seqhi = XFRM_SKB_CB(skb)->seq.output.hi;
+ __u32 seqhi = upper_32_bits(be64_to_cpu(seqno));
extra->esphoff = (unsigned char *)esph -
skb_transport_header(skb);
@@ -543,7 +538,7 @@ int esp_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
else
dsg = &sg[esp->nfrags];
- esph = esp_output_set_extra(skb, x, esp->esph, extra);
+ esph = esp_output_set_extra(skb, x, esp->esph, extra, esp->seqno);
esp->esph = esph;
sg_init_table(sg, esp->nfrags);
diff --git a/net/ipv4/esp4_offload.c b/net/ipv4/esp4_offload.c
index 3a0aafe991f47..6f6ce9ea5c491 100644
--- a/net/ipv4/esp4_offload.c
+++ b/net/ipv4/esp4_offload.c
@@ -358,6 +358,10 @@ static int esp_xmit(struct xfrm_state *x, struct sk_buff *skb, netdev_features_
if (!xo)
return -EINVAL;
+ /* Keep the current sequence number in the private copy. */
+ xo->seq.low = seq;
+ xo->seq.hi = upper_32_bits(be64_to_cpu(esp.seqno));
+
xo->flags |= XFRM_XMIT;
return 0;
}
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
index b287c807b0186..7509fff7f6682 100644
--- a/net/ipv6/esp6.c
+++ b/net/ipv6/esp6.c
@@ -308,20 +308,15 @@ static void esp_output_restore_header(struct sk_buff *skb)
static struct ip_esp_hdr *esp_output_set_esn(struct sk_buff *skb,
struct xfrm_state *x,
struct ip_esp_hdr *esph,
- struct esp_output_extra *extra)
+ struct esp_output_extra *extra,
+ __be64 seqno)
{
/* For ESN we move the header forward by 4 bytes to
* accommodate the high bits. We will move it back after
* encryption.
*/
if ((x->props.flags & XFRM_STATE_ESN)) {
- __u32 seqhi;
- struct xfrm_offload *xo = xfrm_offload(skb);
-
- if (xo)
- seqhi = xo->seq.hi;
- else
- seqhi = XFRM_SKB_CB(skb)->seq.output.hi;
+ __u32 seqhi = upper_32_bits(be64_to_cpu(seqno));
extra->esphoff = (unsigned char *)esph -
skb_transport_header(skb);
@@ -575,7 +570,7 @@ int esp6_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info
else
dsg = &sg[esp->nfrags];
- esph = esp_output_set_esn(skb, x, esp->esph, extra);
+ esph = esp_output_set_esn(skb, x, esp->esph, extra, esp->seqno);
esp->esph = esph;
sg_init_table(sg, esp->nfrags);
diff --git a/net/ipv6/esp6_offload.c b/net/ipv6/esp6_offload.c
index 05d13cce22e47..682063bfe685f 100644
--- a/net/ipv6/esp6_offload.c
+++ b/net/ipv6/esp6_offload.c
@@ -379,6 +379,10 @@ static int esp6_xmit(struct xfrm_state *x, struct sk_buff *skb, netdev_features
if (!xo)
return -EINVAL;
+ /* Keep the current sequence number in the private copy. */
+ xo->seq.low = seq;
+ xo->seq.hi = upper_32_bits(be64_to_cpu(esp.seqno));
+
xo->flags |= XFRM_XMIT;
return 0;
}
--
2.47.3
Technical Details
Message-ID:
<20261108142652.1330952-4-Jeremy.Jean@oss.cyber.gouv.fr>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358767-linux-kernel-netdev=dewy.ruReferences:
<20261108142652.1330952-1-Jeremy.Jean@oss.cyber.gouv.fr>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-358767-linux-kernel-netdev=dewy.ru From: Jeremy.Jean@oss.cyber.gouv.fr (Jérémy Jean) Newsgroups: linux.kernel.netdev Subject: [PATCH ipsec v2 3/7] xfrm: esp: use the current sequence number for AAD and offload Date: Sun, 8 Nov 2026 14:26:48 +0000 Organization: Usenet Network Message-ID: <20261108142652.1330952-4-Jeremy.Jean@oss.cyber.gouv.fr> References: <20261108142652.1330952-1-Jeremy.Jean@oss.cyber.gouv.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="140605"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:1Zb0ykZi0Hd9cSEowkg+J/DK3f0= sha256:9ouA3Wo/EIdIxxMfe/Dm9/Jp9UQFSJehbQmM0yx0d4M= sha1:ej7xUsb1zHALC8ewB/kxGp4KEwg= sha256:slBRmjzKZCzzbaovd305KESCLtPTB+aNLIVxnHCGeZk= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Source X-Source-Args X-Source-Dir X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 78AA711359D; Sun, 8 Nov 2026 17:27:48 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.052 X-Spam-Status: No, score=-3.052 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, HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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=oss.cyber.gouv.fr 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 IklrM2ewad6o; Sun, 8 Nov 2026 17:27:41 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-358767-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=oss.cyber.gouv.fr X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id A24DF11359A; Sun, 8 Nov 2026 17:27:30 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 2722D472ED; Sun, 8 Nov 2026 14:27:09 +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=1794148022; b=sytipMRVkJtuQc4EoFv0wYK+9QikiXB0Gs4/M271oiJhh9Hqe3WeO22LGqBLQmvzfaw7 UNSN2CXX+THKdGKWjXPDJL+szz+NToo4Ws6pM7KFUrwzlx+QdR7nc3ekKyef+eWbcCiGT 1X71Lx7q+8Zz9VxNgcKGSw8wAF97uheUYjTEqxgT/b3zi9p7HUHhJklvwoXsiWgR56EYt guqK7uzDkVXf02B9m+OVj7oWER5TPTadf9aZ0pYm7u2T0m/sHQdmLrbGCsS5lhvWvxgVa bqlRyf9xNd4zL7PyMrdi3DD5YHuu57Wt1xYnv+3fAbVy23Ka5vmxMhaZT4PDaVa7dig== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794148022; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:From:To: Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type: Content-Transfer-Encoding:X-AntiAbuse:X-AntiAbuse:X-AntiAbuse: X-AntiAbuse:X-AntiAbuse:X-Get-Message-Sender-Via: X-Authenticated-Sender:X-Source:X-Source-Args:X-Source-Dir; bh=3wUqO+seTF1eo5qfGWwpAfyX8WoqptNLIiqIBPEK0rM=; b=0UGYaucY43jtEnzYMLTpuXFUjoZjp56oILw9YW/RUslZXRtTtr8ynOX/PQNv9gMtfDq6 QQA9BVFXiEKpdOVh110XdyyqWuVkQerLsCCVvml3H+Edr2oF3n2ivr4wDVjyB9Qoftg7N TbPCaAXO6tOIlgKxMR9QROe0m+H9Z5JvaRnTTBtOscCvLr1eBmqOCr0uDpfd8G7rXvP5i u49SiDWzSKIMOx6IPnL6UR9+bkBDpgKZS4Rgj7Rmm1MjGMXBvIn6oJsv/ZjR4Ry+fHchH adyL5fNOhsfkNnokrbqu1oIg+61B7XjYuFvyIUno+lGfhyDPONmsf1rkiGUohieLNKQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=oss.cyber.gouv.fr header.i=@oss.cyber.gouv.fr header.a=rsa-sha256 header.s=default header.b=Ew2JI7ZC; dmarc=pass header.from=oss.cyber.gouv.fr; spf=pass smtp.mailfrom=oss.cyber.gouv.fr; 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 E308C606D827; Sun, 8 Nov 2026 14:27:01 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oss.cyber.gouv.fr header.i=@oss.cyber.gouv.fr header.a=rsa-sha256 header.s=default header.b=Ew2JI7ZC X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=51.159.188.251 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794148021; b=pYztqccnujgrb226NBYPMSnCWM77CSfpq7a4DIEFyyrsRGGqkZdNdiM/AgQq2fei73yI jR6I9d4ppl9oCuLuXIVdTHWbwkmCjGbX9Be+woU+jNzCGBlSnipUwG8Wk5LxXGsj55GvF Q7/QBH0EYgod80TqD7RS5TFK3459/zR+FhrszeHXvwBo5lV5PF76gF5L8DxHwoCMfsIei gYFxKBlS00pVIVw7A7USogDrU8YcFjl5fikQyfDCNFlGeqjIbWqVw+NVzt+u48XSPishS mYEMGSjd1A1uyHIBjIqSFJU2VB2LFDLtQ1c34+2BpGUz4OJAXkdjCTVToTc10CWPZ3Q== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794148021; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding:X-AntiAbuse:X-AntiAbuse:X-AntiAbuse: X-AntiAbuse:X-AntiAbuse:X-Get-Message-Sender-Via: X-Authenticated-Sender:X-Source:X-Source-Args:X-Source-Dir; bh=3wUqO+seTF1eo5qfGWwpAfyX8WoqptNLIiqIBPEK0rM=; b=RiQbcsYj2lsRrBDbLvUYWucbYafpXf9uh44StV7Y4jchAf5kQT/gA1tVMtnXNOeNQlj7 nJbnPs8JP1+RgB0Glewr3+Ps5xfWxBgAWeMrPwle7mMR6j0MGFj/xfP/hR01bstZQ6UlR 2j2wnkMuncoZWMgvlRybktEJYESySs82uFVaVfHMks9YqD5etIPBsA/Ce7UqFOpKdZS0m I1ueV/ez+1lw4mcBfMWttDje1RttyASovaAUMJhRKh9+2o9JU80A1h5YGr9W4pvIr4HC5 XMWYLqNsNxYOfL6r4FcvvDq4n77S+9vO5+1fWzRbk6H7S9QYA/Y34OkSrlVOZYObWjg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.cyber.gouv.fr; spf=pass smtp.mailfrom=oss.cyber.gouv.fr; dkim=pass header.d=oss.cyber.gouv.fr header.i=@oss.cyber.gouv.fr header.a=rsa-sha256 header.s=default header.b=Ew2JI7ZC; arc=none smtp.remote-ip=51.159.188.251 X-Received: from oss.cyber.gouv.fr (oss.cyber.gouv.fr [51.159.188.251]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80A86606A335; Sun, 8 Nov 2026 14:27:00 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 80A86606A335 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.cyber.gouv.fr X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.cyber.gouv.fr X-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=oss.cyber.gouv.fr; s=default; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Sender:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=3wUqO+seTF1eo5qfGWwpAfyX8WoqptNLIiqIBPEK0rM=; b=Ew2JI7ZC0FdeIFKVj7ZqmJQgNO oJyy4ovx+0VesTBf+Q7cMONJR0OUs1wtW4kwP8daFnvMhvjOHX+Zx42Az7rHWp4CKHcXoW/gFMswQ JP4FGBnn5XfRxsQ0SrW1ei+Sc/Pko9gYeVYfX/EajDVKdpmGaUTZ3nyYnb+GlVrhf894qqRrFFUtY MwKoTzxlSOusUE2COjKYhDL8/bYOuY704pwEGejZeUm+KHVhd8CIf2brBjlsaXARZs8b1aWe2/oOr r+3AMoIOq9x39nGUAHy8DDPyxu3A1gsagOL954RbLjodz4lXzGODyGuGsugNST5gtpM72Ee0kYLTJ SdBDLnyQ==; X-Received: from [151.115.150.205] (port=49652 helo=gepetto..) by pf-012.whm.fr-par.scw.cloud with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from <Jeremy.Jean@oss.cyber.gouv.fr>) id 1xQ3rG-00000008IcJ-3amL; Sun, 08 Nov 2026 15:26:58 +0100 X-Cc: "David S. Miller" <davem@davemloft.net>, Boris Pismenny <borisp@nvidia.com>, Saeed Mahameed <saeedm@nvidia.com>, Leon Romanovsky <leonro@nvidia.com>, Tariq Toukan <tariqt@nvidia.com>, Mark Bloch <mbloch@nvidia.com>, netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Jérémy Jean <Jeremy.Jean@oss.cyber.gouv.fr>, stable@vger.kernel.org X-Mailer: git-send-email 2.47.3 X-In-Reply-To: <20261108142652.1330952-1-Jeremy.Jean@oss.cyber.gouv.fr> 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-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - pf-012.whm.fr-par.scw.cloud X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - oss.cyber.gouv.fr X-Get-Message-Sender-Via: pf-012.whm.fr-par.scw.cloud: authenticated_id: jeremy.jean@oss.cyber.gouv.fr X-Authenticated-Sender: pf-012.whm.fr-par.scw.cloud: jeremy.jean@oss.cyber.gouv.fr