Linux cryptographic layer development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Changwei Zou" <changwei.zou@canonical.com>,
	herbert@gondor.apana.org.au, sahil.malhotra@nxp.com
Cc: davem@davemloft.net, horia.geanta@nxp.com, pankaj.gupta@nxp.com,
	gaurav.jain@nxp.com, jeffbarnes@linux.microsoft.com,
	stephane.debusne@cynove.com, iuliana.prodan@nxp.com,
	"Martin Kepplinger-Novakovic"
	<Martin.Kepplinger-Novakovic@ginzinger.com>,
	lukas@wunner.de, sahil.malhotra@oss.nxp.com,
	linux-crypto@vger.kernel.org
Subject: Re: [PATCH v7 2/2] crypto: caam - Use bounce buffer for unaligned RSA destination buffers
Date: Fri, 20 Nov 2026 11:26:33 +0000	[thread overview]
Message-ID: <sashiko-outbox-225037@kernel.org> (raw)
In-Reply-To: <20261120110525.1170175-3-changwei.zou@canonical.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] crypto: caam - missing Fixes trailer for unaligned RSA
  destination fix
--

commit 9904aef7526cc6f78c558230d818097bb074e798
Author: Changwei Zou <changwei.zou@canonical.com>

> crypto: caam - Use bounce buffer for unaligned RSA destination buffers
>
> The rsa-caam driver directly DMA-maps the destination buffer supplied by
> the caller via req->dst without checking whether it meets the cacheline
> alignment requirements of DMA-incoherent hardware such as i.MX8.
>
> On CPUs with non-coherent DMA caches, if the destination buffer shares a
> cacheline with other data (i.e. it is not cacheline-aligned), cache
> writeback/invalidation during DMA can corrupt adjacent memory or cause
> stale data to be read back. This manifests as intermittent -EKEYREJECTED
> errors when loading signed kernel modules.
>
> Such a destination is produced in the module-signature verification path
> by rsassa_pkcs1_verify() (and crypto_akcipher_sync_prep()), which place
> the I/O buffer right after the request context in a single kmalloc()
> allocation; the buffer therefore starts at an offset into a larger
> allocation and shares a cacheline with that context. The DMA API does not
> cover this: on CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC systems
> dma_kmalloc_needs_bounce() only considers the buffer size, not its offset,
> so a buffer that is size-wise DMA-safe but starts at a non-cacheline-
> aligned offset is not bounced. The driver must detect and bounce it.
>
> When any segment of req->dst is not cacheline-aligned in either its start
> offset or length, allocate a single contiguous aligned bounce buffer
> (dst_len rounded up to a cacheline multiple) and run the operation on it
> via req_ctx->fixup_dst, leaving the caller's req->dst untouched. The RSA
> output (key->n_sz bytes) is copied back to req->dst once the hardware has
> completed successfully.
>
> Introduce a helper sg_is_dma_aligned() that checks both sg->offset and
> sg->length for cacheline alignment. Checking sg->offset suffices for
> the start address since physical pages are always page-aligned and
> PAGE_SIZE is a multiple of dma_get_cache_alignment(). sg->length is
> also checked to ensure the buffer end does not share a cacheline with
> adjacent memory.
>
> The bounce scatterlist is described with the aligned allocation size, not
> the possibly-unaligned dst_len, so that dma_map_sg() does not re-bounce or
> reject it on CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC systems.
>
> The intermittent error 'Key was rejected by service' on i.MX8 with CAAM
> can be triggered when loading signed kernel modules:
>
>     for i in $(seq 1 100); do
>         sudo modprobe xfs 2>&1 && echo "SUCCESS on attempt $i" \
>         && sudo rmmod xfs || echo "FAILED on attempt $i"
>     done
>
> Reported-by: Martin Kepplinger-Novakovic <Martin.Kepplinger-Novakovic@ginzinger.com>
> Closes: https://lore.kernel.org/r/6029acc0f0ddfe25e2537c2866d54fd7f54bc182.camel@ginzinger.com
> Signed-off-by: Changwei Zou <changwei.zou@canonical.com>
> Tested-by: Martin Kepplinger-Novakovic <martin.kepplinger-novakovic@ginzinger.com>
> Tested-by: Stephane Debusne <stephane.debusne@cynove.com>
> Reviewed-by: Sahil Malhotra <sahil.malhotra@nxp.com>

[Severity: Low]
This fixes a bug where rsa_edesc_alloc() DMA-mapped unaligned req->dst
buffers without bouncing them.  Should this include:

  Fixes: 8c419778ab57 ("crypto: caam - add support for RSA algorithm")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120110525.1170175-1-changwei.zou@canonical.com?part=2

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

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 11:05 [PATCH v7 0/2] crypto: caam - Fix RSA error-path unmap and unaligned dst buffers Changwei Zou
2026-11-20 11:05 ` [PATCH v7 1/2] crypto: caam - Fix wrong unmap operations Changwei Zou
2026-11-20 11:05 ` [PATCH v7 2/2] crypto: caam - Use bounce buffer for unaligned RSA destination buffers Changwei Zou
2026-11-20 11:26   ` 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-225037@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Martin.Kepplinger-Novakovic@ginzinger.com \
    --cc=changwei.zou@canonical.com \
    --cc=davem@davemloft.net \
    --cc=gaurav.jain@nxp.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=horia.geanta@nxp.com \
    --cc=iuliana.prodan@nxp.com \
    --cc=jeffbarnes@linux.microsoft.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=pankaj.gupta@nxp.com \
    --cc=sahil.malhotra@nxp.com \
    --cc=sahil.malhotra@oss.nxp.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=stephane.debusne@cynove.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