Skip to contentSkip to conversation

ice: fix theoretical out-of-bounds access in ethtool link modes

PATCH In review Michal Schmidt 4 participants 4 messages Nov 30, 2023 – Dec 11, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ice: fix theoretical out-of-bounds access in ethtool link modes

To map phy types reported by the hardware to ethtool link mode bits, ice uses two lookup tables (phy_type_low_lkup, phy_type_high_lkup). The "low" table has 64 elements to cover every possible bit the hardware may report, but the "high" table has only 13. If the hardware reports a higher bit in phy_types_high, the driver would access memory beyond the lookup table's end.

Instead of iterating through all 64 bits of phy_types_{low,high}, use the sizes of the respective lookup tables.

Fixes 9136e1f1e5c3 ("ice: refactor PHY type to ethtool link mode")
---
 drivers/net/ethernet/intel/ice/ice_ethtool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_ethtool.c +2 -2
index a34083567e6f..bde9bc74f928 100644
@@ -1850,14 +1850,14 @@ ice_phy_type_to_ethtool(struct net_device *netdev,
 	linkmode_zero(ks->link_modes.supported);
 	linkmode_zero(ks->link_modes.advertising);
 
-	for (i = 0; i < BITS_PER_TYPE(u64); i++) {
+	for (i = 0; i < ARRAY_SIZE(phy_type_low_lkup); i++) {
 		if (phy_types_low & BIT_ULL(i))
 			ice_linkmode_set_bit(&phy_type_low_lkup[i], ks,
 					     req_speeds, advert_phy_type_lo,
 					     i);
 	}
 
-	for (i = 0; i < BITS_PER_TYPE(u64); i++) {
+	for (i = 0; i < ARRAY_SIZE(phy_type_high_lkup); i++) {
 		if (phy_types_high & BIT_ULL(i))
 			ice_linkmode_set_bit(&phy_type_high_lkup[i], ks,
 					     req_speeds, advert_phy_type_hi,
Signature · 1 line
2.41.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 27 lines · Michal Schmidt

To map phy types reported by the hardware to ethtool link mode bits, ice uses two lookup tables (phy_type_low_lkup, phy_type_high_lkup). The "low" table has 64 elements to cover every possible bit the hardware may report, but the "high" table has only 13. If the hardware reports a higher bit in phy_types_high, the driver would access memory beyond the lookup table's end.

Instead of iterating through all 64 bits of phy_types_{low,high}, use the sizes of the respective lookup tables.

Fixes 9136e1f1e5c3 ("ice: refactor PHY type to ethtool link mode")
---
  drivers/net/ethernet/intel/ice/ice_ethtool.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_ethtool.c +1 -1
index a34083567e6f..bde9bc74f928 100644
@@ -1850,14 +1850,14 @@ ice_phy_type_to_ethtool(struct net_device *netdev,
  	linkmode_zero(ks->link_modes.supported);
  	linkmode_zero(ks->link_modes.advertising);
 
-	for (i = 0; i < BITS_PER_TYPE(u64); i++) {
+	for (i = 0; i < ARRAY_SIZE(phy_type_low_lkup); i++) {
  		if (phy_types_low & BIT_ULL(i))

drivers/net/ethernet/intel/ice/ice_ethtool.c ice_phy_type_to_ethtool(struct net_device *netdev, · line 1863

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_ethtool.c +1 -1
  			ice_linkmode_set_bit(&phy_type_low_lkup[i], ks,
  					     req_speeds, advert_phy_type_lo,
  					     i);
  	}
 
-	for (i = 0; i < BITS_PER_TYPE(u64); i++) {
+	for (i = 0; i < ARRAY_SIZE(phy_type_high_lkup); i++) {
  		if (phy_types_high & BIT_ULL(i))
  			ice_linkmode_set_bit(&phy_type_high_lkup[i], ks,
  					     req_speeds, advert_phy_type_hi,

I guess that that "HW reported" number really goes through the FW in some way, so one could indeed spoil that in some way, what makes sense to target it at -net.

reviewer Reviewed-by
#2 lore raw
Quoted 41 lines · Przemek Kitszel
Quoted 25 lines · Michal Schmidt

To map phy types reported by the hardware to ethtool link mode bits, ice uses two lookup tables (phy_type_low_lkup, phy_type_high_lkup). The "low" table has 64 elements to cover every possible bit the hardware may report, but the "high" table has only 13. If the hardware reports a higher bit in phy_types_high, the driver would access memory beyond the lookup table's end.

Instead of iterating through all 64 bits of phy_types_{low,high}, use the sizes of the respective lookup tables.

Fixes 9136e1f1e5c3 ("ice: refactor PHY type to ethtool link mode")
---
  drivers/net/ethernet/intel/ice/ice_ethtool.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_ethtool.c +1 -1
index a34083567e6f..bde9bc74f928 100644
@@ -1850,14 +1850,14 @@ ice_phy_type_to_ethtool(struct net_device *netdev,
  	linkmode_zero(ks->link_modes.supported);
  	linkmode_zero(ks->link_modes.advertising);
-	for (i = 0; i < BITS_PER_TYPE(u64); i++) {
+	for (i = 0; i < ARRAY_SIZE(phy_type_low_lkup); i++) {

drivers/net/ethernet/intel/ice/ice_ethtool.c ice_phy_type_to_ethtool(struct net_device *netdev, · line 1861

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_ethtool.c +1 -1
  		if (phy_types_low & BIT_ULL(i))
  			ice_linkmode_set_bit(&phy_type_low_lkup[i], ks,
  					     req_speeds, advert_phy_type_lo,
  					     i);
  	}
-	for (i = 0; i < BITS_PER_TYPE(u64); i++) {
+	for (i = 0; i < ARRAY_SIZE(phy_type_high_lkup); i++) {
  		if (phy_types_high & BIT_ULL(i))
  			ice_linkmode_set_bit(&phy_type_high_lkup[i], ks,
  					     req_speeds, advert_phy_type_hi,

I guess that that "HW reported" number really goes through the FW in some way, so one could indeed spoil that in some way, what makes sense to target it at -net.

Quoted 1 line
Tested-by on v1 1/1
#3 lore raw
In reply to Michal Schmidt
Quoted 14 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Michal Schmidt
Sent: Thursday, November 30, 2023 10:28 PM
To: [email protected]
Cc: Nguyen, Anthony L <[email protected]>; Greenwalt, Paul <[email protected]>; [email protected]; Brandeburg, Jesse <[email protected]>
Subject: [Intel-wired-lan] [PATCH net] ice: fix theoretical out-of-bounds access in ethtool link modes

To map phy types reported by the hardware to ethtool link mode bits, ice uses two lookup tables (phy_type_low_lkup, phy_type_high_lkup). The "low" table has 64 elements to cover every possible bit the hardware may report, but the "high" table has only 13. If the hardware reports a higher bit in phy_types_high, the driver would access memory beyond the lookup table's end.

Quoted 9 lines

Instead of iterating through all 64 bits of phy_types_{low,high}, use the sizes of the respective lookup tables.

Fixes 9136e1f1e5c3 ("ice: refactor PHY type to ethtool link mode")
---
 drivers/net/ethernet/intel/ice/ice_ethtool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)