๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26180

Re: [PATCH 09/22] xfrm: replay: Fix late packet handling with ESN crypto offload

#26180
From: Steffen Klassert
Date: Thu, 03 Dec 2026 07:08
158 lines
15750 bytes
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
Technical Details
Message-ID: <axEVVoLfGtxH8hI-@gauss4>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376358-linux-kernel-netdev=dewy.ru
References: <20261201124252.1163254-10-steffen.klassert@secunet.com> <179621714787.3146.10847263595723444158@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376358-linux-kernel-netdev=dewy.ru
From: steffen.klassert@secunet.com (Steffen Klassert)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH 09/22] xfrm: replay: Fix late packet handling with ESN
 crypto offload
Date: Thu, 3 Dec 2026 08:08:06 +0100
Organization: Usenet Network
Message-ID: <axEVVoLfGtxH8hI-@gauss4>
References: <20261201124252.1163254-10-steffen.klassert@secunet.com>
 <179621714787.3146.10847263595723444158@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2396471"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:p89Uqs8TBp/M2kbiKFkEJ8fMYEM= sha256:jJLL1cJjW/2E3oYtjXGba37PnJTyFTIS9sieA+enps0=
	sha1:AKgfBp4OixTmTyphywATazv14CU= sha256:tSXI/kwh1XoAaXJGVbrSb1fu+xseYJDspG7A9S0G2Uk=
Content-Disposition: inline
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 BBFD1117857; Thu,  3 Dec 2026 10:08:30 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.051
X-Spam-Status: No, score=-3.051 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] 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 NEEW4gEn_owD;
	Thu,  3 Dec 2026 10:08:25 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376358-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id C08FB117859; Thu,  3 Dec 2026 10:08:15 +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 1B05E25053; Thu,  3 Dec 2026 07:08:14 +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=1796281694;
	b=vywBMALUJ2+SjMFurFxnQosg5rZ7ypHnhD2TsGZaY3avGuysvWFEqSd323zVB9h5MFsK
	 nwio2bU0lwORBVE1LV7Rs6rsAcbhDptdBQ6edNTk1xafyKZkZVTb/LJIFU6k8mMMxI4kv
	 ckgn+zyZDUn6norK8c5aUDfLsF0GA5Mkzrac13zmJt+++VzLaRq5ljVEDwUdA7KpYh4Su
	 seasDfL7NMf67eZZ1aGziypZRvyw8whgAhrqzYJiwAraNIrlV27UeTzDt4cU2Bmmef2R6
	 L2vOta+TdOskx4NWakDtveNlV6cB7Hrwx2dOwGKgF3GP4MuXmBAHVFqNezLqWHfLJ6w==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796281694;
	h=X-Original-To:Received:DMARC-Filter:Received:X-Virus-Scanned:
	 Received:Received:DKIM-Filter:DKIM-Signature:Received:Received:Date:
	 From:To:CC:Subject:Message-ID:References:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:Content-Type:Content-Disposition:
	 Content-Transfer-Encoding:In-Reply-To:X-ClientProxiedBy;
	bh=FA2IUtN4fgWuk0jPXPEmYb7CWybM37U+KjdRLpfvy04=;
	b=A4FFFJ+Fmtb91LsyrWJgNyJnwchkRSAz2GjFUjnWoyJAsOHO5ItedYbeWQFcHZzLxPIv
	 TfHVYY9QsyxlYnklhXqOnG2QEC9Ud5doik1DABLmFXHIxgAK7VgB08R5rNBCUOIuMygQu
	 GVg2ot74k+ZvNbOBM4Zs6GtGj9QoIRIi/qBCUHkiOdjpQPqb/5nZtLJgpf2dVPwA1SJCX
	 utNfIGl3pzeogan8Pe5n+rh1MRFmLC2OUkLGc+OGYwVGSomOHBq6B6HnJhX98FI2Yzb8N
	 C1uta39Us7J17GQDWL5vRamtg8g4OvJtx+uygBUPw+EUAJmEPDT41VN/aRpyuR4Wdzw==
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=SZxtUBIK;
	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 E69B4606A333;
	Thu,  3 Dec 2026 07:08:13 +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=SZxtUBIK
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=1796281693;
	b=yZjC+dmqAw/yfZD3UCkzcUUnvwtkFi/iJkCg1x4rZhNyxJRy4h2eU77/hZijyzPI808O
	 SM6J+14pfIY4DOMjXjc1ppdgqFHNL/kqa+HRqjURi3+AGTHKolKTkyC8Pk1BKjn4L/Ugl
	 00nvjXTCiDtBfC1tDRkqNswffrG4yQfUeiRTaZSiL4/un/WF5h0gQbKy8WfhRRWAIDQdZ
	 BAekzFoLODbGleaJtU7aZh+XcbFrcjcWzJEFJ+emNsNoeYPlkHfe2qUp+B3EJeDzRqFpj
	 K35yOoJX4Q8HmtoJ+qquF93gHaHu+vo0vnnvJpp7m5rwjk+/nkHzHccnklrUTzZIk/Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796281693;
	h=DMARC-Filter:Received:X-Virus-Scanned:Received:Received:DKIM-Filter:
	 DKIM-Signature:Received:Received:Date:From:To:CC:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:
	 Content-Transfer-Encoding:In-Reply-To:X-ClientProxiedBy;
	bh=FA2IUtN4fgWuk0jPXPEmYb7CWybM37U+KjdRLpfvy04=;
	b=ox1qQU2CEk/ick2b3XDpgX+Ot5CWWdd7O5PbGGzI3zO24W97vTX0+G/O6L0MoS562tDO
	 iKKiB/DzaT6n0rcLs+yAT4q+tq5NpM59c+AdK9C04inQvmL8sAAnMIiCT7bqki6XKF0su
	 sqPLkVEY+raJqgwflfw0Zpe1cU5Zh23aAmO6g10oWAu5F0QpF9K06f0a3wvbwxjUiggJT
	 aUawF2Ljv0TbQo27azIwe9iyOeeXKJuFbLzOP8Ask/btsFNRn2yaKZsJkIC+8ch+FyOrY
	 Me1bHCgSng9nKDrgp6oWzA1ma7RsAE/y7ufEgB9+xXOoq7k/nSRtbd+Pi1OqTiq1M3A==
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=SZxtUBIK;
	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 8E32E606A32C
	for <netdev@vger.kernel.org>; Thu,  3 Dec 2026 07:08:11 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8E32E606A32C
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 932B2207BB;
	Thu,  3 Dec 2026 08:08:09 +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 MywyPb6lZo8Q; Thu,  3 Dec 2026 08:08:08 +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 883C4207B3;
	Thu,  3 Dec 2026 08:08:08 +0100 (CET)
X-DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com 883C4207B3
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com;
	s=202301; t=1796281688;
	bh=FA2IUtN4fgWuk0jPXPEmYb7CWybM37U+KjdRLpfvy04=;
	h=Date:From:To:CC:Subject:References:In-Reply-To:From;
	b=SZxtUBIKqlfas7vN8mWhK2ZIgX1C94pHudTKdecqjKjuvYBiXJ7FhH3gVqx6mx3Li
	 hSOCYKSongsqJYDo/WYZu+vb5AtoIjX4UvapPnkaOIfGRAZwaU2CTlOZK/q6YF2me9
	 0e/INmbfc0Ii3d2fvv3mhHLaZBjnL5kCG0jvVyroCRgqIMf0W/h8BPYKMxKk79kzxg
	 NvnnrJsQyiM+Qo8HPeVSUO0vUgz5tXyf3oCEVQMYnrwCU1qu2Q6i68ihKjqEnVJjW2
	 JwteNyr4zi6T+QoVZ8BsfSoBhEAuxcoontpWBWB8z412cveqXU/D/i762ZUM4anFvA
	 6FpoD6bwu0WVQ==
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; Thu, 3 Dec
 2026 08:08:07 +0100
X-Received: (nullmailer pid 1000925 invoked by uid 1000);
	Thu, 03 Dec 2026 07:08:07 -0000
X-CC: <davem@davemloft.net>, <kuba@kernel.org>, <herbert@gondor.apana.org.au>,
	<netdev@vger.kernel.org>, Cosmin Ratiu <cratiu@nvidia.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-In-Reply-To: <179621714787.3146.10847263595723444158@kernel.org>
X-ClientProxiedBy: EXCH-04.secunet.de (10.32.0.184) To EXCH-01.secunet.de
 (10.32.0.171)