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,
	stephane.debusne@cynove.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
Subject: Re: [PATCH v2 0/2] crypto: caam - Fix RSA destination buffer handling
Date: Tue, 20 Oct 2026 14:21:44 +1100	[thread overview]
Message-ID: <20261020032144.961571-1-changwei.zou@canonical.com> (raw)
In-Reply-To: <asdIf-bbjjSHRNh7@gondor.apana.org.au>

Hi Herbert,

Thanks for the review.

> If a caller provides an unaligned destination scatterlist where
> req->dst_len is larger than the actual RSA output size (such as
> key->n_sz), the bounce buffer is zero-initialized and sized to
> req->dst_len. [...] Could this corrupt adjacent data by copying zeroes
> over the trailing capacity of the caller's buffer? Should this copy
> only the actual hardware output size instead of the full buffer
> capacity?

There is no out-of-bounds access or adjacent-memory corruption: the
copy-back targets the caller's own dst (orig_dst) and is bounded by
req->dst_len, the buffer length the caller provided. It reads dst_len
bytes from the bounce buffer (sized ALIGN(dst_len, cacheline) >= dst_len)
and writes them into that same dst, so neither buffer is overrun.

That said, copying only the actual output size is a sensible improvement,
and I've applied it in v3: the copy-back is now bounded to the RSA output
size (key->n_sz) instead of req->dst_len. The hardware writes the full
modulus-width (n_sz) output - the RSA PDB has no separate output-length
field - and caam_rsa_enc()/caam_rsa_dec() guarantee dst_len >= n_sz, so
the trailing capacity of the caller's buffer is left untouched.

Another option, if keeping the full dst_len copy is preferred, is to seed
the bounce buffer with the caller's original destination contents before
the operation (rather than zero-initializing it) and copy all dst_len
bytes back afterwards. The hardware overwrites only [0, n_sz) with the
result, so [n_sz, dst_len) still holds the caller's original bytes and the
full copy-back leaves the trailing region unchanged. I went with the
simpler key->n_sz bound for v3, but I'm happy to switch to this if you
prefer.

Kind regards,

Changwei

      reply	other threads:[~2026-10-20  3:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-04 21:01 Changwei Zou
2026-10-04 21:01 ` [PATCH v2 1/2] crypto: caam - Fix wrong unmap operations Changwei Zou
2026-10-04 21:02 ` [PATCH v2 2/2] crypto: caam - Use bounce buffer for unaligned RSA destination buffers Changwei Zou
2026-10-17  8:14   ` Stephane Debusne
2026-10-17 10:20     ` Changwei Zou
2026-10-17 15:39       ` Stephane Debusne
2026-10-08  7:38 ` [PATCH v2 0/2] crypto: caam - Fix RSA destination buffer handling Herbert Xu
2026-10-20  3:21   ` 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=20261020032144.961571-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®