Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: caam - fix endless loop when DECO acquire fails

In case DECO0 cannot be acquired - i.e. run_descriptor_deco0() fails
with -ENODEV, caam_probe() enters an endless loop:

run_descriptor_deco0
ret -ENODEV
-> instantiate_rng
-ENODEV, overwritten by -EAGAIN
ret -EAGAIN
-> caam_probe
-EAGAIN results in endless loop

It turns out the error path in instantiate_rng() is incorrect,
the checks are done in the wrong order.

Cc: <stable@vger.kernel.org> # 3.13+
Fixes: 1005bccd7a4a6 ("crypto: caam - enable instantiation of all RNG4 state handles")
Reported-by: Bryan O'Donoghue <pure.logic@nexus-software.ie>
Suggested-by: Auer Lukas <lukas.auer@aisec.fraunhofer.de>
Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Horia Geantă and committed by
Herbert Xu
225ece3e ba916b6a

+8 -4
+8 -4
drivers/crypto/caam/ctrl.c
··· 228 228 * without any error (HW optimizations for later 229 229 * CAAM eras), then try again. 230 230 */ 231 - rdsta_val = rd_reg32(&ctrl->r4tst[0].rdsta) & RDSTA_IFMASK; 232 - if ((status && status != JRSTA_SSRC_JUMP_HALT_CC) || 233 - !(rdsta_val & (1 << sh_idx))) 234 - ret = -EAGAIN; 235 231 if (ret) 236 232 break; 233 + 234 + rdsta_val = rd_reg32(&ctrl->r4tst[0].rdsta) & RDSTA_IFMASK; 235 + if ((status && status != JRSTA_SSRC_JUMP_HALT_CC) || 236 + !(rdsta_val & (1 << sh_idx))) { 237 + ret = -EAGAIN; 238 + break; 239 + } 240 + 237 241 dev_info(ctrldev, "Instantiated RNG4 SH%d\n", sh_idx); 238 242 /* Clear the contents before recreating the descriptor */ 239 243 memset(desc, 0x00, CAAM_CMD_SZ * 7);