mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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
Subject: Re: [PATCH ipsec] xfrm: policy: avoid an undefined shift when testing the auth algorithm
Date: Sun, 29 Nov 2026 05:57:42 +0000	[thread overview]
Message-ID: <179593186284.3146.17226586054560246501@kernel.org> (raw)
In-Reply-To: <928a3d63-eb17-4192-8952-a9a74a89c5f9@mid.andrii.net>

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

      reply	other threads:[~2026-11-29  5:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  5:38 Andrii Tereshchenko
2026-11-29  5:57 ` netdev-bot+sashiko [this message]

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=179593186284.3146.17226586054560246501@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=ipsec@lists.linux.dev \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=opensource@andrii.net \
    --cc=pabeni@redhat.com \
    --cc=steffen.klassert@secunet.com \
    --cc=syzkaller@googlegroups.com \
    --cc=willemb@google.com \
    /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

all inboxes | Powered by JetHome®