Error handling corner case found during audits
Subsystems (2)
Not sure what should happen here.
drivers/net/e1000e/ethtool.c +2 -0
@@ -494,6 +494,8 @@for (i =0 ; i < last_word - first_word +1 ; i++) { ret_val =e1000_read_nvm (hw, first_word + i,1 , &eeprom_buff[i]); +/* ERROR: This path leaves eeprom_buf containing +old kernel bytes we then byteswap/return */ if (ret_val)break ; }
Quoted 7 lines · Alan Cox
Not sure what should happen here.
diff -u --new-file --recursive --exclude-from
/usr/src/excludelinux.vanilla-2.6.25-mm1/drivers/net/e1000e/ethtool.clinux-2.6.25-mm1/drivers/net/e1000e/ethtool.c
drivers/net/e1000e/ethtool.c line 501
Quoted 8 lines
drivers/net/e1000e/ethtool.c +2
-0@@ -494,6 +494,8 @@for (i =0 ; i < last_word - first_word +1 ; i++) { ret_val =e1000_read_nvm (hw, first_word + i,1 , &eeprom_buff[i]); +/* ERROR: This path leaves eeprom_buf containing +old kernel bytes we then byteswap/return */ if (ret_val)break ; }
either we fill the buffer with 0xff (the determined value for "empty eeprom"), or just kzalloc the buffer instead. This should be enough of a warning for the user that something is really wrong.
Auke
---
e1000e: don't return half-read eeprom on error
On a read error, e1000e might have returned uninitialized block of eeprom data back to userspace. The convention is that 0xff is "empty", so mark the entire eeprom as empty in case of an error.
---
drivers/net/e1000e/ethtool.c +5 -1
@@ -510,8 +510,12 @@ static int e1000_get_eeprom(struct net_device *netdev,for (i =0 ; i < last_word - first_word +1 ; i++) { ret_val =e1000_read_nvm (hw, first_word + i,1 , &eeprom_buff[i]); -if (ret_val) +if (ret_val) { +/* a read error occurred, throw away the +* result */ +memset (eeprom_buff,0xff ,sizeof (eeprom_buff));break ; + } } }
Jeff Garzik
AppliedQuoted 41 lines · Auke
Quoted 7 lines · Alan Cox
Not sure what should happen here.
diff -u --new-file --recursive --exclude-from
/usr/src/excludelinux.vanilla-2.6.25-mm1/drivers/net/e1000e/ethtool.clinux-2.6.25-mm1/drivers/net/e1000e/ethtool.cdrivers/net/e1000e/ethtool.c line 501
Quoted 8 lines
drivers/net/e1000e/ethtool.c +2
-0@@ -494,6 +494,8 @@for (i =0 ; i < last_word - first_word +1 ; i++) { ret_val =e1000_read_nvm (hw, first_word + i,1 , &eeprom_buff[i]); +/* ERROR: This path leaves eeprom_buf containing +old kernel bytes we then byteswap/return */ if (ret_val)break ; }either we fill the buffer with
0xff(the determined value for "empty eeprom"), or just kzalloc the buffer instead. This should be enough of a warning for the user that something is really wrong.Auke
---
e1000e: don't return half-read eeprom on error
On a read error, e1000e might have returned uninitialized block of eeprom data back to userspace. The convention is that
0xffis "empty", so mark the entire eeprom as empty in case of an error.Signed-off-by Auke Kok <[email protected]>---
drivers/net/e1000e/ethtool.c +0
-0@@ -510,8 +510,12 @@ static int e1000_get_eeprom(struct net_device *netdev,for (i =0 ; i < last_word - first_word +1 ; i++) { ret_val = e1000_read_nvm(hw, first_word + i, 1,
drivers/net/e1000e/ethtool.c static int e1000_get_eeprom(struct net_device *netdev, · line 520
Quoted 10 lines
drivers/net/e1000e/ethtool.c +5
-1&eeprom_buff[i]); -if (ret_val) +if (ret_val) { +/* a read error occurred, throw away the +* result */ +memset (eeprom_buff,0xff ,sizeof (eeprom_buff));break ; + } } }
applied