Skip to content

Commit de24ace

Browse files
Asmaa Mnebhiwsakernel
authored andcommitted
i2c: mlxbf: prevent stack overflow in mlxbf_i2c_smbus_start_transaction()
memcpy() is called in a loop while 'operation->length' upper bound is not checked and 'data_idx' also increments. Fixes: b5b5b32 ("i2c: mlxbf: I2C SMBus driver for Mellanox BlueField SoC") Reviewed-by: Khalil Blaiech <kblaiech@nvidia.com> Signed-off-by: Asmaa Mnebhi <asmaa@nvidia.com> Signed-off-by: Wolfram Sang <wsa@kernel.org>
1 parent 2a5be6d commit de24ace

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/i2c/busses/i2c-mlxbf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,9 @@ mlxbf_i2c_smbus_start_transaction(struct mlxbf_i2c_priv *priv,
738738
if (flags & MLXBF_I2C_F_WRITE) {
739739
write_en = 1;
740740
write_len += operation->length;
741+
if (data_idx + operation->length >
742+
MLXBF_I2C_MASTER_DATA_DESC_SIZE)
743+
return -ENOBUFS;
741744
memcpy(data_desc + data_idx,
742745
operation->buffer, operation->length);
743746
data_idx += operation->length;

0 commit comments

Comments
 (0)