From: sashiko-bot@kernel.org
To: "Manorit Chawdhry" <m-chawdhry@ti.com>,
"Herbert Xu" <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
Keerthy <j-keerthy@ti.com>,
"Colin Ian King" <colin.i.king@gmail.com>
Cc: "Andrew Davis" <afd@ti.com>, "Pratham T" <t-pratham@ti.com>,
"Kamlesh Gurudasani" <kamlesh@ti.com>,
"Udit Kumar" <u-kumar1@ti.com>,
linux-crypto@vger.kernel.org
Subject: Re: [PATCH v2 22/30] crypto: sa2ul - validate scatterlist setup and unwind DMA mappings
Date: Wed, 04 Nov 2026 06:01:35 +0000 [thread overview]
Message-ID: <sashiko-outbox-196714@kernel.org> (raw)
In-Reply-To: <20261104-b4-upstream-sa2ul-cleanup-v2-22-15ab90b3f9c2@ti.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] crypto: sa2ul: sa_run() passes 0 nents to dma_map_sgtable() when size is 0
--
commit 615706b20f3b90ba270a289c49acc68499b974e6
Author: Manorit Chawdhry <m-chawdhry@ti.com>
crypto: sa2ul - validate scatterlist setup and unwind DMA mappings
This commit validates source and destination scatterlist lengths with
sg_nents_for_len(), aborts on sg_split() failures, and routes partial setup
errors in sa_run() through sa_free_sa_rx_data().
> diff --git a/drivers/crypto/sa2ul.c b/drivers/crypto/sa2ul.c
> index 2964aa44d50e4..b33fac66c93fc 100644
> --- a/drivers/crypto/sa2ul.c
> +++ b/drivers/crypto/sa2ul.c
> @@ -1071,6 +1071,10 @@ static int sa_run(struct sa_req *req)
> */
> src = req->src;
> sg_nents = sg_nents_for_len(src, req->size);
> + if (sg_nents < 0) {
> + ret = sg_nents;
> + goto err_cleanup;
> + }
>
> split_size = req->size;
>
> @@ -1086,7 +1090,7 @@ static int sa_run(struct sa_req *req)
> mapped_sg->sgt.orig_nents = src_nents;
> ret = dma_map_sgtable(ddev, &mapped_sg->sgt, dir_src, 0);
> if (ret) {
> - kfree(rxd);
> + sa_free_sa_rx_data(rxd);
> return ret;
> }
>
> @@ -1097,7 +1101,7 @@ static int sa_run(struct sa_req *req)
> mapped_sg->sgt.orig_nents = sg_nents;
> ret = dma_map_sgtable(ddev, &mapped_sg->sgt, dir_src, 0);
> if (ret) {
> - kfree(rxd);
> + sa_free_sa_rx_data(rxd);
> return ret;
> }
>
> @@ -1106,12 +1110,10 @@ static int sa_run(struct sa_req *req)
>
> ret = sg_split(mapped_sg->sgt.sgl, mapped_sg->sgt.nents, 0, 1,
> &split_size, &src, &src_nents, gfp_flags);
> - if (ret) {
> - src_nents = mapped_sg->sgt.nents;
> - src = mapped_sg->sgt.sgl;
> - } else {
> - mapped_sg->split_sg = src;
> - }
> + if (ret)
> + goto err_cleanup;
> +
> + mapped_sg->split_sg = src;
> }
>
> dma_sync_sgtable_for_device(ddev, &mapped_sg->sgt, DMA_TO_DEVICE);
> @@ -1121,6 +1123,10 @@ static int sa_run(struct sa_req *req)
> dst = src;
> } else {
> dst_nents = sg_nents_for_len(req->dst, req->size);
> + if (dst_nents < 0) {
> + ret = dst_nents;
> + goto err_cleanup;
> + }
[Severity: High]
What happens in sa_run() when req->size is 0?
In sa_aead_run(), an AEAD request with req->assoclen == 0 and zero plaintext
length (req->cryptlen == 0 on encryption, or req->cryptlen ==
crypto_aead_authsize(tfm) on decryption) results in auth_size == 0. Unlike
sa_cipher_run() and sa_sha_run(), sa_aead_run() does not divert zero-length
requests to the software fallback:
drivers/crypto/sa2ul.c:sa_aead_run() {
...
if (auth_size > SA_MAX_DATA_SZ ||
(auth_size >= SA_UNSAFE_DATA_SZ_MIN &&
auth_size <= SA_UNSAFE_DATA_SZ_MAX)) {
...
}
...
sa_req.size = auth_size;
...
return sa_run(&sa_req);
}
When sa_run() calls sg_nents_for_len() with a length of 0, sg_nents_for_len()
returns 0. Because the new checks only test sg_nents < 0 and dst_nents < 0, a
return value of 0 bypasses the error check, skips the sg_nents == 1 branch,
and enters the else branch:
} else {
mapped_sg->sgt.sgl = req->src;
mapped_sg->sgt.orig_nents = sg_nents;
ret = dma_map_sgtable(ddev, &mapped_sg->sgt, dir_src, 0);
Passing orig_nents == 0 to dma_map_sgtable() triggers the WARN_ON_ONCE(nents
<= 0) in __dma_map_sg_attrs() and fails the request with -EINVAL.
Should sa_run() reject sg_nents <= 0 and dst_nents <= 0 (or should
sa_aead_run() route auth_size == 0 to the software fallback)?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261104-b4-upstream-sa2ul-cleanup-v2-0-15ab90b3f9c2@ti.com?part=22
next prev parent reply other threads:[~2026-11-04 6:01 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 5:44 [PATCH v2 00/30] Clean and improve SA2UL driver Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 01/30] crypto: sa2ul - remove dead code Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 02/30] crypto: sa2ul - remove totally unused structure fields Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 03/30] crypto: sa2ul - remove unused fields from sa_cmdl_cfg Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 04/30] crypto: sa2ul - remove unused context fields Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 05/30] crypto: sa2ul - remove unused macro definitions Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 06/30] crypto: sa2ul - remove unused base register pointer Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 07/30] crypto: sa2ul - remove unused includes and defines Manorit Chawdhry
2026-11-04 5:57 ` sashiko-bot
2026-11-04 5:44 ` [PATCH v2 08/30] crypto: sa2ul - remove unused line Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 09/30] crypto: sa2ul - remove redundant sa_sha_digest() wrapper Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 10/30] crypto: sa2ul - fix struct documentation for match_data Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 11/30] crypto: sa2ul - keep the probe register mapping local Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 12/30] crypto: sa2ul - zero out security context on free Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 13/30] crypto: sa2ul - preserve full authentication key lengths Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 14/30] crypto: sa2ul - validate AES key sizes before indexing Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 15/30] crypto: sa2ul - remove unused SC ID range tracking Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 16/30] crypto: sa2ul - copy command-label inputs locally Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 17/30] crypto: sa2ul - consolidate encryption offset definitions Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 18/30] crypto: sa2ul - handle unaligned IV buffers Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 19/30] crypto: sa2ul - remove redundant algorithm ID fields Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 20/30] crypto: sa2ul - handle transform initialization failures Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 21/30] crypto: sa2ul - reject exhausted context IDs Manorit Chawdhry
2026-11-04 13:31 ` Thorsten Blum
2026-11-04 5:44 ` [PATCH v2 22/30] crypto: sa2ul - validate scatterlist setup and unwind DMA mappings Manorit Chawdhry
2026-11-04 6:01 ` sashiko-bot [this message]
2026-11-04 5:44 ` [PATCH v2 23/30] crypto: sa2ul - propagate DMA transfer errors Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 24/30] crypto: sa2ul - calculate DMA metadata length from the command label Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 25/30] crypto: sa2ul - correct scatterlist DMA ownership transitions Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 26/30] crypto: sa2ul - use a mempool for security contexts Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 27/30] crypto: sa2ul - use synchronous fallbacks and fixed request sizes Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 28/30] crypto: sa2ul - route requests through crypto_engine Manorit Chawdhry
2026-11-04 6:04 ` sashiko-bot
2026-11-04 5:44 ` [PATCH v2 29/30] crypto: sa2ul - report SA engine hardware revision Manorit Chawdhry
2026-11-04 5:44 ` [PATCH v2 30/30] crypto: sa2ul - add SA3UL_CM AES support Manorit Chawdhry
2026-11-04 6:01 ` sashiko-bot
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-196714@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=afd@ti.com \
--cc=colin.i.king@gmail.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=j-keerthy@ti.com \
--cc=kamlesh@ti.com \
--cc=linux-crypto@vger.kernel.org \
--cc=m-chawdhry@ti.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=t-pratham@ti.com \
--cc=u-kumar1@ti.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