Skip to contentSkip to conversation

ipmi: ipmb: Fix off-by-one size check on rcvlen

PATCH In review Colin King 2 participants 2 messages Oct 5, 2021

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 ipmi: ipmb: Fix off-by-one size check on rcvlen

From: Colin Ian King <[email protected]>

There is an off-by-one bounds check on the rcvlen causing a potential out of bounds write on iidev->rcvmsg. Fix this by using the >= operator on the bounds check rather than the > operator.

Addresses-Coverity: ("Out-of-bounds write")

Fixes 0ba0c3c5d1c1 ("ipmi:ipmb: Add initial support for IPMI over IPMB")
---
 drivers/char/ipmi/ipmi_ipmb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/ipmi/ipmi_ipmb.c +1 -1
index b10a1fd9c563..77ebec4ed28e 100644
@@ -192,7 +192,7 @@ static int ipmi_ipmb_slave_cb(struct i2c_client *client,
 		break;
 
 	case I2C_SLAVE_WRITE_RECEIVED:
-		if (iidev->rcvlen > sizeof(iidev->rcvmsg))
+		if (iidev->rcvlen >= sizeof(iidev->rcvmsg))
 			iidev->overrun = true;
 		else
 			iidev->rcvmsg[iidev->rcvlen++] = *val;
Signature · 1 line
2.32.0
#1 lore raw
Quoted 5 lines · Colin King

From: Colin Ian King <[email protected]>

There is an off-by-one bounds check on the rcvlen causing a potential out of bounds write on iidev->rcvmsg. Fix this by using the >= operator on the bounds check rather than the > operator.

Got it, thanks.

-corey

Quoted 30 lines

Addresses-Coverity: ("Out-of-bounds write")

Fixes 0ba0c3c5d1c1 ("ipmi:ipmb: Add initial support for IPMI over IPMB")
---
 drivers/char/ipmi/ipmi_ipmb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/ipmi/ipmi_ipmb.c +1 -1
index b10a1fd9c563..77ebec4ed28e 100644
@@ -192,7 +192,7 @@ static int ipmi_ipmb_slave_cb(struct i2c_client *client,
 		break;
 
 	case I2C_SLAVE_WRITE_RECEIVED:
-		if (iidev->rcvlen > sizeof(iidev->rcvmsg))
+		if (iidev->rcvlen >= sizeof(iidev->rcvmsg))
 			iidev->overrun = true;
 		else
 			iidev->rcvmsg[iidev->rcvlen++] = *val;
Signature · 8 lines
2.32.0



_______________________________________________
Openipmi-developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openipmi-developer