From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Radu Solea <radu.solea@nxp.com>,
Leonard Crestez <leonard.crestez@nxp.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
Sasha Levin <sashal@kernel.org>,
linux-crypto@vger.kernel.org
Subject: [PATCH AUTOSEL 4.4 29/48] crypto: mxs-dcp - Fix SHA null hashes and output length
Date: Tue, 12 Nov 2019 21:01:12 -0500 [thread overview]
Message-ID: <20191113020131.13356-29-sashal@kernel.org> (raw)
In-Reply-To: <20191113020131.13356-1-sashal@kernel.org>
From: Radu Solea <radu.solea@nxp.com>
[ Upstream commit c709eebaf5c5faa8a0f140355f9cfe67e8f7afb1 ]
DCP writes at least 32 bytes in the output buffer instead of hash length
as documented. Add intermediate buffer to prevent write out of bounds.
When requested to produce null hashes DCP fails to produce valid output.
Add software workaround to bypass hardware and return valid output.
Signed-off-by: Radu Solea <radu.solea@nxp.com>
Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/crypto/mxs-dcp.c | 47 +++++++++++++++++++++++++++++++---------
1 file changed, 37 insertions(+), 10 deletions(-)
diff --git a/drivers/crypto/mxs-dcp.c b/drivers/crypto/mxs-dcp.c
index fe8cfe24c518f..38c5dd8891138 100644
--- a/drivers/crypto/mxs-dcp.c
+++ b/drivers/crypto/mxs-dcp.c
@@ -28,9 +28,24 @@
#define DCP_MAX_CHANS 4
#define DCP_BUF_SZ PAGE_SIZE
+#define DCP_SHA_PAY_SZ 64
#define DCP_ALIGNMENT 64
+/*
+ * Null hashes to align with hw behavior on imx6sl and ull
+ * these are flipped for consistency with hw output
+ */
+const uint8_t sha1_null_hash[] =
+ "\x09\x07\xd8\xaf\x90\x18\x60\x95\xef\xbf"
+ "\x55\x32\x0d\x4b\x6b\x5e\xee\xa3\x39\xda";
+
+const uint8_t sha256_null_hash[] =
+ "\x55\xb8\x52\x78\x1b\x99\x95\xa4"
+ "\x4c\x93\x9b\x64\xe4\x41\xae\x27"
+ "\x24\xb9\x6f\x99\xc8\xf4\xfb\x9a"
+ "\x14\x1c\xfc\x98\x42\xc4\xb0\xe3";
+
/* DCP DMA descriptor. */
struct dcp_dma_desc {
uint32_t next_cmd_addr;
@@ -48,6 +63,7 @@ struct dcp_coherent_block {
uint8_t aes_in_buf[DCP_BUF_SZ];
uint8_t aes_out_buf[DCP_BUF_SZ];
uint8_t sha_in_buf[DCP_BUF_SZ];
+ uint8_t sha_out_buf[DCP_SHA_PAY_SZ];
uint8_t aes_key[2 * AES_KEYSIZE_128];
@@ -518,8 +534,6 @@ static int mxs_dcp_run_sha(struct ahash_request *req)
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
struct dcp_async_ctx *actx = crypto_ahash_ctx(tfm);
struct dcp_sha_req_ctx *rctx = ahash_request_ctx(req);
- struct hash_alg_common *halg = crypto_hash_alg_common(tfm);
-
struct dcp_dma_desc *desc = &sdcp->coh->desc[actx->chan];
dma_addr_t digest_phys = 0;
@@ -541,10 +555,23 @@ static int mxs_dcp_run_sha(struct ahash_request *req)
desc->payload = 0;
desc->status = 0;
+ /*
+ * Align driver with hw behavior when generating null hashes
+ */
+ if (rctx->init && rctx->fini && desc->size == 0) {
+ struct hash_alg_common *halg = crypto_hash_alg_common(tfm);
+ const uint8_t *sha_buf =
+ (actx->alg == MXS_DCP_CONTROL1_HASH_SELECT_SHA1) ?
+ sha1_null_hash : sha256_null_hash;
+ memcpy(sdcp->coh->sha_out_buf, sha_buf, halg->digestsize);
+ ret = 0;
+ goto done_run;
+ }
+
/* Set HASH_TERM bit for last transfer block. */
if (rctx->fini) {
- digest_phys = dma_map_single(sdcp->dev, req->result,
- halg->digestsize, DMA_FROM_DEVICE);
+ digest_phys = dma_map_single(sdcp->dev, sdcp->coh->sha_out_buf,
+ DCP_SHA_PAY_SZ, DMA_FROM_DEVICE);
desc->control0 |= MXS_DCP_CONTROL0_HASH_TERM;
desc->payload = digest_phys;
}
@@ -552,9 +579,10 @@ static int mxs_dcp_run_sha(struct ahash_request *req)
ret = mxs_dcp_start_dma(actx);
if (rctx->fini)
- dma_unmap_single(sdcp->dev, digest_phys, halg->digestsize,
+ dma_unmap_single(sdcp->dev, digest_phys, DCP_SHA_PAY_SZ,
DMA_FROM_DEVICE);
+done_run:
dma_unmap_single(sdcp->dev, buf_phys, DCP_BUF_SZ, DMA_TO_DEVICE);
return ret;
@@ -572,6 +600,7 @@ static int dcp_sha_req_to_buf(struct crypto_async_request *arq)
const int nents = sg_nents(req->src);
uint8_t *in_buf = sdcp->coh->sha_in_buf;
+ uint8_t *out_buf = sdcp->coh->sha_out_buf;
uint8_t *src_buf;
@@ -626,11 +655,9 @@ static int dcp_sha_req_to_buf(struct crypto_async_request *arq)
actx->fill = 0;
- /* For some reason, the result is flipped. */
- for (i = 0; i < halg->digestsize / 2; i++) {
- swap(req->result[i],
- req->result[halg->digestsize - i - 1]);
- }
+ /* For some reason the result is flipped */
+ for (i = 0; i < halg->digestsize; i++)
+ req->result[i] = out_buf[halg->digestsize - i - 1];
}
return 0;
--
2.20.1
next prev parent reply other threads:[~2019-11-13 2:04 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-13 2:00 [PATCH AUTOSEL 4.4 01/48] net: ovs: fix return type of ndo_start_xmit function Sasha Levin
2019-11-13 2:00 ` [PATCH AUTOSEL 4.4 02/48] ARM: dts: omap5: enable OTG role for DWC3 controller Sasha Levin
2019-11-13 2:00 ` [PATCH AUTOSEL 4.4 03/48] f2fs: return correct errno in f2fs_gc Sasha Levin
2019-11-13 2:00 ` [PATCH AUTOSEL 4.4 04/48] SUNRPC: Fix priority queue fairness Sasha Levin
2019-11-13 2:00 ` [PATCH AUTOSEL 4.4 05/48] ath10k: fix vdev-start timeout on error Sasha Levin
2019-11-13 2:00 ` [PATCH AUTOSEL 4.4 06/48] ath9k: fix reporting calculated new FFT upper max Sasha Levin
2019-11-13 2:00 ` [PATCH AUTOSEL 4.4 07/48] usb: gadget: udc: fotg210-udc: Fix a sleep-in-atomic-context bug in fotg210_get_status() Sasha Levin
2019-11-13 2:00 ` [PATCH AUTOSEL 4.4 08/48] nl80211: Fix a GET_KEY reply attribute Sasha Levin
2019-11-13 2:00 ` [PATCH AUTOSEL 4.4 09/48] dmaengine: ep93xx: Return proper enum in ep93xx_dma_chan_direction Sasha Levin
2019-11-13 2:00 ` [PATCH AUTOSEL 4.4 10/48] dmaengine: timb_dma: Use proper enum in td_prep_slave_sg Sasha Levin
2019-11-13 2:00 ` [PATCH AUTOSEL 4.4 11/48] mei: samples: fix a signedness bug in amt_host_if_call() Sasha Levin
2019-11-13 2:00 ` [PATCH AUTOSEL 4.4 12/48] cxgb4: Use proper enum in cxgb4_dcb_handle_fw_update Sasha Levin
2019-11-13 2:00 ` [PATCH AUTOSEL 4.4 13/48] cxgb4: Use proper enum in IEEE_FAUX_SYNC Sasha Levin
2019-11-13 2:00 ` [PATCH AUTOSEL 4.4 14/48] powerpc/pseries: Fix DTL buffer registration Sasha Levin
2019-11-13 2:00 ` [PATCH AUTOSEL 4.4 15/48] powerpc/pseries: Fix how we iterate over the DTL entries Sasha Levin
2019-11-13 2:00 ` [PATCH AUTOSEL 4.4 16/48] mtd: rawnand: sh_flctl: Use proper enum for flctl_dma_fifo0_transfer Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 17/48] ixgbe: Fix crash with VFs and flow director on interface flap Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 18/48] IB/mthca: Fix error return code in __mthca_init_one() Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 19/48] ata: ep93xx: Use proper enums for directions Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 20/48] ALSA: hda/sigmatel - Disable automute for Elo VuPoint Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 21/48] KVM: PPC: Book3S PR: Exiting split hack mode needs to fixup both PC and LR Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 22/48] USB: serial: cypress_m8: fix interrupt-out transfer length Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 23/48] mtd: physmap_of: Release resources on error Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 24/48] brcmfmac: fix full timeout waiting for action frame on-channel tx Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 25/48] NFSv4.x: fix lock recovery during delegation recall Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 26/48] dmaengine: ioat: fix prototype of ioat_enumerate_channels Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 27/48] Input: st1232 - set INPUT_PROP_DIRECT property Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 28/48] x86/olpc: Fix build error with CONFIG_MFD_CS5535=m Sasha Levin
2019-11-13 2:01 ` Sasha Levin [this message]
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 30/48] crypto: mxs-dcp - Fix AES issues Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 31/48] ACPI / SBS: Fix rare oops when removing modules Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 32/48] fbdev: sbuslib: use checked version of put_user() Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 33/48] fbdev: sbuslib: integer overflow in sbusfb_ioctl_helper() Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 34/48] bcache: recal cached_dev_sectors on detach Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 35/48] proc/vmcore: Fix i386 build error of missing copy_oldmem_page_encrypted() Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 36/48] backlight: lm3639: Unconditionally call led_classdev_unregister Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 37/48] printk: Give error on attempt to set log buffer length to over 2G Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 38/48] media: isif: fix a NULL pointer dereference bug Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 39/48] GFS2: Flush the GFS2 delete workqueue before stopping the kernel threads Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 40/48] media: cx231xx: fix potential sign-extension overflow on large shift Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 41/48] x86/kexec: Correct KEXEC_BACKUP_SRC_END off-by-one error Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 42/48] gpio: syscon: Fix possible NULL ptr usage Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 43/48] spi: spidev: Fix OF tree warning logic Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 44/48] ARM: 8802/1: Call syscall_trace_exit even when system call skipped Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 45/48] hwmon: (pwm-fan) Silence error on probe deferral Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 46/48] mac80211: minstrel: fix CCK rate group streams value Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 47/48] spi: rockchip: initialize dma_slave_config properly Sasha Levin
2019-11-13 2:01 ` [PATCH AUTOSEL 4.4 48/48] ARM: dts: omap5: Fix dual-role mode on Super-Speed port Sasha Levin
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=20191113020131.13356-29-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=leonard.crestez@nxp.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=radu.solea@nxp.com \
--cc=stable@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