From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51E841F00896; Sun, 29 Nov 2026 05:57:43 +0000 (UTC) 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== Subject: Re: [PATCH ipsec] xfrm: policy: avoid an undefined shift when testing the auth algorithm From: netdev-bot+sashiko@kernel.org To: opensource@andrii.net 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 Date: Sun, 29 Nov 2026 05:57:42 +0000 Message-ID: <179593186284.3146.17226586054560246501@kernel.org> In-Reply-To: <928a3d63-eb17-4192-8952-a9a74a89c5f9@mid.andrii.net> References: <928a3d63-eb17-4192-8952-a9a74a89c5f9@mid.andrii.net> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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<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