Linux cryptographic layer development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rosen Penev" <rosenp@gmail.com>,
	linux-crypto@vger.kernel.org,
	"Herbert Xu" <herbert@gondor.apana.org.au>
Cc: "Srujana Challa" <schalla@marvell.com>,
	"Bharat Bhushan" <bbhushan2@marvell.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Arnaud Ebalard" <arno@natisbad.org>,
	"Boris Brezillon" <bbrezillon@kernel.org>,
	"Russell King" <rmk+kernel@arm.linux.org.uk>,
	"Romain Perier" <romain.perier@free-electrons.com>
Subject: Re: [PATCH 8/8] crypto: cesa - finish long hashes on the non-TDMA path
Date: Sat, 28 Nov 2026 04:52:16 +0000	[thread overview]
Message-ID: <sashiko-outbox-238463@kernel.org> (raw)
In-Reply-To: <20261128044050.722617-9-rosenp@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] crypto: cesa: buffer overflow on creq->cache in
  mv_cesa_ahash_std_step()
--

commit 819442c312cc2cf884cbbf9084155d8ab97dd609
Author: Rosen Penev <rosenp@gmail.com>

crypto: cesa - finish long hashes on the non-TDMA path

This commit fixes hash finalization on the non-TDMA path for messages of
64 KiB or more by entering the manual padding block whenever the last
request's source data is consumed, carrying partial blocks across steps,
and tracking final step emission via sreq->final_issued.

> diff --git a/drivers/crypto/marvell/cesa/hash.c b/drivers/crypto/marvell/cesa/hash.c
> index b51315cd01dfa..5e867e688ffa5 100644
> --- a/drivers/crypto/marvell/cesa/hash.c
> +++ b/drivers/crypto/marvell/cesa/hash.c
[ ... ]
> @@ -221,16 +222,17 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)
>  
>  	frag_mode = mv_cesa_get_op_cfg(op) & CESA_SA_DESC_CFG_FRAG_MSK;
>  
> -	if (creq->last_req && sreq->offset == req->nbytes &&
> -	    creq->len <= CESA_SA_DESC_MAC_SRC_TOTAL_LEN_MAX) {
> +	/* All data of the last request is in SRAM: finish the hash. */
> +	final = creq->last_req && sreq->offset == req->nbytes;
> +
> +	if (final && creq->len <= CESA_SA_DESC_MAC_SRC_TOTAL_LEN_MAX) {
>  		if (frag_mode == CESA_SA_DESC_CFG_FIRST_FRAG)
>  			frag_mode = CESA_SA_DESC_CFG_NOT_FRAG;
>  		else if (frag_mode == CESA_SA_DESC_CFG_MID_FRAG)
>  			frag_mode = CESA_SA_DESC_CFG_LAST_FRAG;
>  	}
>  
> -	if (frag_mode == CESA_SA_DESC_CFG_NOT_FRAG ||
> -	    frag_mode == CESA_SA_DESC_CFG_LAST_FRAG) {
> +	if (final) {
>  		if (len &&
>  		    creq->len <= CESA_SA_DESC_MAC_SRC_TOTAL_LEN_MAX) {
>  			mv_cesa_set_mac_op_total_len(op, creq->len);
> @@ -238,8 +240,13 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)
>  			int trailerlen = mv_cesa_ahash_pad_len(creq) + 8;
>  
>  			if (len + trailerlen > CESA_SA_SRAM_PAYLOAD_SIZE) {
> -				len &= CESA_HASH_BLOCK_SIZE_MSK;
> -				new_cache_ptr = 64 - trailerlen;
> +				/*
> +				 * No room for the padding: hash the whole
> +				 * blocks now and carry the partial one over
> +				 * to the next step, which adds the padding.
> +				 */
> +				new_cache_ptr = len & CESA_HASH_BLOCK_SIZE_MSK;
> +				len &= ~CESA_HASH_BLOCK_SIZE_MSK;
>  				if (engine->pool)
>  					memcpy(creq->cache,
>  					       engine->sram_pool +
> @@ -262,15 +269,20 @@ static void mv_cesa_ahash_std_step(struct ahash_request *req)
>  						    CESA_SA_DATA_SRAM_OFFSET,
>  						    creq->cache, i);
>  				len += i;
> +				sreq->final_issued = true;
>  			}

[Severity: High]
Can mv_cesa_ahash_pad_req(creq, creq->cache) overflow creq->cache[] when
creq->len > CESA_SA_DESC_MAC_SRC_TOTAL_LEN_MAX and (creq->len & 63) >= 56?

Previously, the manual padding branch was only reachable when len == 0
and creq->len <= 0xffff, which only occurred on block-aligned lengths
where padlen + 8 is 64 bytes.  Now that long hashes enter this branch for
any remainder, a message with (creq->len & 63) in 56..63 has a padlen of
57..64 bytes, so mv_cesa_ahash_pad_req() writes 65..72 bytes (padlen plus
the 8-byte bit length) into creq->cache[CESA_MAX_HASH_BLOCK_SIZE], which
is only 64 bytes.

That overwrites the adjacent creq->cache_ptr and creq->len fields in
struct mv_cesa_ahash_req, and the subsequent memcpy() of i bytes reads
past creq->cache[] (triggering a FORTIFY_SOURCE panic when engine->pool
is used).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261128044050.722617-1-rosenp@gmail.com?part=8

      reply	other threads:[~2026-11-28  4:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28  4:40 [PATCH 0/8] crypto: cesa - fixes for the Marvell CESA driver Rosen Penev
2026-11-28  4:40 ` [PATCH 1/8] crypto: cesa - clear the IRQ affinity hint before freeing the IRQ Rosen Penev
2026-11-28  4:40 ` [PATCH 2/8] crypto: cesa - do not allow unbinding the device Rosen Penev
2026-11-28  4:40 ` [PATCH 3/8] crypto: cesa - hash the last full SRAM chunk before the padding Rosen Penev
2026-11-28  4:40 ` [PATCH 4/8] crypto: cesa - finish the HMAC outer hash when padding by hand Rosen Penev
2026-11-28  4:52   ` sashiko-bot
2026-11-28  4:40 ` [PATCH 5/8] crypto: cesa - keep the chained IV on the non-TDMA cipher path Rosen Penev
2026-11-28  4:40 ` [PATCH 6/8] crypto: cesa - put the non-TDMA hash padding behind the data Rosen Penev
2026-11-28  4:40 ` [PATCH 7/8] crypto: cesa - do not step empty hash operations on the non-TDMA path Rosen Penev
2026-11-28  4:40 ` [PATCH 8/8] crypto: cesa - finish long hashes " Rosen Penev
2026-11-28  4:52   ` 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-238463@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=arno@natisbad.org \
    --cc=bbhushan2@marvell.com \
    --cc=bbrezillon@kernel.org \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=rmk+kernel@arm.linux.org.uk \
    --cc=romain.perier@free-electrons.com \
    --cc=rosenp@gmail.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=schalla@marvell.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