Skip to content

Commit 1b09500

Browse files
ljd42cfriedt
authored andcommitted
drivers: crypto: crypto_ataes132a fix missing count check
Coverity reported an untrusted loop bound caused by a missing check on the count value in ataes132a_send_command() for the response received from the device. As per datasheet section 6.1, count should be at least 3 bytes (1 byte for count, and 2 bytes for the 16 bits CRC). While I'm expecting this condition to be very rare, it doesn't hurt to implement a proper checking and report an error if count<3. Coverity CID: 434625 Signed-off-by: Loic Domaigne <tech@domaigne.com>
1 parent cce11a5 commit 1b09500

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

drivers/crypto/crypto_ataes132a.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ static int ataes132a_send_command(const struct device *dev, uint8_t opcode,
110110
burst_read_i2c(&cfg->i2c, ATAES_COMMAND_MEM_ADDR, data->command_buffer, 64);
111111

112112
count = data->command_buffer[0];
113+
/* validate count: at least 3 bytes (1 for count, 2 for CRC) */
114+
if (count < 3) {
115+
LOG_ERR("invalid packet received: count=%d"
116+
" , expects count>=3", count);
117+
return -EINVAL;
118+
}
113119

114120
/* Calculate and validate response CRC */
115121
ataes132a_atmel_crc(data->command_buffer, count - 2, crc);
@@ -130,7 +136,11 @@ static int ataes132a_send_command(const struct device *dev, uint8_t opcode,
130136
burst_read_i2c(&cfg->i2c, ATAES_COMMAND_MEM_ADDR, data->command_buffer, 64);
131137

132138
count = data->command_buffer[0];
133-
139+
if (count < 3) {
140+
LOG_ERR("invalid packet received: count=%d"
141+
" , expects count>=3", count);
142+
return -EINVAL;
143+
}
134144
ataes132a_atmel_crc(data->command_buffer, count - 2, crc);
135145
retry_count++;
136146

0 commit comments

Comments
 (0)