[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220816225412.9095-6-asmaa@nvidia.com>
Date: Tue, 16 Aug 2022 18:54:10 -0400
From: Asmaa Mnebhi <asmaa@...dia.com>
To: Wolfram Sang <wsa+renesas@...g-engineering.com>,
linux-i2c@...r.kernel.org, linux-kernel@...r.kernel.org
Cc: Asmaa Mnebhi <asmaa@...dia.com>,
Khalil Blaiech <kblaiech@...dia.com>
Subject: [PATCH v1 5/7] 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.
Reviewed-by: Khalil Blaiech <kblaiech@...dia.com>
Signed-off-by: Asmaa Mnebhi <asmaa@...dia.com>
---
drivers/i2c/busses/i2c-mlxbf.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/i2c/busses/i2c-mlxbf.c b/drivers/i2c/busses/i2c-mlxbf.c
index 02ed6983c35c..c6959ba7113e 100644
--- a/drivers/i2c/busses/i2c-mlxbf.c
+++ b/drivers/i2c/busses/i2c-mlxbf.c
@@ -724,6 +724,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;
--
2.30.1
Powered by blists - more mailing lists