Linux cryptographic layer development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Danny Tsen" <dtsen@linux.ibm.com>, linux-crypto@vger.kernel.org
Cc: herbert@gondor.apana.org.au, leitao@debian.org,
	nayna@linux.ibm.com, appro@cryptogams.org, mpe@ellerman.id.au,
	ltcgcw@linux.vnet.ibm.com, dtsen@us.ibm.com
Subject: Re: [PATCH] crypto: powerpc/p10-aes-gcm - Fix IPsec stall on bond failover
Date: Fri, 20 Nov 2026 16:02:58 +0000	[thread overview]
Message-ID: <sashiko-outbox-225520@kernel.org> (raw)
In-Reply-To: <20261120150856.7039-1-dtsen@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Critical] crypto: p10-aes-gcm - unchecked key memcpy overflow in
  p10_aes_gcm_setkey()
- [High] crypto: p10-aes-gcm - missing fallback authsize update in
  set_authsize()
- [High] crypto: p10-aes-gcm - uninitialized fallback subreq in
  p10_aes_gcm_crypt()
- [Medium] crypto: p10-aes-gcm - missing CRYPTO_ALG_ASYNC mask in
  p10_aead_init()
- [Medium] crypto: p10-aes-gcm - missing CRYPTO_GCM select for
  CRYPTO_AES_GCM_P10
--

commit 0ea59836db10f05695eb5711fdb48763c557e6c5
Author: Danny Tsen <dtsen@linux.ibm.com>

crypto: powerpc/p10-aes-gcm - Fix IPsec stall on bond failover

This commit replaces the crypto SIMD wrapper registration for Power10
AES-GCM with direct aead_alg registration and synchronous fallback
transforms for requests that cannot use VSX or have cryptlen < 64.

> diff --git a/arch/powerpc/crypto/aes-gcm-p10-glue.c b/arch/powerpc/crypto/aes-gcm-p10-glue.c
> index f3417436d3f79..13352b838432d 100644
> --- a/arch/powerpc/crypto/aes-gcm-p10-glue.c
> +++ b/arch/powerpc/crypto/aes-gcm-p10-glue.c
[ ... ]
> @@ -173,6 +177,40 @@ static void finish_tag(struct gcm_ctx *gctx, struct Hash_ctx *hash, int len)
>  		hash->Htable[i] ^= gctx->ivtag[i];
>  }
>  
> +static int p10_aead_init(struct crypto_aead *tfm)
> +{
> +	struct p10_aes_gcm_ctx *ctx = crypto_aead_ctx(tfm);
> +
> +	ctx->fallback_tfm = crypto_alloc_aead("gcm(aes)", 0, CRYPTO_ALG_NEED_FALLBACK);
> +	if (IS_ERR(ctx->fallback_tfm))
> +		return PTR_ERR(ctx->fallback_tfm);
> +
> +	crypto_aead_set_reqsize(tfm, sizeof(struct aead_request) +
> +				crypto_aead_reqsize(ctx->fallback_tfm));
> +	return 0;
> +}
> +
> +static int rfc4106_init(struct crypto_aead *tfm)
> +{
> +	struct p10_aes_gcm_ctx *ctx = crypto_aead_ctx(tfm);
> +
> +	ctx->fallback_tfm = crypto_alloc_aead("rfc4106(gcm(aes))", 0, CRYPTO_ALG_NEED_FALLBACK);
> +	if (IS_ERR(ctx->fallback_tfm))
> +		return PTR_ERR(ctx->fallback_tfm);
> +
> +	crypto_aead_set_reqsize(tfm, sizeof(struct aead_request) +
> +				crypto_aead_reqsize(ctx->fallback_tfm));
> +	return 0;
> +}

[Severity: Medium]
Should p10_aead_init() and rfc4106_init() pass
CRYPTO_ALG_NEED_FALLBACK | CRYPTO_ALG_ASYNC as the mask to
crypto_alloc_aead()?

gcm_aes_algs[] registers synchronous AEAD algorithms without
CRYPTO_ALG_ASYNC, so if an asynchronous implementation with higher
priority than the generic fallback is bound to ctx->fallback_tfm, it can
return -EINPROGRESS or -EBUSY to callers expecting synchronous completion.

[Severity: Medium]
Should CRYPTO_AES_GCM_P10 in arch/powerpc/crypto/Kconfig also select
CRYPTO_GCM and CRYPTO_AES now that p10_aead_init() and rfc4106_init()
unconditionally allocate fallback gcm(aes) and rfc4106(gcm(aes))
transforms?

On powerpc, the library-based gcm-aes-lib AEAD registrations in
crypto/aes.c are disabled under !CONFIG_PPC, so transform initialization
fails with -ENOENT when CONFIG_CRYPTO_GCM or CONFIG_CRYPTO_AES is not
enabled.

> +
> +static void p10_aead_exit(struct crypto_aead *tfm)
> +{
> +	struct p10_aes_gcm_ctx *ctx = crypto_aead_ctx(tfm);
> +
> +	if (ctx->fallback_tfm)
> +		crypto_free_aead(ctx->fallback_tfm);
> +}
> +
>  static int set_authsize(struct crypto_aead *tfm, unsigned int authsize)
>  {
>  	switch (authsize) {
> @@ -194,13 +232,34 @@ static int set_authsize(struct crypto_aead *tfm, unsigned int authsize)
>  static int p10_aes_gcm_setkey(struct crypto_aead *aead, const u8 *key,
>  			      unsigned int keylen)
>  {
> -	struct crypto_tfm *tfm = crypto_aead_tfm(aead);
> -	struct p10_aes_gcm_ctx *ctx = crypto_tfm_ctx(tfm);
> +	struct p10_aes_gcm_ctx *ctx = crypto_aead_ctx(aead);
> +	int ret = 0;
> +
> +	ctx->simd_set_key = 0;
> +	if (crypto_simd_usable()) {
> +		vsx_begin();
> +		ret = aes_p10_set_encrypt_key(key, keylen * 8, &ctx->enc_key);
> +		vsx_end();
> +		ctx->simd_set_key = 1;
> +		if (ret)
> +			ctx->simd_set_key = 0;
> +	}
> +
> +	ctx->keylen = keylen;
> +	memcpy(ctx->key, key, keylen);
> +
> +	return ret ? -EINVAL : 0;
> +}
> +
> +static int gcm_setkey(struct crypto_aead *aead, const u8 *key,
> +		      unsigned int keylen)
> +{
> +	struct p10_aes_gcm_ctx *ctx = crypto_aead_ctx(aead);
>  	int ret;
>  
> -	vsx_begin();
> -	ret = aes_p10_set_encrypt_key(key, keylen * 8, &ctx->enc_key);
> -	vsx_end();
> +	ret = p10_aes_gcm_setkey(aead, key, keylen);
> +
> +	ret |= crypto_aead_setkey(ctx->fallback_tfm, key, keylen);
>  
>  	return ret ? -EINVAL : 0;
>  }

[Severity: Critical]
Can memcpy(ctx->key, key, keylen) in p10_aes_gcm_setkey() overflow
ctx->key[AES_MAX_KEYLENGTH]?

gcm_setkey() calls p10_aes_gcm_setkey() before crypto_aead_setkey()
validates keylen, and p10_aes_gcm_setkey() copies keylen bytes even when
aes_p10_set_encrypt_key() fails or is skipped.  An unprivileged user can
pass keylen > 240 via setsockopt(ALG_SET_KEY) on an AF_ALG socket bound to
gcm(aes) and write past ctx->key in struct p10_aes_gcm_ctx.  ctx->key and
ctx->keylen are also never read anywhere in this driver and can be dropped.

> @@ -208,8 +267,8 @@ static int p10_aes_gcm_setkey(struct crypto_aead *aead, const u8 *key,
>  static int p10_aes_gcm_crypt(struct aead_request *req, u8 *riv,
>  			     int assoclen, int enc)
>  {
> -	struct crypto_tfm *tfm = req->base.tfm;
> -	struct p10_aes_gcm_ctx *ctx = crypto_tfm_ctx(tfm);
> +	struct crypto_aead *tfm = crypto_aead_reqtfm(req);
> +	struct p10_aes_gcm_ctx *ctx = crypto_aead_ctx(tfm);
>  	u8 databuf[sizeof(struct gcm_ctx) + PPC_ALIGN];
>  	struct gcm_ctx *gctx = PTR_ALIGN((void *)databuf, PPC_ALIGN);
>  	u8 hashbuf[sizeof(struct Hash_ctx) + PPC_ALIGN];
> @@ -220,12 +279,24 @@ static int p10_aes_gcm_crypt(struct aead_request *req, u8 *riv,
>  	unsigned int cryptlen = req->cryptlen;
>  	unsigned char ivbuf[AES_BLOCK_SIZE+PPC_ALIGN];
>  	unsigned char *iv = PTR_ALIGN((void *)ivbuf, PPC_ALIGN);
> -	int ret;
> -	unsigned long auth_tag_len = crypto_aead_authsize(__crypto_aead_cast(tfm));
> +	int ret = 0;
> +	unsigned long auth_tag_len = crypto_aead_authsize(tfm);
>  	u8 otag[16];
>  	int total_processed = 0;
>  	int nbytes;
>  
> +	if (!crypto_simd_usable() || !ctx->simd_set_key || req->cryptlen < 64) {
> +		struct aead_request *subreq = aead_request_ctx(req);
> +
> +		aead_request_set_tfm(subreq, ctx->fallback_tfm);
> +		aead_request_set_crypt(subreq, req->src, req->dst,
> +					req->cryptlen, req->iv);
> +		aead_request_set_ad(subreq, req->assoclen);
> +
> +		return enc ? crypto_aead_encrypt(subreq) :
> +			     crypto_aead_decrypt(subreq);
> +	}

[Severity: High]
Does the fallback path use the wrong tag size when authsize is configured
to less than 16 bytes?

Neither set_authsize() nor rfc4106_setauthsize() calls
crypto_aead_setauthsize(ctx->fallback_tfm, authsize), so
ctx->fallback_tfm->authsize stays at 16.  When a transform configured with
a shorter tag (such as 8 or 12 bytes) takes the fallback path, encryption
writes a 16-byte tag past the caller's tag buffer (or walks off the end of
req->dst) and decryption fails with -EINVAL or -EBADMSG.

[Severity: High]
Does the fallback path leave subreq->base.flags, subreq->base.complete,
and subreq->base.data uninitialized by not calling
aead_request_set_callback()?

crypto_gcm_encrypt() and crypto_gcm_decrypt() read aead_request_flags(req)
and forward it to the underlying skcipher request.  When
p10_aes_gcm_crypt() falls back in softirq context (or during crypto
self-tests, where testmgr poisons the request context with 0xfe) and
CRYPTO_TFM_REQ_MAY_SLEEP happens to be set in subreq->base.flags, the
skcipher walk can perform GFP_KERNEL allocations and call cond_resched() in
atomic context.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120150856.7039-1-dtsen@linux.ibm.com?part=1

      reply	other threads:[~2026-11-20 16:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 15:08 [PATCH] crypto: powerpc/p10-aes-gcm - Fix IPsec stall on bond failover Danny Tsen
2026-11-20 16:02 ` sashiko-bot [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=sashiko-outbox-225520@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=appro@cryptogams.org \
    --cc=dtsen@linux.ibm.com \
    --cc=dtsen@us.ibm.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=leitao@debian.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=ltcgcw@linux.vnet.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=nayna@linux.ibm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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