mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Changwei Zou <changwei.zou@canonical.com>
To: herbert@gondor.apana.org.au
Cc: changwei.zou@canonical.com, davem@davemloft.net,
	gaurav.jain@nxp.com, horia.geanta@nxp.com,
	iuliana.prodan@nxp.com, jeffbarnes@linux.microsoft.com,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
	lukas@wunner.de, martin.kepplinger-novakovic@ginzinger.com,
	pankaj.gupta@nxp.com, sahil.malhotra@nxp.com,
	sahil.malhotra@oss.nxp.com, stephane.debusne@cynove.com
Subject: Re: [PATCH v3 2/2] crypto: caam - Use bounce buffer for unaligned RSA destination buffers
Date: Wed, 11 Nov 2026 23:40:59 +1100	[thread overview]
Message-ID: <20261111124059.789629-1-changwei.zou@canonical.com> (raw)
In-Reply-To: <avRIYjWB6AUbeLUS@gondor.apana.org.au>

Hi Herbert,

Thanks a lot.
This is a valid finding, I'll fix it in v4.

> rsa_edesc_alloc() allocates req_ctx->bounce_buf with size
> ALIGN(req->dst_len, dma_get_cache_alignment()), but initializes the
> bounce scatterlist entry via sg_init_one(&req_ctx->dst,
> req_ctx->bounce_buf, req->dst_len) with the unaligned req->dst_len.

Correct. The bounce buffer is allocated with the aligned size, but the SG
is described with the possibly-unaligned req->dst_len.

So the fix is to describe the SG with the aligned allocation size:

	unsigned int bounce_len =
		ALIGN(req->dst_len, dma_get_cache_alignment());

	req_ctx->bounce_buf = kzalloc(bounce_len, flags);
	if (!req_ctx->bounce_buf)
		return ERR_PTR(-ENOMEM);
	sg_init_one(&req_ctx->dst, req_ctx->bounce_buf, bounce_len);

My own test case (loading signed kernel modules) used req->dst_len = 512
bytes, which is already cacheline-aligned, so this unaligned-length path
was not exercised and the issue was missed.

Kind regards,
Changwei

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

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20  2:54 [PATCH v3 0/2] crypto: caam - Fix RSA error-path unmap and unaligned dst buffers Changwei Zou
2026-10-20  2:54 ` [PATCH v3 1/2] crypto: caam - Fix wrong unmap operations Changwei Zou
2026-10-20  2:54 ` [PATCH v3 2/2] crypto: caam - Use bounce buffer for unaligned RSA destination buffers Changwei Zou
2026-11-11 10:50   ` Herbert Xu
2026-11-11 12:40     ` Changwei Zou [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=20261111124059.789629-1-changwei.zou@canonical.com \
    --to=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=linux-kernel@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=martin.kepplinger-novakovic@ginzinger.com \
    --cc=pankaj.gupta@nxp.com \
    --cc=sahil.malhotra@nxp.com \
    --cc=sahil.malhotra@oss.nxp.com \
    --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

all inboxes | Powered by JetHome®