Article View: linux.kernel.netdev
Article #25261[PATCH 09/22] xfrm: replay: Fix late packet handling with ESN crypto offload
From: Steffen Klassert
Date: Tue, 01 Dec 2026 12:41
Date: Tue, 01 Dec 2026 12:41
73 lines
12157 bytes
12157 bytes
From: Cosmin Ratiu <cratiu@nvidia.com>
xfrm_replay_seqhi() guesses seq_hi for a given ingress seq per RFC 4303
section A2.2. Packets with seq < bottom are interpreted as being ahead
and the function returns the next seq_hi. xfrm_replay_check_esn() redoes
the same computation and defers to the ICV check.
On SW crypto, such packets then fail the ICV check and are dropped,
unless they're actual packets ~2^32 in the future (very unlikely).
But on crypto offload, the ICV check already happened in HW and isn't
repeated. xfrm_replay_advance_esn() then increments replay_esn->seq_hi.
The problem becomes visible when the HW state is renewed (e.g. bond
failover or mlx5 mid-sequence ESN state update). The newly offloaded SA
carries the wrong seq_hi and completely breaks ingress since all future
packets fail ICV.
This was verified on b2b ConnectX NICs, with an 'iperf3 -P 2' test over
a pair of SAs over a bond device in active-backup mode.
After ~10s of traffic at ~10 Gbps, replay_esn->seq_hi was ~2.5M due to
the two streams sharing the ESN state.
Forcing a bond failover on both sides breaks traffic permanently.
Fix this by dropping packets up to 2^31 before the replay window for
crypto offload, since the SW seq_hi guess cannot be validated. Packets
up to 2^31 ahead are accepted as new, same as old code. A burst loss of
more than 2^31 packets now stalls the SA (previously up to 2^32-wsize).
SW crypto is unaffected.
Fixes: 50bd870a9e5c ("xfrm: Add ESN support for IPSec HW offload")
Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
net/xfrm/xfrm_replay.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/net/xfrm/xfrm_replay.c b/net/xfrm/xfrm_replay.c
index 9394953247ab..37c0c299cb10 100644
--- a/net/xfrm/xfrm_replay.c
+++ b/net/xfrm/xfrm_replay.c
@@ -451,6 +451,7 @@ static int xfrm_replay_overflow_esn(struct xfrm_state *x, struct sk_buff *skb)
static int xfrm_replay_check_esn(struct xfrm_state *x,
struct sk_buff *skb, __be32 net_seq)
{
+ struct xfrm_offload *xo = xfrm_offload(skb);
unsigned int bitnr, nr;
u32 diff;
struct xfrm_replay_state_esn *replay_esn = x->replay_esn;
@@ -469,7 +470,18 @@ static int xfrm_replay_check_esn(struct xfrm_state *x,
diff = top - seq;
- if (likely(top >= wsize - 1)) {
+ if (xo && (xo->flags & CRYPTO_DONE)) {
+ /* The ICV was already verified by HW with its own seq_hi,
+ * so the seq_hi guessed by xfrm_replay_seqhi() can't
+ * be validated in SW.
+ *
+ * Treat seq up to 2^31 ahead of top as new, everything else as
+ * behind: in-window ones go through the bitmap, the rest get
+ * dropped.
+ */
+ if (likely(diff >= BIT(31)))
+ return 0;
+ } else if (likely(top >= wsize - 1)) {
/* A. same subspace */
if (likely(seq > top) || seq < bottom)
return 0;
--
2.53.0
Technical Details
Message-ID:
<20261201124252.1163254-10-steffen.klassert@secunet.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375048-linux-kernel-netdev=dewy.ruReferences:
<20261201124252.1163254-1-steffen.klassert@secunet.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375048-linux-kernel-netdev=dewy.ru From: steffen.klassert@secunet.com (Steffen Klassert) Newsgroups: linux.kernel.netdev Subject: [PATCH 09/22] xfrm: replay: Fix late packet handling with ESN crypto offload Date: Tue, 1 Dec 2026 13:41:35 +0100 Organization: Usenet Network Message-ID: <20261201124252.1163254-10-steffen.klassert@secunet.com> References: <20261201124252.1163254-1-steffen.klassert@secunet.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1712415"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:NWwbWRWh8X4yuPIccUkxO8Tstuo= sha256:D3LAQroD1Qv6db+k5jIPGlXDKGDr9DUWyFRTo4lTO5w= sha1:dYEmhs9hWkTwg8pjB/bMOEFnThY= sha256:jq9RlXA8qbkhKh+pZehZuE1dEJ6mVDBYg/PbF/IsZZc= 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 D5850117383; Tue, 1 Dec 2026 15:45:04 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.05 X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, 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, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=secunet.com 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 7YvXFFNm-t_7; Tue, 1 Dec 2026 15:45:01 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-375048-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=secunet.com X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 6FC9E117391; Tue, 1 Dec 2026 15:44:53 +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 196EC29DDD; Tue, 1 Dec 2026 12:44:35 +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=1796129057; b=G9HgfJ5taPE6msoBVtISDrXbVgYZvbx1P3U4kuII3DpORWZSBHE3mY4ac/FVFtMZ++b/ fYm2uLTaNwnjPlENgqEFy5B94UjSPYJgOoPLSAnhnNvmF0MXZtqZhzdLcTfGjHdkrxKNb pGq1nN7F+qMoMD0Pve30iSq6YA1qXAqv4VkRYppBYiMDvMAvLcUiWB97x0B5peJusLVKW ej07fpBlAo7rX7UQ1mROXR12GYW+LQX9UoKIq3xNAX5R3jdRUezWQZz3Gaxmi9AFmcrGp 3+MOE3RTr+wdbl7Bilent0aQJWX3REk9eUHqEAE/qMYsXN1lW5h19GIRltuMISmEpFg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796129057; h=X-Original-To:Received:DMARC-Filter:Received:X-Virus-Scanned: Received:Received:DKIM-Filter:DKIM-Signature:Received: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-Transfer-Encoding:Content-Type:X-ClientProxiedBy; bh=SgkFjEx6ZJ/ut+KNudm7YdMDL9fPF+4jT8gOf8VaNS8=; b=LjHG7yO3sqaO0QCrp7agMpWSjbxq6/MNBb9EJS9dSmcBQYxjiWeoNUF85Yq6v7H0ke44 ACNjsVfhUZIR6+FztZobJ94rCCfWs68FhfJ++BACUzdiPOj4dgzSt02BI7AQC3KdcdtNJ Co+89fkGipJBNL5B2uZ3BpM2shbqdydS4WkAG+s/5U0Ip9LY6/vLTEHXlUihs6EKL4FGa nPzVRyrJZmqzR3kxN/zBf5kGz2mLTCGWo+eY3+R52iVhVsaduFnXpRPzOmKnsgHAW4Q9P yhMdF2AtmibCqsCZjyWonzzRypQe7TFMxg+uHcDKHnI9F1T4iIKpYX9e18S7t5CW32w== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=XPvvRI4f; dmarc=pass header.from=secunet.com; spf=pass smtp.mailfrom=secunet.com; 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 6828A606A689; Tue, 1 Dec 2026 12:44:17 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=XPvvRI4f X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=62.96.220.36 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796129056; b=wtPaD2+WuZOaLywAtUkCRtYfR1I0Nr2irfr1wP7NIh5uskWOEn50Di+tG98HEzXKx0Oz bRfVnlDIuvFnFD1po2sk0hHyBiNlCemQ4M8+rGbCB9hZmhkrOthEdKqqKFD3NBcik2Naz dxhEkU3UroXR54+xeg36gscyFp2K5+Ax2peCBCg0hj948MHKj9AE9FP4rtD66k/uOeqZj wrsRs6dH1c0huknG70PJmnxX3ZDVJFAKjFLJwHmyGqZhV5A1nlHq1Qcp9f+rYjC6gT21y neK+leOk6SMIXcVtK6Ix0sPuM5eQ0kPasRzPGHrwZJV8CLHYaYcC2cKjVfO0+2EIp8Q== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796129056; h=DMARC-Filter:Received:X-Virus-Scanned:Received:Received:DKIM-Filter: DKIM-Signature:Received:Received:From:To:CC:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:Content-Type:X-ClientProxiedBy; bh=SgkFjEx6ZJ/ut+KNudm7YdMDL9fPF+4jT8gOf8VaNS8=; b=eVhJ1b32+wyBqEQ2XEd+ZYYTRvzbFgdZaQ14IxJttI/Cjx/4I76eaDOXuKHUcCR446eD onw39Rij217APa6tanbWlIkdKCxswX3Njk6XAB3icX5EpcwfPP8mgcvq/sdGBpWjItt4+ avBJLW7cJ1Uvody9Sse0UOOcHxt5W6en+mPESMqbMuDt9pG4/WlgUysg1vucqm6DGyc6v KCZ+Fb4cdsoI2eELYHAQsivkDzMu0N6/+jqaA3DPW4tSUMDsmF3Z8RsR568sqL7k9goLO ebqHz5hBGbMV1iwqJl6bfebre7eE+uy15C/iwdIEj7y/OxRIqfeGCWGIDLjqShIPKMg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=secunet.com; spf=pass smtp.mailfrom=secunet.com; dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=XPvvRI4f; arc=none smtp.remote-ip=62.96.220.36 X-Received: from mx1.secunet.com (mx1.secunet.com [62.96.220.36]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEF18606A6A2 for <netdev@vger.kernel.org>; Tue, 1 Dec 2026 12:44:15 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DEF18606A6A2 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=secunet.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=secunet.com X-Received: from localhost (localhost [127.0.0.1]) by mx1.secunet.com (Postfix) with ESMTP id AD4F420764; Tue, 1 Dec 2026 13:44:14 +0100 (CET) X-Virus-Scanned: by secunet X-Received: from mx1.secunet.com ([127.0.0.1]) by localhost (mx1.secunet.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0V4z710Ifhi2; Tue, 1 Dec 2026 13:44:14 +0100 (CET) X-Received: from EXCH-01.secunet.de (rl1.secunet.de [10.32.0.231]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.secunet.com (Postfix) with ESMTPS id 028CD20684; Tue, 1 Dec 2026 13:44:14 +0100 (CET) X-DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com 028CD20684 X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com; s=202301; t=1796129054; bh=SgkFjEx6ZJ/ut+KNudm7YdMDL9fPF+4jT8gOf8VaNS8=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=XPvvRI4fv2wkQfY+6DbzZ2pvOXHLzBDn830LyvKNQ7Y8y+H4shltdI/ArlLUrrBsd VADriyVjw2VS3NbTvws7tQ4CzjJSXjmFlda4/9hOZcQZuRkSfLrZV25DGEqOWfhYsE 2ZG1wUyYv+pzlMjv3hNqqVrOtMNMEXBeQaVRVZhUtN/EopXQiO3zn2pTeSiJe5QWUz qq4jHBpn9SDWn/Ol/Nnsn9gW8XUWgMqJgRxDhJfNXmhjTW8JhhywHLstCxI93dkjWi 6Diew1ymbPoy2TIKsoolWgn26Eu9QfsDbp1Mj12Qn6j0YS8lqhNfGHynQtCarJjf1D xwGbvFFI0va1Q== X-Received: from gauss4 (10.182.7.102) by EXCH-01.secunet.de (10.32.0.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.49; Tue, 1 Dec 2026 13:44:13 +0100 X-Received: (nullmailer pid 1165787 invoked by uid 1000); Tue, 01 Dec 2026 12:43:55 -0000 X-CC: Herbert Xu <herbert@gondor.apana.org.au>, Steffen Klassert <steffen.klassert@secunet.com>, <netdev@vger.kernel.org> X-Mailer: git-send-email 2.53.0 X-In-Reply-To: <20261201124252.1163254-1-steffen.klassert@secunet.com> 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-ClientProxiedBy: EXCH-03.secunet.de (10.32.0.183) To EXCH-01.secunet.de (10.32.0.171)