Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alex Ousherovitch" <aousherovitch@rambus.com>,
	"Saravanakrishnan Krishnamoorthy" <skrishnamoorthy@rambus.com>,
	"Joel Wittenauer" <Joel.Wittenauer@cryptography.com>,
	"Thi Nguyen" <thin@rambus.com>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Randy Dunlap" <rdunlap@infradead.org>
Cc: linux-crypto@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v8 4/5] crypto: cmh - add AES skcipher/aead/cmac
Date: Tue, 10 Nov 2026 18:18:53 +0000	[thread overview]
Message-ID: <sashiko-outbox-207570@kernel.org> (raw)
In-Reply-To: <20261110-cmh-b4-a-v8-v8-4-4cea8ebc1d40@rambus.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Critical] crypto: cmh: stack overflow in ahash_request_zero() via
  missing tfm->fb
- [Medium] crypto: cmh: missing CRYPTO_ALG_ASYNC mask in
  cmh_aes_aead_init_tfm()
--

commit 89559a30a0ea6b4fc4382fe41b13de31385e0958
Author: Alex Ousherovitch <aousherovitch@rambus.com>

crypto: cmh - add AES skcipher/aead/cmac

This commit registers AES skcipher (ECB, CBC, CTR, XTS), AEAD (GCM, CCM),
and ahash (CMAC) algorithms on the CMH AES core, along with the AES core
ABI definitions.

> diff --git a/drivers/crypto/cmh/cmh_aes_aead.c b/drivers/crypto/cmh/cmh_aes_aead.c
> new file mode 100644
> index 0000000000000..7edacf38198bf
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_aes_aead.c

[ ... ]

> +static int cmh_aes_aead_init_tfm(struct crypto_aead *tfm)
> +{
> +	struct cmh_aes_aead_tfm_ctx *tctx = crypto_aead_ctx(tfm);
> +	const struct cmh_aes_aead_info *info = cmh_aes_aead_get_info(tfm);
> +
> +	memset(tctx, 0, sizeof(*tctx));
> +	tctx->authsize = info->maxauthsize;
> +
> +	if (info->type == CMH_AES_AEAD_CCM) {
> +		struct crypto_aead *fb;
> +
> +		tctx->ccm = true;
> +		fb = crypto_alloc_aead("ccm(aes)", 0,
> +				       CRYPTO_ALG_NEED_FALLBACK);

[Severity: Medium]
Does this fallback allocation need CRYPTO_ALG_ASYNC in the mask so that
ccm(aes) does not wrap rambus-cmh-ctr-aes?

On architectures where ccm-aes-lib is not registered (such as arm64 and
arm), allocating ccm(aes) instantiates the ccm template via
crypto_ccm_create_common(), which grabs ctr(aes) using the passed mask.
Because cmh_aes_register() has already registered rambus-cmh-ctr-aes at
priority 300, the fallback ends up running CTR on the CMH hardware via
bounce buffers and rejecting requests over 32 MiB with -EINVAL, rather
than using a software implementation with no size limit as documented.

> diff --git a/drivers/crypto/cmh/cmh_aes_cmac.c b/drivers/crypto/cmh/cmh_aes_cmac.c
> new file mode 100644
> index 0000000000000..34a7a5ba07baf
> --- /dev/null
> +++ b/drivers/crypto/cmh/cmh_aes_cmac.c

[ ... ]

> +static int cmh_aes_cmac_init_tfm(struct crypto_ahash *tfm)
> +{
> +	struct cmh_aes_cmac_tfm_ctx *tctx = crypto_ahash_ctx(tfm);
> +	struct crypto_ahash *fb;
> +
> +	tctx->key.mode = CMH_KEY_NONE;
> +
> +	/*
> +	 * The generic cmac(aes) shash has no export_core, so the crypto
> +	 * core cannot wrap it as crypto_ahash_fb().  Allocate it here
> +	 * instead; masking out CRYPTO_ALG_ASYNC excludes this (async)
> +	 * driver so the allocator picks the generic, synchronous transform,
> +	 * and its request is embedded after the reqctx.
> +	 */
> +	fb = crypto_alloc_ahash(crypto_ahash_alg_name(tfm), 0,
> +				CRYPTO_ALG_ASYNC);
> +	if (IS_ERR(fb))
> +		return PTR_ERR(fb);
> +	tctx->fb = fb;
> +
> +	crypto_ahash_set_reqsize(tfm,
> +				 sizeof(struct cmh_aes_cmac_reqctx) +
> +				 crypto_tfm_ctx_alignment() +
> +				 sizeof(struct ahash_request) +
> +				 crypto_ahash_reqsize(fb));
> +	crypto_ahash_set_statesize(tfm, crypto_ahash_statesize(fb));
> +	return 0;
> +}

[Severity: Critical]
Can leaving crypto_ahash_tfm(tfm)->fb pointing to the async CMH transform
overflow the kernel stack when a caller uses crypto_hash_digest() or
HASH_FBREQ_ON_STACK()?

Because cmh_aes_cmac_alg sets CRYPTO_ALG_NO_FALLBACK,
crypto_create_tfm_node() leaves tfm->fb pointing to tfm itself, while
cmh_aes_cmac_init_tfm() sets tfm's reqsize to over 800 bytes above
MAX_SYNC_HASH_REQSIZE:

crypto/ahash.c:crypto_hash_digest() {
	HASH_REQUEST_ON_STACK(req, crypto_ahash_fb(tfm));
	int err;

	ahash_request_set_callback(req, 0, NULL, NULL);
	ahash_request_set_virt(req, data, out, len);
	err = crypto_ahash_digest(req);

	ahash_request_zero(req);

	return err;
}

HASH_REQUEST_ON_STACK() reserves only sizeof(struct ahash_request) +
MAX_SYNC_HASH_REQSIZE bytes on the stack and binds req to
crypto_ahash_fb(tfm) (still the CMH tfm).  crypto_ahash_digest() then
returns -EAGAIN because an on-stack request is used with an async
transform, and ahash_request_zero() zeroes sizeof(*req) +
crypto_ahash_reqsize(tfm) bytes, writing over 800 bytes past the stack
buffer.

Pointing crypto_ahash_tfm(tfm)->fb at crypto_ahash_tfm(fb) (and restoring
it before freeing fb in cmh_aes_cmac_exit_tfm()) would direct stack
requests to the synchronous fallback transform.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261110-cmh-b4-a-v8-v8-0-4cea8ebc1d40@rambus.com?part=4

  reply	other threads:[~2026-11-10 18:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 16:52 [PATCH v8 0/5] crypto: cmh - add Rambus CryptoManager Hub core driver and AES Alex Ousherovitch via B4 Relay
2026-11-10 16:52 ` [PATCH v8 1/5] dt-bindings: crypto: add Rambus CryptoManager Hub Alex Ousherovitch via B4 Relay
2026-11-10 17:20   ` sashiko-bot
2026-11-10 16:52 ` [PATCH v8 2/5] crypto: cmh - add core platform driver Alex Ousherovitch via B4 Relay
2026-11-10 17:50   ` sashiko-bot
2026-11-10 16:52 ` [PATCH v8 3/5] crypto: cmh - add key/datastore infrastructure Alex Ousherovitch via B4 Relay
2026-11-10 16:52 ` [PATCH v8 4/5] crypto: cmh - add AES skcipher/aead/cmac Alex Ousherovitch via B4 Relay
2026-11-10 18:18   ` sashiko-bot [this message]
2026-11-10 16:52 ` [PATCH v8 5/5] MAINTAINERS: add Rambus CryptoManager Hub (CMH) Alex Ousherovitch via B4 Relay

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-207570@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Joel.Wittenauer@cryptography.com \
    --cc=aousherovitch@rambus.com \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=krzk+dt@kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=skhan@linuxfoundation.org \
    --cc=skrishnamoorthy@rambus.com \
    --cc=thin@rambus.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