Skip to content

Commit 52393d6

Browse files
garyrhookherbertx
authored andcommitted
crypto: ccp - Validate the the error value used to index error messages
The error code read from the queue status register is only 6 bits wide, but we need to verify its value is within range before indexing the error messages. Fixes: 81422ba ("crypto: ccp - Make syslog errors human-readable") Cc: <stable@vger.kernel.org> Reported-by: Cfir Cohen <cfir@google.com> Signed-off-by: Gary R Hook <gary.hook@amd.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent ae400be commit 52393d6

2 files changed

Lines changed: 52 additions & 46 deletions

File tree

‎drivers/crypto/ccp/ccp-dev.c‎

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,56 +35,62 @@ struct ccp_tasklet_data {
3535
};
3636

3737
/* Human-readable error strings */
38+
#define CCP_MAX_ERROR_CODE 64
3839
static char *ccp_error_codes[] = {
3940
"",
40-
"ERR 01: ILLEGAL_ENGINE",
41-
"ERR 02: ILLEGAL_KEY_ID",
42-
"ERR 03: ILLEGAL_FUNCTION_TYPE",
43-
"ERR 04: ILLEGAL_FUNCTION_MODE",
44-
"ERR 05: ILLEGAL_FUNCTION_ENCRYPT",
45-
"ERR 06: ILLEGAL_FUNCTION_SIZE",
46-
"ERR 07: Zlib_MISSING_INIT_EOM",
47-
"ERR 08: ILLEGAL_FUNCTION_RSVD",
48-
"ERR 09: ILLEGAL_BUFFER_LENGTH",
49-
"ERR 10: VLSB_FAULT",
50-
"ERR 11: ILLEGAL_MEM_ADDR",
51-
"ERR 12: ILLEGAL_MEM_SEL",
52-
"ERR 13: ILLEGAL_CONTEXT_ID",
53-
"ERR 14: ILLEGAL_KEY_ADDR",
54-
"ERR 15: 0xF Reserved",
55-
"ERR 16: Zlib_ILLEGAL_MULTI_QUEUE",
56-
"ERR 17: Zlib_ILLEGAL_JOBID_CHANGE",
57-
"ERR 18: CMD_TIMEOUT",
58-
"ERR 19: IDMA0_AXI_SLVERR",
59-
"ERR 20: IDMA0_AXI_DECERR",
60-
"ERR 21: 0x15 Reserved",
61-
"ERR 22: IDMA1_AXI_SLAVE_FAULT",
62-
"ERR 23: IDMA1_AIXI_DECERR",
63-
"ERR 24: 0x18 Reserved",
64-
"ERR 25: ZLIBVHB_AXI_SLVERR",
65-
"ERR 26: ZLIBVHB_AXI_DECERR",
66-
"ERR 27: 0x1B Reserved",
67-
"ERR 27: ZLIB_UNEXPECTED_EOM",
68-
"ERR 27: ZLIB_EXTRA_DATA",
69-
"ERR 30: ZLIB_BTYPE",
70-
"ERR 31: ZLIB_UNDEFINED_SYMBOL",
71-
"ERR 32: ZLIB_UNDEFINED_DISTANCE_S",
72-
"ERR 33: ZLIB_CODE_LENGTH_SYMBOL",
73-
"ERR 34: ZLIB _VHB_ILLEGAL_FETCH",
74-
"ERR 35: ZLIB_UNCOMPRESSED_LEN",
75-
"ERR 36: ZLIB_LIMIT_REACHED",
76-
"ERR 37: ZLIB_CHECKSUM_MISMATCH0",
77-
"ERR 38: ODMA0_AXI_SLVERR",
78-
"ERR 39: ODMA0_AXI_DECERR",
79-
"ERR 40: 0x28 Reserved",
80-
"ERR 41: ODMA1_AXI_SLVERR",
81-
"ERR 42: ODMA1_AXI_DECERR",
82-
"ERR 43: LSB_PARITY_ERR",
41+
"ILLEGAL_ENGINE",
42+
"ILLEGAL_KEY_ID",
43+
"ILLEGAL_FUNCTION_TYPE",
44+
"ILLEGAL_FUNCTION_MODE",
45+
"ILLEGAL_FUNCTION_ENCRYPT",
46+
"ILLEGAL_FUNCTION_SIZE",
47+
"Zlib_MISSING_INIT_EOM",
48+
"ILLEGAL_FUNCTION_RSVD",
49+
"ILLEGAL_BUFFER_LENGTH",
50+
"VLSB_FAULT",
51+
"ILLEGAL_MEM_ADDR",
52+
"ILLEGAL_MEM_SEL",
53+
"ILLEGAL_CONTEXT_ID",
54+
"ILLEGAL_KEY_ADDR",
55+
"0xF Reserved",
56+
"Zlib_ILLEGAL_MULTI_QUEUE",
57+
"Zlib_ILLEGAL_JOBID_CHANGE",
58+
"CMD_TIMEOUT",
59+
"IDMA0_AXI_SLVERR",
60+
"IDMA0_AXI_DECERR",
61+
"0x15 Reserved",
62+
"IDMA1_AXI_SLAVE_FAULT",
63+
"IDMA1_AIXI_DECERR",
64+
"0x18 Reserved",
65+
"ZLIBVHB_AXI_SLVERR",
66+
"ZLIBVHB_AXI_DECERR",
67+
"0x1B Reserved",
68+
"ZLIB_UNEXPECTED_EOM",
69+
"ZLIB_EXTRA_DATA",
70+
"ZLIB_BTYPE",
71+
"ZLIB_UNDEFINED_SYMBOL",
72+
"ZLIB_UNDEFINED_DISTANCE_S",
73+
"ZLIB_CODE_LENGTH_SYMBOL",
74+
"ZLIB _VHB_ILLEGAL_FETCH",
75+
"ZLIB_UNCOMPRESSED_LEN",
76+
"ZLIB_LIMIT_REACHED",
77+
"ZLIB_CHECKSUM_MISMATCH0",
78+
"ODMA0_AXI_SLVERR",
79+
"ODMA0_AXI_DECERR",
80+
"0x28 Reserved",
81+
"ODMA1_AXI_SLVERR",
82+
"ODMA1_AXI_DECERR",
8383
};
8484

85-
void ccp_log_error(struct ccp_device *d, int e)
85+
void ccp_log_error(struct ccp_device *d, unsigned int e)
8686
{
87-
dev_err(d->dev, "CCP error: %s (0x%x)\n", ccp_error_codes[e], e);
87+
if (WARN_ON(e >= CCP_MAX_ERROR_CODE))
88+
return;
89+
90+
if (e < ARRAY_SIZE(ccp_error_codes))
91+
dev_err(d->dev, "CCP error %d: %s\n", e, ccp_error_codes[e]);
92+
else
93+
dev_err(d->dev, "CCP error %d: Unknown Error\n", e);
8894
}
8995

9096
/* List of CCPs, CCP count, read-write access lock, and access functions

‎drivers/crypto/ccp/ccp-dev.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ struct ccp5_desc {
632632
void ccp_add_device(struct ccp_device *ccp);
633633
void ccp_del_device(struct ccp_device *ccp);
634634

635-
extern void ccp_log_error(struct ccp_device *, int);
635+
extern void ccp_log_error(struct ccp_device *, unsigned int);
636636

637637
struct ccp_device *ccp_alloc_struct(struct sp_device *sp);
638638
bool ccp_queues_suspended(struct ccp_device *ccp);

0 commit comments

Comments
 (0)