Thread (2 messages) flat view 2 messages, 2 authors, 20d ago

[PATCH net v3] e100: prevent shift-out-of-bounds in EEPROM access

From: <hidden>
Date: 2026-08-16 11:39:29
Also in: intel-wired-lan, lkml
Subsystem: intel ethernet drivers, networking drivers, the rest · Maintainers: Tony Nguyen, Przemek Kitszel, Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds

From: Yalagada Pavan Kumar <redacted>

When reading the EEPROM address length, e100_eeprom_read() can return
an invalid length. This value is then used as a shift count when
calculating eeprom_wc, resulting in a shift-out-of-bounds UBSAN warning.

Stop EEPROM address probing if the detected address length exceeds
the initial address length to prevent addr_len from underflowing.

Validate addr_len after reading it from the EEPROM in both
e100_eeprom_load() and e100_eeprom_save(), and return -EIO
if the value is zero or greater than 8.

Reported-by: syzbot+e0abb1d45ac291ebebeb@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=e0abb1d45ac291ebebeb
Signed-off-by: Yalagada Pavan Kumar <redacted>
---
v3:
 - Prevent addr_len underflow during EEPROM probing.
 - Use BIT() and explicitly cast the result to u16 when assigning eeprom_wc.
 - Update the commit message and subject to reflect the scope of the fix.
 - verify the UBSAN failure with syzkaller reproducer before the fix
   and its absence after the fix.

v2: https://lore.kernel.org/all/20260810083355.21631-1-pavankumaryalagada@gmail.com/ (local)
 - Return -EIO instead of -EINVAL for an invalid EEPROM address length.
 - Validate addr_len in e100_eeprom_save() as well.
 - Drop the unnecessary 1U change in the shift.
 - Update the commit message.

v1: https://lore.kernel.org/all/20260807145626.52692-1-pavankumaryalagada@gmail.com/ (local)
---
 drivers/net/ethernet/intel/e100.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c
index 464dc2d6cdb5..5165f1d3c98f 100644
--- a/drivers/net/ethernet/intel/e100.c
+++ b/drivers/net/ethernet/intel/e100.c
@@ -746,10 +746,12 @@ static __le16 e100_eeprom_read(struct nic *nic, u16 *addr_len, u16 addr)
 		if (!(ctrl & eedo) && i > 16) {
 			u16 len = i - 16;
 
-			if (len > *addr_len)
+			if (len > *addr_len) {
 				*addr_len = 0;
-			else
-				*addr_len -= len;
+				break;
+			}
+
+			*addr_len -= len;
 			i = 17;
 		}
 
@@ -771,14 +773,14 @@ static int e100_eeprom_load(struct nic *nic)
 	/* Try reading with an 8-bit addr len to discover actual addr len */
 	e100_eeprom_read(nic, &addr_len, 0);
 
-	if (!addr_len || addr_len >= 16) {
+	if (!addr_len || addr_len > 8) {
 		netif_err(nic, probe, nic->netdev,
 			"Invalid EEPROM address length %u\n",
 			addr_len);
 		return -EIO;
 	}
 
-	nic->eeprom_wc = 1 << addr_len;
+	nic->eeprom_wc = (u16)BIT(addr_len);
 
 	for (addr = 0; addr < nic->eeprom_wc; addr++) {
 		nic->eeprom[addr] = e100_eeprom_read(nic, &addr_len, addr);
@@ -805,14 +807,14 @@ static int e100_eeprom_save(struct nic *nic, u16 start, u16 count)
 	/* Try reading with an 8-bit addr len to discover actual addr len */
 	e100_eeprom_read(nic, &addr_len, 0);
 
-	if (!addr_len || addr_len >= 16) {
+	if (!addr_len || addr_len > 8) {
 		netif_err(nic, probe, nic->netdev,
 			"Invalid EEPROM address length %u\n",
 			addr_len);
 		return -EIO;
 	}
 
-	nic->eeprom_wc = 1 << addr_len;
+	nic->eeprom_wc = (u16)BIT(addr_len);
 
 	if (start + count >= nic->eeprom_wc)
 		return -EINVAL;
-- 
2.43.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help