[PATCH 01/10] crypto: caam - Fix descriptor buffer overflow in caam_process_blob()

From: Lee Jones

Date: Mon Nov 23 2026 - 10:11:15 EST


Commit a703a4c2a328 ("KEYS: trusted: caam based protected key") switched
caam_process_blob() from append_seq_in_ptr_intlen() and
append_seq_out_ptr_intlen() to append_seq_in_ptr() and
append_seq_out_ptr(), each of which emits an extra 32-bit extended
length word, and added append_key(), append_fifo_store(), and
append_jump() when encapsulating a protected key.

However, CAAM_BLOB_DESC_BYTES_MAX was not updated and still reserves
only 44 or 52 bytes (for 32-bit or 64-bit DMA addresses), whereas
caam_process_blob() now writes up to 60 bytes for standard blobs on
64-bit DMA platforms and up to 72 or 88 bytes when encapsulating a
protected key, overflowing the kzalloc()-allocated job descriptor
buffer into adjacent slab memory.

Update CAAM_BLOB_DESC_BYTES_MAX to account for the protected-key
commands and the extended sequence pointer length words.

Fixes: a703a4c2a328 ("KEYS: trusted: caam based protected key")
Closes: https://sashiko.dev/#/bug/linux-fd968875-61a8-4100-ba0c-b9cd164d86e8
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/crypto/caam/blob_gen.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/caam/blob_gen.c b/drivers/crypto/caam/blob_gen.c
index c18dbac56493..b4fdc15dd0b6 100644
--- a/drivers/crypto/caam/blob_gen.c
+++ b/drivers/crypto/caam/blob_gen.c
@@ -23,12 +23,16 @@
#define CAAM_BLOB_DESC_BYTES_MAX \
/* Command to initialize & stating length of descriptor */ \
(CAAM_CMD_SZ + \
+ /* Commands to load plain key, store protected key and jump */ \
+ CAAM_CMD_SZ + CAAM_PTR_SZ_MAX + \
+ CAAM_CMD_SZ + CAAM_PTR_SZ_MAX + \
+ 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 to include input key + pointer and length */ \
+ 2 * CAAM_CMD_SZ + CAAM_PTR_SZ_MAX + \
+ /* Command to include output key + pointer and length */ \
+ 2 * CAAM_CMD_SZ + CAAM_PTR_SZ_MAX + \
/* Command describing the operation to perform */ \
CAAM_CMD_SZ)

--
2.56.1.750.gf70dc682cf-goog