mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrii Tereshchenko <opensource@andrii.net>
To: netdev-bot+sashiko@kernel.org
Cc: Steffen Klassert <steffen.klassert@secunet.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Willem de Bruijn <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 19:05:35 -0700	[thread overview]
Message-ID: <715d488f-594d-4eac-950a-1aeabdecec1e@mid.andrii.net> (raw)
In-Reply-To: <179593186284.3146.17226586054560246501@kernel.org>

Sashiko (netdev AI review) wrote:
> On x86 and arm64, does this change which inbound digest_null SAs pass the
> template check?
[...]
> 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.

Yes, it does, in one case, and "no functional change" below the --- was
wrong. The test runs only when the template does not allow all
algorithms (allalgs is 0). For a digest_null SA (SADB_X_AALG_NULL,
251), the old code tests bit 27 of aalgos on x86, where the compiled
check is a bt on a 32-bit register (bit number modulo 32, and
251 = 7 * 32 + 27), and on arm64, where the shift count is also taken
modulo 32. On 32-bit ARM, PowerPC and s390 the shift gives 0. So on x86
and arm64 a template installed with XFRM_MSG_NEWPOLICY, or as a socket
policy, with bit 27 of aalgos set (in practice aalgos = ~0) and a
restricted ealgos or calgos accepted inbound digest_null SAs, and with
this patch it refuses them. Templates from iproute2 and PF_KEY have all
three masks at ~0 (allalgs) and do not reach the shift, before or
after.

I would rather not give ~0 a meaning of its own, though:

- aalgos is a mask of algorithm IDs, bit n for ID n, and nothing in the
  UAPI or the code says ~0 means more than IDs 0 to 31. The one "any
  algorithm" the code defines is allalgs, set in copy_templates() when
  all three masks are ~0.
- digest_null was admitted by an out-of-range shift, so by bit 27,
  which names no algorithm, and only on some architectures. A template
  with any other mask that has bit 27 set admitted it too.
- af_key.c has treated an ID outside the mask as not set since
  f398035f2dec ("[IPSEC]: Avoid undefined shift operation when testing
  algorithm ID") in 2007, and 32-bit ARM, PowerPC and s390 have always
  refused it here. The patch makes x86 and arm64 do the same.
- digest_null gives no integrity protection. When a template restricts
  the algorithms, refusing an SA that no bit of the mask names is the
  safer reading; a policy that wants any algorithm, digest_null
  included, sets all three masks to ~0.

Steffen, if you want the behaviour change in the git history, I'll send
a v2 with the same code and the note moved above the --- in place of
"no functional change".

Andrii Tereshchenko

      reply	other threads:[~2026-11-30  2:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  5:38 Andrii Tereshchenko
2026-11-29  5:57 ` netdev-bot+sashiko
2026-11-30  2:05   ` Andrii Tereshchenko [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=715d488f-594d-4eac-950a-1aeabdecec1e@mid.andrii.net \
    --to=opensource@andrii.net \
    --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-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --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®