Fix a possible heap overflow in e1000_set_eeprom function by adding
input validation for the requested length of the change in the EEPROM.

Fixes: bc7f75fa9788 ("[E1000E]: New pci-express e1000 driver (currently for 
ICH9 devices only)")
Co-developed-by: Mikael Wessel <[email protected]>
Signed-off-by: Mikael Wessel <[email protected]>
Signed-off-by: Vitaly Lifshits <[email protected]>
---
 drivers/net/ethernet/intel/e1000e/ethtool.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/intel/e1000e/ethtool.c 
b/drivers/net/ethernet/intel/e1000e/ethtool.c
index 9364bc2b4eb1..a9f5ff047544 100644
--- a/drivers/net/ethernet/intel/e1000e/ethtool.c
+++ b/drivers/net/ethernet/intel/e1000e/ethtool.c
@@ -569,6 +569,10 @@ static int e1000_set_eeprom(struct net_device *netdev,
 
        max_len = hw->nvm.word_size * 2;
 
+       if (eeprom->len > max_len ||
+           eeprom->offset + eeprom->len > max_len)
+               return -EINVAL;
+
        first_word = eeprom->offset >> 1;
        last_word = (eeprom->offset + eeprom->len - 1) >> 1;
        eeprom_buff = kmalloc(max_len, GFP_KERNEL);
-- 
2.34.1

Reply via email to