Article View: linux.kernel.netdev
Article #25797Re: [PATCH 09/22] xfrm: replay: Fix late packet handling with ESN crypto offload
From: netdev-bot+sashiko
Date: Wed, 02 Dec 2026 13:12
Date: Wed, 02 Dec 2026 13:12
151 lines
13663 bytes
13663 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 ยท High: 1 ยท Medium: 0 ยท Low: 1
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).
- [High] The fix is incomplete.
- [Low] The commit message understates the impact of the bug being fixed.
--
xfrm: replay: Fix late packet handling with ESN crypto offload
This changes xfrm_replay_check_esn() so that, for crypto offloaded
packets (CRYPTO_DONE), only sequence numbers up to 2^31 ahead of the
window top are treated as new. Everything else is treated as behind and
either goes through the bitmap or is dropped. The aim is to stop the SW
seq_hi from being bumped by late packets that the HW has already
authenticated with a different seq_hi.
> 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.
[Severity: Low]
Should the commit message also mention the anti-replay impact of the old
code?
Before this patch, case A in xfrm_replay_check_esn() returned 0 for any
seq < bottom:
if (likely(seq > top) || seq < bottom)
return 0;
For a CRYPTO_DONE skb, xfrm_input() skips x->type->input(). It also skips
the recheck:
if (!crypto_done && xfrm_replay_recheck(x, skb, seq)) {
...
xfrm_replay_advance(x, seq);
That leaves xfrm_replay_check() as the only anti-replay barrier on the
offload path. A genuine, HW-authenticated packet older than the replay
window was therefore accepted and delivered a second time.
xfrm_replay_advance_esn() then saw wrap > 0. It cleared the bitmap, set
replay_esn->seq to the old low value and did replay_esn->seq_hi++. That
moves the window backwards. Packets already received between that value
and the previous top could then be replayed as well.
The description only covers the seq_hi drift and the breakage after
re-offload. Could it also say that out-of-window replays were being
accepted on ESN crypto offload SAs, to help stable and CVE triage?
> diff --git a/net/xfrm/xfrm_replay.c b/net/xfrm/xfrm_replay.c
> index 9394953247ab9..37c0c299cb106 100644
> --- a/net/xfrm/xfrm_replay.c
> +++ b/net/xfrm/xfrm_replay.c
[ ... ]
> @@ -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;
[Severity: High]
Can this still advance the SW ESN state on a seq_hi guess that differs
from the seq_hi the HW used for the ICV?
When diff >= 2^31 and seq is numerically below top (a wrapped "ahead"
packet), this branch returns 0 without checking the bitmap. For
crypto_done packets, xfrm_input() then goes straight to the advance:
xfrm_input()
xfrm_replay_check()
xfrm_replay_check_esn() /* diff >= BIT(31) -> return 0 */
xfrm_replay_advance()
xfrm_replay_advance_esn()
xfrm_replay_seqhi() /* seq < bottom -> seq_hi + 1 */
replay_esn->seq = seq;
replay_esn->seq_hi++;
The 2^31 boundary here is measured from top, but mlx5 picks its epoch
from the window bottom. mlx5e_ipsec_update_esn_state() computes esn_msb
from xfrm_replay_seqhi(x, htonl(seq_bottom)). It flips overlap based on
seq_bottom versus 2^31:
if (unlikely(overlap && seq_bottom < MLX5E_IPSEC_ESN_SCOPE_MID)) {
sa_entry->esn_state.overlap = 0;
return true;
} else if (unlikely(!overlap &&
(seq_bottom >= MLX5E_IPSEC_ESN_SCOPE_MID))) {
That update is also deferred to a work item by
mlx5e_xfrm_advance_esn_state().
So there seem to be two windows where HW and SW disagree:
- Case 1: top is in [2^31 + 1, 2^31 + wsize - 2], or later while the
overlap 0->1 work is still pending. The HW authenticates seq in
[1, top - 2^31] with seq_hi H, but this branch accepts them as new
under H + 1.
- Case 2: right after the low seq wraps to a small top, while the
overlap 1->0 work is still pending. The HW still uses H for
seq >= 2^31, but this branch accepts seq in [2^31, top + 2^31] as new
under H + 1.
ESP sequence numbers are sent in cleartext, so an on-path attacker could
time a replay of a captured epoch H packet into one of these windows.
The packet passes the HW ICV check because it is genuine, and this
branch then lets it be delivered again.
After that the SW state is (H + 1, s). In the first case, the sender's
legitimate (H, 2^31 + k) packets then give diff < 2^31 and
diff >= wsize. They are dropped as behind, which would stall the SA for
roughly 2^31 packets.
The wrong seq_hi also reaches the driver through
xfrm_dev_state_advance_esn(). A later re-offload would carry it, which
is the failure the commit message describes.
Could the SW use the seq_hi the HW actually verified instead? Another
option is to never let an offloaded packet bump seq_hi based only on the
SW guess.
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201124252.1163254-2-steffen.klassert%40secunet.com
Technical Details
Message-ID:
<179621714787.3146.10847263595723444158@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375796-linux-kernel-netdev=dewy.ruReferences:
<20261201124252.1163254-10-steffen.klassert@secunet.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375796-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH 09/22] xfrm: replay: Fix late packet handling with ESN crypto offload Date: Wed, 02 Dec 2026 13:12:27 +0000 Organization: Usenet Network Message-ID: <179621714787.3146.10847263595723444158@kernel.org> References: <20261201124252.1163254-10-steffen.klassert@secunet.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1976932"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:aDdpFuIJj/HluVBSdhKPIL446Zg= sha256:R3FASs1eE03QWbxbhABfv/2Bh2D+T98VmaIX5L6B+BA= sha1:cVwQvBiXoBv0gRx3/5zXVRvtc8Y= sha256:Eq2Lh7/VIFUhP5kx+w+LyfBtT4sOyqv6NvJC9gzIvn4= 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 CCC2C117648; Wed, 2 Dec 2026 16:12:49 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 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, DKIM_VALID_EF=-0.1, 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=kernel.org 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 6zLKr1Rk2_ng; Wed, 2 Dec 2026 16:12:45 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-375796-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id B1BC1117640; Wed, 2 Dec 2026 16:12:33 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 24E3629460; Wed, 2 Dec 2026 13:12:30 +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=1796217149; b=E+F++Z3UXY3jJaksCS6ikZehh0FgdkqDWQDcJneCES6lWWo2byBB/k6h+rihfA9AFApn qTyv5SU9ctw5U0Om7lQVRrcl16qMU+BcFYBT1PkQATzpRhyltnEGArxf6IoMBzhJBIcdS 8KsrOhHXr/EEPnu4pHG5GpEPxjc+0yEe5GPHrXClNb53axU5JBu7DNwfqmtiKXGzpOkWY QgvzwvtszDPD+IAnEuWvf0r38gFniwCkalxmk3vXi9VnnytjynjpXWR+OvaGg0ZHXQR95 txkLVzotvql1lqAINySMor5W+zbNuHdejHAE7takYQiELdj5lamDhRevwWCSh4mgQbA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796217149; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=BNlvoLhLH3mwEhoR1bVaKcuVqP6dYKRigRgYw5ZK8/M=; b=QHRFJHctoNDX1s9bNYwGDH2zJLyzzSzNYpLrQbtaVVvha7Vo0kj9vpF9lUjjb/6l1huT ozCtUxlWWa+A7qcrvAV+xjBFZ0FsjrmjTwllaFuhi46FACxhNsa5Z3UDhOGKXj3/6jA7Q ZaWseJDT8wORzEg1X/9O2fQXiimcUhvl2T3nSrcra35HtnFLsuP4yGFskzQ7pjuidWtAV LSzno666HwNN2hpbg+X3Ab6Nc8VoO0sbskvTTuXykbIOwAaianTRDDZe1QhNO4x8LpxDT uzUq846zc4hF4266uihLn1svKFYITL5Hdc8GULK7+m900JEMKYq1AiBmJy7UWViO0EQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="oMeY/FkK"; 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 BF970606A323; Wed, 2 Dec 2026 13:12:29 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oMeY/FkK X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796217149; b=y00q+JkvcnjAZPdIYcX5iHZzjBuI4y4suc29E39WIxh7Vm0onGps+pfpG+LwGSBE4HBk xAYn6/cmUYMlYJ7q168ghJHrtm7PjRmQfU1V/1WMmRqDobKwYBUYEOuD8YTiJcoSrFJmK Wqvehg+atErzcbvHgVIZ6egJCZENoIJ0yDDpA9FZanL7ZqH0gsHR0aUDH/FYxshWoLzNj JUdPzUnFwwAvZFjuTr3/BW1YgWJnwYVHT5CX22uDFu+4cVIaLXAc8JYvxP9FK0Q/yFx1X MAJwxMOuOsLE2yEgfCC2KaflBXAHRK+3iRIO27pqcWzjWFKG/7IBe8o1N7N42pDz52Q== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796217149; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=BNlvoLhLH3mwEhoR1bVaKcuVqP6dYKRigRgYw5ZK8/M=; b=tGvgJM7wiXxGXmCnPD6D2f59On7XD5T1kUK9dX1DMrlbwNCXGVBg/RmXWGceiPClHCWl zZfubvcgjDu0OGt/Bg6D+o4IlCcgOCjfwhXscw7CLZ/NAzebaRir/FNjymXaioTZ8+Yel mneY8YChnJ+VQOMPUmphtcC8djedCo3o+ifG9kkbOzO89b/dRbh8XI8IhzZJCOiAZkSA5 GrTwVjGWZCoyRTIn+DbnC78nagDr3x20ry51ESD6FrdHrobOydReiHiWyHOBVoiQYA2DV BUcmrGqTlWPhzkNPRrmzZ8eY4avCMSdKwjciiaTZbK9TBybFFX6w5w6kAYIjwZKMq/Q== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="oMeY/FkK"; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1981606A32D for <netdev@vger.kernel.org>; Wed, 2 Dec 2026 13:12:28 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51EA31F000C1; Wed, 2 Dec 2026 13:12:28 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796217148; bh=BNlvoLhLH3mwEhoR1bVaKcuVqP6dYKRigRgYw5ZK8/M=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=oMeY/FkK2uvon66Uu6IqbvoKX0BY+LPmK7SRxGQvBgJy+7s5hBClZ9JWdV/f4UFPA RGFACBxI0dC4jIyqwTtFOXdwUXlw9ST8xqx0+Jqq7kGI36BVZZYVBL6z3axm/9jtah wer9X7TYmnK7J8q78ty1c1dkqL7QkxJcThv2N1junyY9gnODX/70KBxJK252o2hGWa xw+b4qPyL5dX7H8nzvQoB2LRw2hfmUpYSFiC9mke5wJ7C1PtXIAMO6Se3oWRyyUitJ ChS8FbCrltUeU6lRd37smZHEG6hBd4Ug2kUOR7qcBZvlIP/nRQ87wi9DONMSkKYhtB FZkd2WpcvcOOg== X-Cc: davem@davemloft.net, kuba@kernel.org, herbert@gondor.apana.org.au, netdev@vger.kernel.org X-In-Reply-To: <20261201124252.1163254-10-steffen.klassert@secunet.com> X-sashiko-severity: High 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