All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] e100: prevent shift out-of-bounds in e100_eeprom_load
@ 2026-08-07 14:56 ` pavankumaryalagada
  0 siblings, 0 replies; 4+ messages in thread
From: pavankumaryalagada @ 2026-08-07 14:56 UTC (permalink / raw)
  To: intel-wired-lan, netdev
  Cc: anthony.l.nguyen, przemyslaw.kitszel, andrew+netdev, davem,
	edumazet, kuba, pabeni, linux-kernel, skhan, pavankumaryalagada,
	syzbot+e0abb1d45ac291ebebeb

From: Yalagada Pavan Kumar <pavankumaryalagada@gmail.com>

When reading the EEPROM address length, e100_eeprom_read() can return
an invalid length (0 or >= 16). Passing an invalid addr_len to bit-shift
operations causes a shift out-of-bounds, triggering a kernel panic or
UBSAN warning.

Validate addr_len after reading it from EEPROM and return -EINVAL if
the value is out of bounds. Additionally, use 1U to prevent
signed integer overflow when calculating eeprom_wc.

Reported-by: syzbot+e0abb1d45ac291ebebeb@syzkaller.appspotmail.com
Tested-by: syzbot+e0abb1d45ac291ebebeb@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=e0abb1d45ac291ebebeb
Signed-off-by: Yalagada Pavan Kumar <pavankumaryalagada@gmail.com>
---
Tested using syzbot c reproducer.
---
 drivers/net/ethernet/intel/e100.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c
index 29960762e64a..1de5cd41ea0c 100644
--- a/drivers/net/ethernet/intel/e100.c
+++ b/drivers/net/ethernet/intel/e100.c
@@ -744,7 +744,12 @@ static __le16 e100_eeprom_read(struct nic *nic, u16 *addr_len, u16 addr)
 		 * complete address.  Use this to adjust addr_len. */
 		ctrl = ioread8(&nic->csr->eeprom_ctrl_lo);
 		if (!(ctrl & eedo) && i > 16) {
-			*addr_len -= (i - 16);
+			u16 len = i - 16;
+
+			if (len > *addr_len)
+				*addr_len = 0;
+			else
+				*addr_len -= len;
 			i = 17;
 		}
 
@@ -765,7 +770,15 @@ 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);
-	nic->eeprom_wc = 1 << addr_len;
+
+	if (!addr_len || addr_len >= 16) {
+		netif_err(nic, probe, nic->netdev,
+			"Invalid EEPROM address length %u\n",
+			addr_len);
+		return -EINVAL;
+	}
+
+	nic->eeprom_wc = 1U << addr_len;
 
 	for (addr = 0; addr < nic->eeprom_wc; addr++) {
 		nic->eeprom[addr] = e100_eeprom_read(nic, &addr_len, addr);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Intel-wired-lan] [PATCH] e100: prevent shift out-of-bounds in e100_eeprom_load
@ 2026-08-07 14:56 ` pavankumaryalagada
  0 siblings, 0 replies; 4+ messages in thread
From: pavankumaryalagada @ 2026-08-07 14:56 UTC (permalink / raw)
  To: intel-wired-lan, netdev
  Cc: anthony.l.nguyen, przemyslaw.kitszel, andrew+netdev, davem,
	edumazet, kuba, pabeni, linux-kernel, skhan, pavankumaryalagada,
	syzbot+e0abb1d45ac291ebebeb

From: Yalagada Pavan Kumar <pavankumaryalagada@gmail.com>

When reading the EEPROM address length, e100_eeprom_read() can return
an invalid length (0 or >= 16). Passing an invalid addr_len to bit-shift
operations causes a shift out-of-bounds, triggering a kernel panic or
UBSAN warning.

Validate addr_len after reading it from EEPROM and return -EINVAL if
the value is out of bounds. Additionally, use 1U to prevent
signed integer overflow when calculating eeprom_wc.

Reported-by: syzbot+e0abb1d45ac291ebebeb@syzkaller.appspotmail.com
Tested-by: syzbot+e0abb1d45ac291ebebeb@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=e0abb1d45ac291ebebeb
Signed-off-by: Yalagada Pavan Kumar <pavankumaryalagada@gmail.com>
---
Tested using syzbot c reproducer.
---
 drivers/net/ethernet/intel/e100.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c
index 29960762e64a..1de5cd41ea0c 100644
--- a/drivers/net/ethernet/intel/e100.c
+++ b/drivers/net/ethernet/intel/e100.c
@@ -744,7 +744,12 @@ static __le16 e100_eeprom_read(struct nic *nic, u16 *addr_len, u16 addr)
 		 * complete address.  Use this to adjust addr_len. */
 		ctrl = ioread8(&nic->csr->eeprom_ctrl_lo);
 		if (!(ctrl & eedo) && i > 16) {
-			*addr_len -= (i - 16);
+			u16 len = i - 16;
+
+			if (len > *addr_len)
+				*addr_len = 0;
+			else
+				*addr_len -= len;
 			i = 17;
 		}
 
@@ -765,7 +770,15 @@ 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);
-	nic->eeprom_wc = 1 << addr_len;
+
+	if (!addr_len || addr_len >= 16) {
+		netif_err(nic, probe, nic->netdev,
+			"Invalid EEPROM address length %u\n",
+			addr_len);
+		return -EINVAL;
+	}
+
+	nic->eeprom_wc = 1U << addr_len;
 
 	for (addr = 0; addr < nic->eeprom_wc; addr++) {
 		nic->eeprom[addr] = e100_eeprom_read(nic, &addr_len, addr);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Intel-wired-lan] [PATCH] e100: prevent shift out-of-bounds in e100_eeprom_load
  2026-08-07 14:56 ` [Intel-wired-lan] " pavankumaryalagada
  (?)
@ 2026-08-08 15:12 ` Kohei Enju
  2026-08-08 19:09   ` Yalagada Pavan Kumar
  -1 siblings, 1 reply; 4+ messages in thread
From: Kohei Enju @ 2026-08-08 15:12 UTC (permalink / raw)
  To: pavankumaryalagada
  Cc: intel-wired-lan, netdev, anthony.l.nguyen, przemyslaw.kitszel,
	andrew+netdev, davem, edumazet, kuba, pabeni, linux-kernel, skhan,
	syzbot+e0abb1d45ac291ebebeb

On 08/07 20:26, pavankumaryalagada@gmail.com wrote:
> From: Yalagada Pavan Kumar <pavankumaryalagada@gmail.com>
> 
> When reading the EEPROM address length, e100_eeprom_read() can return
> an invalid length (0 or >= 16). Passing an invalid addr_len to bit-shift
> operations causes a shift out-of-bounds, triggering a kernel panic or
> UBSAN warning.
> 
> Validate addr_len after reading it from EEPROM and return -EINVAL if
> the value is out of bounds. Additionally, use 1U to prevent
> signed integer overflow when calculating eeprom_wc.
> 
> Reported-by: syzbot+e0abb1d45ac291ebebeb@syzkaller.appspotmail.com
> Tested-by: syzbot+e0abb1d45ac291ebebeb@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=e0abb1d45ac291ebebeb
> Signed-off-by: Yalagada Pavan Kumar <pavankumaryalagada@gmail.com>
> ---
> Tested using syzbot c reproducer.
> ---
>  drivers/net/ethernet/intel/e100.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c
> index 29960762e64a..1de5cd41ea0c 100644
> --- a/drivers/net/ethernet/intel/e100.c
> +++ b/drivers/net/ethernet/intel/e100.c
> @@ -744,7 +744,12 @@ static __le16 e100_eeprom_read(struct nic *nic, u16 *addr_len, u16 addr)
>  		 * complete address.  Use this to adjust addr_len. */
>  		ctrl = ioread8(&nic->csr->eeprom_ctrl_lo);
>  		if (!(ctrl & eedo) && i > 16) {
> -			*addr_len -= (i - 16);
> +			u16 len = i - 16;
> +
> +			if (len > *addr_len)
> +				*addr_len = 0;
> +			else
> +				*addr_len -= len;
>  			i = 17;
>  		}
>  
> @@ -765,7 +770,15 @@ 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);
> -	nic->eeprom_wc = 1 << addr_len;
> +
> +	if (!addr_len || addr_len >= 16) {
> +		netif_err(nic, probe, nic->netdev,
> +			"Invalid EEPROM address length %u\n",
> +			addr_len);
> +		return -EINVAL;

An invalid address length here appears to indicate an unexpected
response from the EEPROM, rather than an invalid argument. Therefore,
-EINVAL seems somewhat misleading. Would -EIO be more appropriate here?

Also, e100_eeprom_save() seems to have the same pattern. Shouldn't we
fix that as well?

> +	}
> +
> +	nic->eeprom_wc = 1U << addr_len;

The commit message says that the U suffix prevents signed integer
overflow. However, after the validation addr_len is in [1, 15], so 1 <<
addr_len cannot overflow an int. I think what prevents the out-of-bounds
shift is the validation, not the U.

>  
>  	for (addr = 0; addr < nic->eeprom_wc; addr++) {
>  		nic->eeprom[addr] = e100_eeprom_read(nic, &addr_len, addr);
> -- 
> 2.43.0
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Intel-wired-lan] [PATCH] e100: prevent shift out-of-bounds in e100_eeprom_load
  2026-08-08 15:12 ` Kohei Enju
@ 2026-08-08 19:09   ` Yalagada Pavan Kumar
  0 siblings, 0 replies; 4+ messages in thread
From: Yalagada Pavan Kumar @ 2026-08-08 19:09 UTC (permalink / raw)
  To: Kohei Enju
  Cc: intel-wired-lan, netdev, anthony.l.nguyen, przemyslaw.kitszel,
	andrew+netdev, davem, edumazet, kuba, pabeni, linux-kernel, skhan,
	syzbot+e0abb1d45ac291ebebeb

On Sun, Aug 09, 2026 at 12:12:31AM +0900, Kohei Enju wrote:
> On 08/07 20:26, pavankumaryalagada@gmail.com wrote:
> > From: Yalagada Pavan Kumar <pavankumaryalagada@gmail.com>
> > 
> > When reading the EEPROM address length, e100_eeprom_read() can return
> > an invalid length (0 or >= 16). Passing an invalid addr_len to bit-shift
> > operations causes a shift out-of-bounds, triggering a kernel panic or
> > UBSAN warning.
> > 
> > Validate addr_len after reading it from EEPROM and return -EINVAL if
> > the value is out of bounds. Additionally, use 1U to prevent
> > signed integer overflow when calculating eeprom_wc.
> > 
> > Reported-by: syzbot+e0abb1d45ac291ebebeb@syzkaller.appspotmail.com
> > Tested-by: syzbot+e0abb1d45ac291ebebeb@syzkaller.appspotmail.com
> > Closes: https://syzkaller.appspot.com/bug?extid=e0abb1d45ac291ebebeb
> > Signed-off-by: Yalagada Pavan Kumar <pavankumaryalagada@gmail.com>
> > ---
> > Tested using syzbot c reproducer.
> > ---
> >  drivers/net/ethernet/intel/e100.c | 17 +++++++++++++++--
> >  1 file changed, 15 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c
> > index 29960762e64a..1de5cd41ea0c 100644
> > --- a/drivers/net/ethernet/intel/e100.c
> > +++ b/drivers/net/ethernet/intel/e100.c
> > @@ -744,7 +744,12 @@ static __le16 e100_eeprom_read(struct nic *nic, u16 *addr_len, u16 addr)
> >  		 * complete address.  Use this to adjust addr_len. */
> >  		ctrl = ioread8(&nic->csr->eeprom_ctrl_lo);
> >  		if (!(ctrl & eedo) && i > 16) {
> > -			*addr_len -= (i - 16);
> > +			u16 len = i - 16;
> > +
> > +			if (len > *addr_len)
> > +				*addr_len = 0;
> > +			else
> > +				*addr_len -= len;
> >  			i = 17;
> >  		}
> >  
> > @@ -765,7 +770,15 @@ 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);
> > -	nic->eeprom_wc = 1 << addr_len;
> > +
> > +	if (!addr_len || addr_len >= 16) {
> > +		netif_err(nic, probe, nic->netdev,
> > +			"Invalid EEPROM address length %u\n",
> > +			addr_len);
> > +		return -EINVAL;
> 
> An invalid address length here appears to indicate an unexpected
> response from the EEPROM, rather than an invalid argument. Therefore,
> -EINVAL seems somewhat misleading. Would -EIO be more appropriate here?
Agreed, addr_len comes from an unexpected EEPROM response,
so i will change -EINVAL to -EIO.
> 
> Also, e100_eeprom_save() seems to have the same pattern. Shouldn't we
> fix that as well?
yes, i'll fix e100_eeprom_save() as well. 
> 
> > +	}
> > +
> > +	nic->eeprom_wc = 1U << addr_len;
> 
> The commit message says that the U suffix prevents signed integer
> overflow. However, after the validation addr_len is in [1, 15], so 1 <<
> addr_len cannot overflow an int. I think what prevents the out-of-bounds
> shift is the validation, not the U.
Agreed, I'll remove the unnecessary U suffix.
I made these changes and will send v2.
> 
> >  
> >  	for (addr = 0; addr < nic->eeprom_wc; addr++) {
> >  		nic->eeprom[addr] = e100_eeprom_read(nic, &addr_len, addr);
> > -- 
> > 2.43.0
> > 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-08 19:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-07 14:56 [PATCH] e100: prevent shift out-of-bounds in e100_eeprom_load pavankumaryalagada
2026-08-07 14:56 ` [Intel-wired-lan] " pavankumaryalagada
2026-08-08 15:12 ` Kohei Enju
2026-08-08 19:09   ` Yalagada Pavan Kumar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.