mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ralf Lici <ralf@mandelbit.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: linux-crypto@vger.kernel.org, Antoine Tenart <atenart@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH crypto 2/2] crypto: safexcel - Map AEAD buffers with accurate DMA directions
Date: Mon, 28 Sep 2026 12:25:00 +0200	[thread overview]
Message-ID: <20260928102502.266108-1-ralf@mandelbit.com> (raw)
In-Reply-To: <arn3UFsriRlGMXwB@gondor.apana.org.au>

On Mon, 28 Sep 2026 15:12:48 +1000, Herbert Xu <herbert@gondor.apana.org.au> wrote:
> On Wed, Sep 23, 2026 at 11:13:17AM +0200, Ralf Lici wrote:
> >
> > There is no caller to identify for that particular single-entry layout,
> > it was only a hypothetical example in response to your question. Even
> > for out-of-place AEAD, the destination starts with space reserved for
> > the associated data (as documented in the comment at the top of
> > include/crypto/aead.h). A single linear destination entry can therefore
> > contain both that reserved prefix, which the device does not write, and
> > the ciphertext and tag, which it does write. Because the DMA direction
> > applies to the whole entry, such a mixed entry is mapped
> > DMA_BIDIRECTIONAL.
>
> So why is it a problem if the dst SG list entries aren't pointing
> to memory that's also occupied by the SG list entries?
>
> Even if the hardware doesn't write to the data, it should be OK to
> map them.
>
> The only issue that I can see is if the same memory is present in
> both the src SG list and the dst SG list, but that is expressly
> forbidden for out-of-place operations, and indeed would be a grave
> security issue.
>

I think the missing point is that DMA_FROM_DEVICE is not neutral for
bytes which the device does not write.

For an out-of-place request, the caller may have already populated the
reserved destination AAD area. The AEAD API says that this area will not
be written by the cipher operation:

  Even in the out-of-place case, space must be reserved in the
  destination for the associated data, even though it won't be written
  to.

With SWIOTLB, however, mapping it as DMA_FROM_DEVICE may leave the
corresponding bounce-buffer bytes uninitialized, and unmapping then
copies those untouched bytes back over the caller's AAD.

The API also explicitly permits the source and destination AAD entries
to describe the exact same byte range (and users do this in practice,
for example nitrox_rfc4106_set_aead_rctx_sglist):

  It is permissible for the "destination" associated data to alias
  the "source" associated data.

Therefore, this is a valid out-of-place request:

  src: [ AAD X ] [ plaintext P ]
  dst: [ AAD X ] [ ciphertext C ] [ tag T ]

P and C use separate storage. Only the two AAD entries point to the same
addresses X.

Safexcel currently maps the source list as DMA_TO_DEVICE and the whole
destination list as DMA_FROM_DEVICE. Consequently, X is mapped as device
output even though the accelerator deliberately does not write it. On a
non-coherent system or with SWIOTLB, unmapping the destination can then
overwrite X with stale data.

Thanks for following up.

-- 
Ralf Lici
Mandelbit Srl

      reply	other threads:[~2026-09-28 10:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15 11:32 [PATCH crypto 0/2] crypto: safexcel: fix AEAD DMA mapping and cleanup Ralf Lici
2026-09-15 11:32 ` [PATCH crypto 1/2] crypto: safexcel - Avoid unmapping failed DMA mappings Ralf Lici
2026-09-15 11:32 ` [PATCH crypto 2/2] crypto: safexcel - Map AEAD buffers with accurate DMA directions Ralf Lici
2026-09-23  5:30   ` Herbert Xu
2026-09-23  7:26     ` Ralf Lici
2026-09-23  8:32       ` Herbert Xu
2026-09-23  9:13         ` Ralf Lici
2026-09-28  5:12           ` Herbert Xu
2026-09-28 10:25             ` Ralf Lici [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=20260928102502.266108-1-ralf@mandelbit.com \
    --to=ralf@mandelbit.com \
    --cc=atenart@kernel.org \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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®