diff mbox series

[v3,4/9] i2c-mlxbf: prevent stack overflow in mlxbf_i2c_smbus_start_transaction()

Message ID 20220908173544.32615-5-asmaa@nvidia.com
State Superseded
Headers show
Series i2c-mlxbf.c: bug fixes and new feature support | expand

Commit Message

Asmaa Mnebhi Sept. 8, 2022, 5:35 p.m. UTC
memcpy() is called in a loop while 'operation->length' upper bound
is not checked and 'data_idx' also increments.

Fixes: b5b5b32081cd206b ("i2c: mlxbf: I2C SMBus driver for Mellanox BlueField SoC")
Reviewed-by: Khalil Blaiech <kblaiech@nvidia.com>
Signed-off-by: Asmaa Mnebhi <asmaa@nvidia.com>
---
 drivers/i2c/busses/i2c-mlxbf.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Wolfram Sang Sept. 17, 2022, 6:14 p.m. UTC | #1
On Thu, Sep 08, 2022 at 01:35:39PM -0400, Asmaa Mnebhi wrote:
> memcpy() is called in a loop while 'operation->length' upper bound
> is not checked and 'data_idx' also increments.
> 
> Fixes: b5b5b32081cd206b ("i2c: mlxbf: I2C SMBus driver for Mellanox BlueField SoC")
> Reviewed-by: Khalil Blaiech <kblaiech@nvidia.com>
> Signed-off-by: Asmaa Mnebhi <asmaa@nvidia.com>

Fixed the prefix in $subject and applied to for-current, thanks!
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-mlxbf.c b/drivers/i2c/busses/i2c-mlxbf.c
index da0bdbd66e2e..a8c5fef3f1cd 100644
--- a/drivers/i2c/busses/i2c-mlxbf.c
+++ b/drivers/i2c/busses/i2c-mlxbf.c
@@ -731,6 +731,9 @@  mlxbf_i2c_smbus_start_transaction(struct mlxbf_i2c_priv *priv,
 		if (flags & MLXBF_I2C_F_WRITE) {
 			write_en = 1;
 			write_len += operation->length;
+			if (data_idx + operation->length >
+					MLXBF_I2C_MASTER_DATA_DESC_SIZE)
+				return -ENOBUFS;
 			memcpy(data_desc + data_idx,
 			       operation->buffer, operation->length);
 			data_idx += operation->length;