All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Praneeth Balasubramanian" <praneethb2002@gmail.com>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>
Cc: linux-crypto@vger.kernel.org
Subject: Re: [PATCH] crypto: bcm - Reject requests with too many fragments
Date: Sat, 05 Dec 2026 07:02:46 +0000	[thread overview]
Message-ID: <sashiko-outbox-251182@kernel.org> (raw)
In-Reply-To: <20261205064109.2526623-1-praneethb2002@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Critical] crypto: bcm: off-by-one rx_frag_num check wraps u8 in
  spu_aead_rx_sg_create()
--

commit 18c5819a2054b0edb55dbef6d87807eed0c94639
Author: Praneeth Balasubramanian <praneethb2002@gmail.com>

crypto: bcm - Reject requests with too many fragments

This commit widens the fragment counters in the skcipher, ahash, and aead
request handlers from u8 to u32 and rejects requests with -EINVAL when a
count exceeds U8_MAX before calling the sg create helpers.

> diff --git a/drivers/crypto/bcm/cipher.c b/drivers/crypto/bcm/cipher.c
> index 8c3e9525c134e..6a811a93a31fb 100644
> --- a/drivers/crypto/bcm/cipher.c
> +++ b/drivers/crypto/bcm/cipher.c

[ ... ]

> @@ -1486,6 +1496,9 @@ static int handle_aead_req(struct iproc_reqctx_s *rctx)
>  			rx_frag_num -= rctx->dst_nents;
>  	}
>  
> +	/* The sg create helpers take the fragment counts as a u8 */
> +	if (rx_frag_num > U8_MAX)
> +		return -EINVAL;
>  	err = spu_aead_rx_sg_create(mssg, req, rctx, rx_frag_num,
>  				    aead_parms.assoc_size,
>  				    aead_parms.ret_iv_len, resp_len, digestsize,

[Severity: Critical]
Can rx_frag_num still wrap to 0 inside spu_aead_rx_sg_create()?

This check lets rx_frag_num == U8_MAX (255) through, but
spu_aead_rx_sg_create() takes rx_frag_num as a u8 and increments it again
when data_padlen is non-zero:

drivers/crypto/bcm/cipher.c:spu_aead_rx_sg_create() {
	...
	if (data_padlen)
		/* have to catch gcm pad in separate buffer */
		rx_frag_num++;

	mssg->spu.dst = kmalloc_objs(struct scatterlist, rx_frag_num, rctx->gfp);
	if (!mssg->spu.dst)
		return -ENOMEM;

	sg = mssg->spu.dst;
	sg_init_table(sg, rx_frag_num);
	...
}

On SPU-M hardware, an unprivileged AF_ALG user submitting a GCM request
with a payload not aligned to 16 bytes (e.g. 252 bytes across 252 dst sg
entries) gets a non-zero data_padlen from spum_gcm_ccm_pad_len() with
rx_frag_num == 255.

Incrementing u8 rx_frag_num wraps it to 0, so kmalloc_objs() returns
ZERO_SIZE_PTR (bypassing the NULL check) and sg_init_table(sg, 0) writes
out of bounds through ZERO_SIZE_PTR, causing a kernel oops or panic.

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

  reply	other threads:[~2026-12-05  7:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  6:41 [PATCH] crypto: bcm - Reject requests with too many fragments Praneeth Balasubramanian
2026-12-05  7:02 ` sashiko-bot [this message]
2026-12-05  8:21   ` Praneeth Balasubramanian

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-251182@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=praneethb2002@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.