MLK-22039: crypto: caam - limit output IV to CBC to work around CTR mode DMA issue
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 31 May 2019 08:13:06 +0000 (10:13 +0200)
committerHoria Geantă <horia.geanta@nxp.com>
Fri, 5 Jul 2019 15:00:04 +0000 (18:00 +0300)
commit100197706119e3cb8e8552afb93c46f7ec12f414
treee5f19ef3c731229b4809737b541c0961693a86df
parent86a1a22f4f2119719638243f7181545cc7086dcd
MLK-22039: crypto: caam - limit output IV to CBC to work around CTR mode DMA issue

The CAAM driver currently violates an undocumented and slightly
controversial requirement imposed by the crypto stack that a buffer
referred to by the request structure via its virtual address may not
be modified while any scatterlists passed via the same request
structure are mapped for inbound DMA.

This may result in errors like

  alg: aead: decryption failed on test 1 for gcm_base(ctr-aes-caam,ghash-generic): ret=74
  alg: aead: Failed to load transform for gcm(aes): -2

on non-cache coherent systems, due to the fact that the GCM driver
passes an IV buffer by virtual address which shares a cacheline with
the auth_tag buffer passed via a scatterlist, resulting in corruption
of the auth_tag when the IV is updated while the DMA mapping is live.

Since the IV that is returned to the caller is only valid for CBC mode,
and given that the in-kernel users of CBC (such as CTS) don't trigger the
same issue as the GCM driver, let's just disable the output IV generation
for all modes except CBC for the time being.

Fixes: 854b06f76879 ("crypto: caam - properly set IV after {en,de}crypt")
Cc: Horia Geanta <horia.geanta@nxp.com>
Cc: Iuliana Prodan <iuliana.prodan@nxp.com>
Reported-by: Sascha Hauer <s.hauer@pengutronix.de>
Cc: <stable@vger.kernel.org>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Horia Geanta <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
(cherry picked from commit ed527b13d800dd515a9e6c582f0a73eca65b2e1b)

backported to imx_4.19.y

Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
Reviewed-by: Iuliana Prodan <iuliana.prodan@nxp.com>
drivers/crypto/caam/caamalg.c