From: Steffen Klassert <steffen.klassert@secunet.com>
To: <netdev-bot+sashiko@kernel.org>
Cc: <davem@davemloft.net>, <kuba@kernel.org>,
<herbert@gondor.apana.org.au>, <netdev@vger.kernel.org>,
Cosmin Ratiu <cratiu@nvidia.com>
Subject: Re: [PATCH 09/22] xfrm: replay: Fix late packet handling with ESN crypto offload
Date: Thu, 3 Dec 2026 08:08:06 +0100 [thread overview]
Message-ID: <axEVVoLfGtxH8hI-@gauss4> (raw)
In-Reply-To: <179621714787.3146.10847263595723444158@kernel.org>
Ccing the author of the patch.
On Wed, Dec 02, 2026 at 01:12:27PM +0000, netdev-bot+sashiko@kernel.org wrote:
> 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))) {
I don't know what the driver is doing here, but the patch fixes
a real issue. So this should be handled as a followup.
>
> 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
next prev parent reply other threads:[~2026-12-03 7:08 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 12:41 [PATCH 0/22] pull request (net): ipsec 2026-12-01 Steffen Klassert
2026-12-01 12:41 ` [PATCH 01/22] xfrm: ipcomp: account full fragment pages in truesize Steffen Klassert
2026-12-01 13:36 ` bot+bpf-ci
2026-12-01 12:41 ` [PATCH 02/22] xfrm: esp: reset outer TCP GSO metadata on espintcp input Steffen Klassert
2026-12-01 12:41 ` [PATCH 03/22] xfrm: keep the mode module pinned until destroy_state returns Steffen Klassert
2026-12-01 12:41 ` [PATCH 04/22] xfrm: serialize SA activation with state deletion Steffen Klassert
2026-12-01 12:41 ` [PATCH 05/22] xfrm: keep old state references until migration deletion completes Steffen Klassert
2026-12-01 12:41 ` [PATCH 06/22] xfrm: hold migrated states through rollback Steffen Klassert
2026-12-01 12:41 ` [PATCH 07/22] xfrm: check inner family via skb_dst for small_ipv6 DF clearing Steffen Klassert
2026-12-02 13:12 ` netdev-bot+sashiko
2026-12-03 6:58 ` Steffen Klassert
2026-12-01 12:41 ` [PATCH 08/22] xfrm: account XFRMA_MARK in xfrm_sa_len() Steffen Klassert
2026-12-01 12:41 ` [PATCH 09/22] xfrm: replay: Fix late packet handling with ESN crypto offload Steffen Klassert
2026-12-02 13:12 ` netdev-bot+sashiko
2026-12-03 7:08 ` Steffen Klassert [this message]
2026-12-01 12:41 ` [PATCH 10/22] xfrm: fix IPv6 first-fragment protocol decode Steffen Klassert
2026-12-02 13:12 ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 11/22] xfrm: fix selector matching for IPv6 atomic fragments Steffen Klassert
2026-12-02 13:12 ` netdev-bot+sashiko
2026-12-03 7:15 ` Steffen Klassert
2026-12-01 12:41 ` [PATCH 12/22] xfrm: espintcp: read the socket error queue for MSG_ERRQUEUE Steffen Klassert
2026-12-01 12:41 ` [PATCH 13/22] xfrm: iptfs: force a dst reference before queueing an skb Steffen Klassert
2026-12-01 13:36 ` bot+bpf-ci
2026-12-01 12:41 ` [PATCH 14/22] xfrm: espintcp: select receive path by skb protocol Steffen Klassert
2026-12-01 12:41 ` [PATCH 15/22] net: xfrm: interface: restore dst_orig on every xfrm interface Steffen Klassert
2026-12-02 13:12 ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 16/22] xfrm: iptfs: make room before copying a continuation in reassembly Steffen Klassert
2026-12-01 12:41 ` [PATCH 17/22] xfrm/compat: pass on the translated length of a socket policy Steffen Klassert
2026-12-01 12:41 ` [PATCH 18/22] xfrm: Give GC list nodes their own storage Steffen Klassert
2026-12-02 13:12 ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 19/22] xfrm: Serialize device state teardown Steffen Klassert
2026-12-02 13:12 ` netdev-bot+sashiko
2026-12-03 7:24 ` Steffen Klassert
2026-12-01 12:41 ` [PATCH 20/22] xfrm: Wait for an RCU grace period before freeing device state Steffen Klassert
2026-12-02 13:12 ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 21/22] Revert "xfrm: serialize state GC with device state flush" Steffen Klassert
2026-12-02 13:12 ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 22/22] xfrm: Serialize offload stats updates with x->lock Steffen Klassert
2026-12-02 16:06 ` [PATCH 0/22] pull request (net): ipsec 2026-12-01 Paolo Abeni
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=axEVVoLfGtxH8hI-@gauss4 \
--to=steffen.klassert@secunet.com \
--cc=cratiu@nvidia.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=kuba@kernel.org \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
/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