🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24062

Re: [PATCH ipsec] xfrm: policy: avoid an undefined shift when testing the auth algorithm

#24062
From: netdev-bot+sashiko
Date: Sun, 29 Nov 2026 05:57
97 lines
11874 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

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).

- [Medium] On x86 and arm64, this patch changes which inbound digest_null
  SAs pass the policy template check, and the commit message does not…

--

xfrm: policy: avoid an undefined shift when testing the auth algorithm

This commit adds a range check to xfrm_state_ok() before the template's
32-bit aalgos mask is shifted by x->props.aalgo. With the check,
digest_null's ID (SADB_X_AALG_NULL, 251) no longer triggers a UBSAN
shift-out-of-bounds report. An auth algorithm ID that does not fit in the
mask is now treated as not set.

> diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
> index d2e938d4db9aa..b980d915a24a6 100644
> --- a/net/xfrm/xfrm_policy.c
> +++ b/net/xfrm/xfrm_policy.c
> @@ -3396,7 +3396,9 @@ xfrm_state_ok(const struct xfrm_tmpl *tmpl, const struct xfrm_state *x,
>  		(x->id.spi == tmpl->id.spi || !tmpl->id.spi) &&
>  		(x->props.reqid == tmpl->reqid || !tmpl->reqid) &&
>  		x->props.mode == tmpl->mode &&
> -		(tmpl->allalgs || (tmpl->aalgos & (1<<x->props.aalgo)) ||
> +		(tmpl->allalgs ||
> +		 (x->props.aalgo < BITS_PER_TYPE(tmpl->aalgos) &&
> +		  (tmpl->aalgos & (1U << x->props.aalgo))) ||

[Severity: Medium]
On x86 and arm64, does this change which inbound digest_null SAs pass the
template check?

Take a template installed through XFRM_MSG_NEWPOLICY with aalgos set to
0xffffffff and a restricted ealgos or calgos. copy_templates() in
net/xfrm/xfrm_user.c sets allalgs only when all three masks are ~0:

    t->allalgs = !~(t->aalgos & t->ealgos & t->calgos);

In that case allalgs is 0. For AH/ESP/COMP the aalgos clause then decides
the result.

Before this patch, 1<<251 was a hardware shift. x86 SHL and arm64 LSL take
the count modulo 32, so the code tested bit 27. That bit is set in ~0, so
the digest_null SA matched.

With the new guard, x->props.aalgo < BITS_PER_TYPE(tmpl->aalgos) is false.
The clause is then false even though the template allows every auth
algorithm. xfrm_policy_ok() finds no matching template, and the inbound
packets are dropped as XfrmInTmplMismatch:

xfrm_policy_ok() {
    ...
	if (xfrm_state_ok(tmpl, sp->xvec[idx], family, if_id))
		return ++idx;
    ...
}

The output path doesn't look at aalgos or allalgs. The same policy would
still send with the digest_null SA but refuse its inbound packets.

After this change, no aalgos value can admit digest_null unless all three
masks are ~0. Could tmpl->aalgos == ~0U also be treated as allowing any
aalgo? That would still avoid the out-of-range shift and would keep the
"all auth algorithms" meaning.

The commit message says only that an out-of-range ID is treated "as not
set". The note about this behaviour change sits below the --- line, so it
won't reach git history:

  Until now the result for ID 251 depended on the CPU: x86 and arm64
  mask the shift count and test bit 27; 32-bit ARM, PowerPC and s390
  give 0, which this patch makes the rule everywhere.

The same section also says:

  No functional change is intended beyond the UBSAN report

That doesn't match the x86/arm64 behaviour described above. Since the
Fixes: tag makes an automatic stable backport likely, could the commit
message itself state the behaviour change, whichever semantic is chosen?

>  		 !(xfrm_id_proto_match(tmpl->id.proto, IPSEC_PROTO_ANY))) &&
>  		!(x->props.mode != XFRM_MODE_TRANSPORT &&
>  		  xfrm_state_addr_cmp(tmpl, x, family)) &&

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/928a3d63-eb17-4192-8952-a9a74a89c5f9%40mid.andrii.net
Technical Details
Message-ID: <179593186284.3146.17226586054560246501@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373384-linux-kernel-netdev=dewy.ru
References: <928a3d63-eb17-4192-8952-a9a74a89c5f9@mid.andrii.net>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373384-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH ipsec] xfrm: policy: avoid an undefined shift when testing
 the auth algorithm
Date: Sun, 29 Nov 2026 05:57:42 +0000
Organization: Usenet Network
Message-ID: <179593186284.3146.17226586054560246501@kernel.org>
References: <928a3d63-eb17-4192-8952-a9a74a89c5f9@mid.andrii.net>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1113468"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:tMWpCoATZHzKRY6ohXaBTiWrt1c= sha256:JV42Ly6HA40YxVhMakPqIr6+7aj330X3ZLE52NsZm0Q=
	sha1:M1kzOh3WOthZQd9AiIrce9062fs= sha256:fYqcmTWrQHTcz8JEm78Fd13pAhlX0NdsK+JzzQx5tDg=
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 5DA19125F8A; Sun, 29 Nov 2026 08:58:06 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.5
X-Spam-Status: No, score=-3.5 tagged_above=-9999 required=6.31
	tests=[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 4B_grRxNYhWz;
	Sun, 29 Nov 2026 08:57:58 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-373384-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 31AFF125F93; Sun, 29 Nov 2026 08:57:49 +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 2F8AE26374; Sun, 29 Nov 2026 05:57:46 +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=1795931865;
	b=gJoURKw8txR8lclkbQYA/S4OQzR6IUM76pKRG06+YtZvh9hIzESpUHFBRQxxiVJnvNRW
	 PI/1nb7Menh360uqRfqBxie+hZJ7TIJ6rypWsA43uyX3Uy1/X+Z6aJVR6zn2MnIs9YNXz
	 cns21ZROKQFeiltVB7U4bdH/qgT7Yir6nDGETwn3URVlZblcgGi25uSTzyrggJNRovCxE
	 uwMqaoUijTpzonSj+4RPASFylizrWuzm3KZBg2vhf7K2BkRaqjZHYRrJGaV6aLPaqFej7
	 ZXBS5cXlTAf4IjOaSpPSWFKYU5alazYlHr5Mdmf6hjxvfspU3gG4qoVOIF/+GUYsWLw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795931865;
	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=v9b8cGzI1ntiCtO1Hcyll140tPvmbF+VPoWMFHTZMAc=;
	b=UxEjIb4g72orDi7hY42tS22JgCtqMOjzNyTqOH891zu8Rl1zBmxvMBIyxvRvkdkGtRBm
	 OdQlHUkqArMvY9ptXC07nyWueve4wmqj2B+DNbU+RM9w6A6MBnAwFCVKXy1/vqeddLVsM
	 d77MFKtK9qg7kA4sPUOxJp5u73IAi1UyLDJORsDEjXaIAmfSdi2+1quRg7JjWYFF+ViRS
	 LAom9FOMLLvqu7NvF33aoOAM8ZDtxOturfALNVUygxi/kNP6vuqPr2QbURSLK3VMPO9FC
	 RDcmBHrJZmstP917D67QYgYqdtwutDBTWLo9Ml0yWmVnxKebMSabxmYkVVR1ge9nYQA==
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="oNHgD/R+";
	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 47855606A330;
	Sun, 29 Nov 2026 05:57:45 +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=oNHgD/R+
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=1795931864;
	b=Z+/FVmoKYlKtQFo3UjXnCImjNRd9HwAJnyK1/9I21vESFNxUTYVrD+f0l4lcLh2OQiMB
	 +xx370LMmg81uNFneFYBth/e50nHgQLztj+0rSbJC/4YKeB0qW0+w96V+r1eDx20N8+MT
	 upRadBFBlheybIBeQUZI5Hs0BdG88ngBcBU5sHFBk1SUK7hH0IoBor3mKOvi8JHdCHPrn
	 LA4UHLEvIBycOkLxwnp/UY/qBArwD25gtwl2k6QAzMjXy9fph1GE3TmNbDVfrTNd2f9bA
	 8VvH8Kc3iQv+Sh/h+LRBEqQwNKcOOjUBRBymvQH5kAt2E4T1uC1oZ1cg0iF4yhtU2BA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795931864;
	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=v9b8cGzI1ntiCtO1Hcyll140tPvmbF+VPoWMFHTZMAc=;
	b=VQlaZCkOH1oK0UPi//2OHW1xaE+yjULMmH4rB62ikonzyhdSCyS0X24VQ8BrQgXcgDlu
	 o9bOqNqqzs7m25sswjIyVXZKCbtu2s/JJsUcgiRcFGxnjeCQ1KnQUMj9nMIT0V0lBW5ty
	 LyGO1DZRsJ6YnrCVNneFg+H0Fo1DQXaXS36OOnjA6ilPgQnj5yuNnPKIPM+eJXm81gXll
	 SHYlYnWhxIml+/fUbaQgb2/628u1VPJB4EGaSqZeOyQqImGmUPbaQcwaeznLD9aiBjhDK
	 exRocJsSAJGmtvNjZAjCeYosCwmy3Usdz4mu2rnON8JKTKSnBN4tKkHwOj54rBYVeFQ==
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="oNHgD/R+";
	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 66F97606A31C;
	Sun, 29 Nov 2026 05:57:44 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51E841F00896;
	Sun, 29 Nov 2026 05:57:43 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795931864;
	bh=v9b8cGzI1ntiCtO1Hcyll140tPvmbF+VPoWMFHTZMAc=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=oNHgD/R+MiMpNqZmzGwOynVO2ZqJHdSrQi3aFbZesTls0ciHVeW4Fxd/n9Offmn21
	 U438h16hXHgCJnlbVjygc9apIUmzVfjpVdbgisAzzclA9dB2OBX/lJUMFL2AZo8pC3
	 tAsnrSbv4/ROE+BMBNfuQajRxLH/soKAq4TQDVjKJxJ54f71DCa1hoqcJ+8+Q/Kd+a
	 XFGf0X/DzU+nzGgf1llOHFIKy9s51sePrP2NdBjbl6OSDxdxazPfSFMf0SgFUnhson
	 p3/wEhN/9saANhL4nEO6mJEUUJQ11OuqLAkrCNE4xCvUhfgM/yC6xJIB3MEU5nQAiD
	 zCnYvaUWrECPA==
X-Cc: steffen.klassert@secunet.com, herbert@gondor.apana.org.au,
 davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 horms@kernel.org, willemb@google.com, netdev@vger.kernel.org,
 ipsec@lists.linux.dev, linux-kernel@vger.kernel.org,
 syzkaller@googlegroups.com
X-In-Reply-To: <928a3d63-eb17-4192-8952-a9a74a89c5f9@mid.andrii.net>
X-sashiko-severity: Medium
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