Revert "i2c: fix stack buffer overflow vulnerability in i2c md command"
PATCH 1/2 Revert "i2c: fix stack buffer overflow vulnerability in i2c md command"
This reverts commit 8f8c04bf1ebbd2f72f1643e7ad9617dafa6e5409.
The commit is largely wrong and breaks most of i2c command functionality. The problem described in the aforementioned commit commit message is valid, however the commit itself does many more changes unrelated to fixing that one problem it describes. Those extra changes, namely the handling of i2c device address length as unsigned instead of signed integer, breaks the expectation that address length may be negative value. The negative value is used by DM to indicate that address length of device does not change.
The actual bug documented in commit 8f8c04bf1ebbd2f72f1643e7ad9617dafa6e5409 can be fixed by extra sanitization in separate patch.
--- cmd/i2c.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
cmd/i2c.c +12 -12
@@ -200,10 +200,10 @@ void i2c_init_board(void)* * Returns the address length. */ -static uint get_alen (char *arg,uint default_len) +static uint get_alen (char *arg,int default_len) { -uint j; -uint alen; +int j; +int alen; alen = default_len;for (j =0 ; j <8 ; j++) {
@@ -247,7 +247,7 @@ static int do_i2c_read(struct cmd_tbl *cmdtp, int flag, int argc, {uint chip;uint devaddr, length; -uint alen; +int alen;u_char *memaddr;int ret;#if CONFIG_IS_ENABLED (DM_I2C )
@@ -301,7 +301,7 @@ static int do_i2c_write(struct cmd_tbl *cmdtp, int flag, int argc, {uint chip;uint devaddr, length; -uint alen; +int alen;u_char *memaddr;int ret;#if CONFIG_IS_ENABLED (DM_I2C )
@@ -469,8 +469,8 @@ static int do_i2c_md(struct cmd_tbl *cmdtp, int flag, int argc, {uint chip;uint addr, length; -uint alen; -uint j, nbytes, linebytes; +int alen; +int j, nbytes, linebytes;int ret;#if CONFIG_IS_ENABLED (DM_I2C )struct udevice *dev;
@@ -589,9 +589,9 @@ static int do_i2c_mw(struct cmd_tbl *cmdtp, int flag, int argc, {uint chip;ulong addr; -uint alen; +int alen;uchar byte; -uint count; +int count;int ret;#if CONFIG_IS_ENABLED (DM_I2C )struct udevice *dev;
@@ -676,8 +676,8 @@ static int do_i2c_crc(struct cmd_tbl *cmdtp, int flag, int argc, {uint chip;ulong addr; -uint alen; -uint count; +int alen; +int count;uchar byte;ulong crc;ulong err;
@@ -985,7 +985,7 @@ static int do_i2c_loop(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) {uint chip; -uint alen; +int alen;uint addr;uint length;u_char bytes[16 ];
Signature · 1 line
2.35.1
PATCH 2/2 i2c: fix stack buffer overflow vulnerability in i2c md command
This reinstates fix from commit 8f8c04bf1ebbd2f72f1643e7ad9617dafa6e5409 without the changes unrelated to the actual fix. Avoid the underflow by setting only nbytes and linebytes as unsigned integers.
--- cmd/i2c.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
cmd/i2c.c +2 -1
@@ -470,7 +470,8 @@ static int do_i2c_md(struct cmd_tbl *cmdtp, int flag, int argc,uint chip;uint addr, length;int alen; -int j, nbytes, linebytes; +int j; +uint nbytes, linebytes;int ret;#if CONFIG_IS_ENABLED (DM_I2C )struct udevice *dev;
Signature · 1 line
2.35.1
Re: [PATCH 2/2] i2c: fix stack buffer overflow vulnerability in i2c md command
Quoted 29 lines · Marek Vasut
This reinstates fix from commit
8f8c04bf1ebbd2f72f1643e7ad9617dafa6e5409without the changes unrelated to the actual fix. Avoid the underflow by setting only nbytes and linebytes as unsigned integers.Signed-off-by Marek Vasut <[email protected]>Cc Heiko Schocher <[email protected]>Cc Nicolas Iooss <[email protected]>Cc Simon Glass <[email protected]>Cc Tim Harvey <[email protected]>--- cmd/i2c.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)cmd/i2c.c +2
-2@@ -470,7 +470,8 @@ static int do_i2c_md(struct cmd_tbl *cmdtp, int flag, int argc,uint chip;uint addr, length;int alen; -int j, nbytes, linebytes; +int j; +uint nbytes, linebytes;int ret;#if CONFIG_IS_ENABLED (DM_I2C )struct udevice *dev; --
Quoted 2 lines
2.35.1
Marek,
Did 8f8c04bf1ebbd2f72f1643e7ad9617dafa6e5409 get reverted then?
Best Regards,
Tim
Tim Harvey
Acked-byRe: [PATCH 2/2] i2c: fix stack buffer overflow vulnerability in i2c md command
Quoted 36 lines · Tim Harvey
Quoted 29 lines · Marek Vasut
This reinstates fix from commit
8f8c04bf1ebbd2f72f1643e7ad9617dafa6e5409without the changes unrelated to the actual fix. Avoid the underflow by setting only nbytes and linebytes as unsigned integers.Signed-off-by Marek Vasut <[email protected]>Cc Heiko Schocher <[email protected]>Cc Nicolas Iooss <[email protected]>Cc Simon Glass <[email protected]>Cc Tim Harvey <[email protected]>--- cmd/i2c.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)cmd/i2c.c +2
-2@@ -470,7 +470,8 @@ static int do_i2c_md(struct cmd_tbl *cmdtp, int flag, int argc,uint chip;uint addr, length;int alen; -int j, nbytes, linebytes; +int j; +uint nbytes, linebytes;int ret;#if CONFIG_IS_ENABLED (DM_I2C )struct udevice *dev; --Quoted 2 lines
2.35.1
Marek,
Quoted 2 lines
Did
8f8c04bf1ebbd2f72f1643e7ad9617dafa6e5409get reverted then?
Oh gosh... my bad for not seeing your first patch that reverts it!
Best Regards,
Tim
Re: [PATCH 2/2] i2c: fix stack buffer overflow vulnerability in i2c md command
In reply to Marek VasutQuoted 10 lines · Marek Vasut
This reinstates fix from commit
8f8c04bf1ebbd2f72f1643e7ad9617dafa6e5409without the changes unrelated to the actual fix. Avoid the underflow by setting only nbytes and linebytes as unsigned integers.Signed-off-by Marek Vasut <[email protected]>Cc Heiko Schocher <[email protected]>Cc Nicolas Iooss <[email protected]>Cc Simon Glass <[email protected]>Cc Tim Harvey <[email protected]>Acked-by Tim Harvey <[email protected]>
Applied to u-boot/master, thanks!
Signature · 1 line
Tom
Quoted 14 lines · Marek Vasut
This reverts commit
8f8c04bf1ebbd2f72f1643e7ad9617dafa6e5409.The commit is largely wrong and breaks most of i2c command functionality. The problem described in the aforementioned commit commit message is valid, however the commit itself does many more changes unrelated to fixing that one problem it describes. Those extra changes, namely the handling of i2c device address length as unsigned instead of signed integer, breaks the expectation that address length may be negative value. The negative value is used by DM to indicate that address length of device does not change.
The actual bug documented in commit
8f8c04bf1ebbd2f72f1643e7ad9617dafa6e5409can be fixed by extra sanitization in separate patch.
Quoted 8 lines
Signed-off-by Marek Vasut <[email protected]>Cc Heiko Schocher <[email protected]>Cc Nicolas Iooss <[email protected]>Cc Simon Glass <[email protected]>Cc Tim Harvey <[email protected]>--- cmd/i2c.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
Quoted 13 lines · Marek Vasut
This reverts commit
8f8c04bf1ebbd2f72f1643e7ad9617dafa6e5409.The commit is largely wrong and breaks most of i2c command functionality. The problem described in the aforementioned commit commit message is valid, however the commit itself does many more changes unrelated to fixing that one problem it describes. Those extra changes, namely the handling of i2c device address length as unsigned instead of signed integer, breaks the expectation that address length may be negative value. The negative value is used by DM to indicate that address length of device does not change.
The actual bug documented in commit
8f8c04bf1ebbd2f72f1643e7ad9617dafa6e5409can be fixed by extra sanitization in separate patch.
Quoted 6 lines
Signed-off-by Marek Vasut <[email protected]>Cc Heiko Schocher <[email protected]>Cc Nicolas Iooss <[email protected]>Cc Simon Glass <[email protected]>Cc Tim Harvey <[email protected]>Reviewed-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 1 line
Tom