Skip to contentSkip to conversation

crypto: caam - allocate enough space for blob descriptors

PATCH New Keisuke Tsukuda 1 participant 1 message Dec 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 crypto: caam - allocate enough space for blob descriptors

Commit a703a4c2a328 ("KEYS: trusted: caam based protected key") replaced the _intlen sequence-pointer helpers in caam_process_blob() with append_seq_in_ptr() and append_seq_out_ptr(). These helpers append an external length word for each u32 length, but CAAM_BLOB_DESC_BYTES_MAX accounts for neither word.

The trusted-key caller uses the 10-byte "SECURE_KEY" modifier. Its 12-byte padded length leaves four bytes unused in the macro's 16-byte modifier allowance. Thus, when the DMA and CAAM pointer widths match, the allocation is four bytes short. On an i.MX6 Quad, "new 32" builds a 48-byte descriptor in a 44-byte allocation. KASAN reports a four-byte slab-out-of-bounds write at append_operation().

On this 32-bit configuration, the protected-key path would build a 68-byte descriptor, beyond the observed kmalloc-64 slot. This path was not tested.

Allocate CAAM_DESC_BYTES_MAX, the existing 64-word descriptor limit, instead of maintaining an incomplete blob-specific size calculation. The same trusted-key operation completes without a KASAN report on the patched kernel.

Fixes a703a4c2a328 ("KEYS: trusted: caam based protected key")

---
v2:
- Add the stable Cc and Sahil Malhotra's Reviewed-by tag.
- No code changes.

v1: https://lore.kernel.org/r/[email protected]/

 drivers/crypto/caam/blob_gen.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/crypto/caam/blob_gen.c +1 -13
index c18dbac56..0b19e5f7c 100644
@@ -20,18 +20,6 @@
 #include "jr.h"
 #include "regs.h"
 
-#define CAAM_BLOB_DESC_BYTES_MAX					\
-	/* Command to initialize & stating length of descriptor */	\
-	(CAAM_CMD_SZ +							\
-	/* Command to append the key-modifier + key-modifier data */	\
-	 CAAM_CMD_SZ + CAAM_BLOB_KEYMOD_LENGTH +			\
-	/* Command to include input key + pointer to the input key */	\
-	 CAAM_CMD_SZ + CAAM_PTR_SZ_MAX +				\
-	/* Command to include output key + pointer to the output key */	\
-	 CAAM_CMD_SZ + CAAM_PTR_SZ_MAX +				\
-	/* Command describing the operation to perform */		\
-	 CAAM_CMD_SZ)
-
 struct caam_blob_priv {
 	struct device jrdev;
 };
@@ -109,7 +97,7 @@ int caam_process_blob(struct caam_blob_priv *priv,
 		len = info->input_len;
 	}
 
-	desc = kzalloc(CAAM_BLOB_DESC_BYTES_MAX, GFP_KERNEL);
+	desc = kzalloc(CAAM_DESC_BYTES_MAX, GFP_KERNEL);
 	if (!desc)
 		return -ENOMEM;
 

base-commit: 04cd6899aaaeeab82afb97e58eb8619fde35b47d

Signature · 1 line
2.50.1 (Apple Git-155)