Skip to content

Commit 0aec321

Browse files
vlifshtsgregkh
authored andcommitted
e1000e: fix heap overflow in e1000_set_eeprom
commit 90fb7db 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>
1 parent 3c26a8d commit 0aec321

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,12 +549,12 @@ static int e1000_set_eeprom(struct net_device *netdev,
549549
{
550550
struct e1000_adapter *adapter = netdev_priv(netdev);
551551
struct e1000_hw *hw = &adapter->hw;
552+
size_t total_len, max_len;
552553
u16 *eeprom_buff;
553-
void *ptr;
554-
int max_len;
554+
int ret_val = 0;
555555
int first_word;
556556
int last_word;
557-
int ret_val = 0;
557+
void *ptr;
558558
u16 i;
559559

560560
if (eeprom->len == 0)
@@ -569,6 +569,10 @@ static int e1000_set_eeprom(struct net_device *netdev,
569569

570570
max_len = hw->nvm.word_size * 2;
571571

572+
if (check_add_overflow(eeprom->offset, eeprom->len, &total_len) ||
573+
total_len > max_len)
574+
return -EFBIG;
575+
572576
first_word = eeprom->offset >> 1;
573577
last_word = (eeprom->offset + eeprom->len - 1) >> 1;
574578
eeprom_buff = kmalloc(max_len, GFP_KERNEL);

0 commit comments

Comments
 (0)