Skip to content

Commit b930a4e

Browse files
vlifshtsUlrich Hecht
authored andcommitted
e1000e: fix heap overflow in e1000_set_eeprom
commit 90fb7db49c6dbac961c6b8ebfd741141ffbc8545 upstream. Fix a possible heap overflow in e1000_set_eeprom function by adding input validation for the requested length of the change in the EEPROM. In addition, change the variable type from int to size_t for better code practices and rearrange declarations to RCT. Cc: stable@vger.kernel.org Fixes: bc7f75f ("[E1000E]: New pci-express e1000 driver (currently for ICH9 devices only)") Co-developed-by: Mikael Wessel <post@mikaelkw.online> Signed-off-by: Mikael Wessel <post@mikaelkw.online> Signed-off-by: Vitaly Lifshits <vitaly.lifshits@intel.com> Tested-by: Mor Bar-Gabay <morx.bar.gabay@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Ulrich Hecht <uli@kernel.org>
1 parent 8506dd1 commit b930a4e

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

drivers/net/ethernet/intel/e1000e/ethtool.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,12 +552,12 @@ static int e1000_set_eeprom(struct net_device *netdev,
552552
{
553553
struct e1000_adapter *adapter = netdev_priv(netdev);
554554
struct e1000_hw *hw = &adapter->hw;
555+
size_t total_len, max_len;
555556
u16 *eeprom_buff;
556-
void *ptr;
557-
int max_len;
557+
int ret_val = 0;
558558
int first_word;
559559
int last_word;
560-
int ret_val = 0;
560+
void *ptr;
561561
u16 i;
562562

563563
if (eeprom->len == 0)
@@ -572,6 +572,10 @@ static int e1000_set_eeprom(struct net_device *netdev,
572572

573573
max_len = hw->nvm.word_size * 2;
574574

575+
if (check_add_overflow(eeprom->offset, eeprom->len, &total_len) ||
576+
total_len > max_len)
577+
return -EFBIG;
578+
575579
first_word = eeprom->offset >> 1;
576580
last_word = (eeprom->offset + eeprom->len - 1) >> 1;
577581
eeprom_buff = kmalloc(max_len, GFP_KERNEL);

0 commit comments

Comments
 (0)