Skip to contentSkip to conversation

xilinx: fru: fix OOB access in OEM MAC record parsing

PATCH Applied Pranav Tilak 2 participants 2 messages Sep 22 – Oct 13 Arm/Zynq architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xilinx: fru: fix OOB access in OEM MAC record parsing

In fru_parse_multirec() the OEM MAC memcpy uses the EEPROM record length minus the IANA/version prefix with no check against the destination. A short record makes that length negative and it is converted to a large unsigned size by memcpy(), while an oversized record writes past the stored MAC array.

Validate the OEM MAC record length before calculating the copy size. Return -EINVAL when the MAC payload is not a whole number of MAC addresses or exceeds the destination buffer.

Fixes 7a036b674fc8 ("fru: ops: Add support to read mac addresses from multirecord")
---
 board/xilinx/common/fru_ops.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
board/xilinx/common/fru_ops.c +6 -1
index 610293bccf7..24b135f7666 100644
@@ -260,8 +260,13 @@ static int fru_parse_multirec(unsigned long addr)
 			if (CONFIG_IS_ENABLED(FRU_SC))
 				type = FRU_SC_MACID;
 
-			if (mac->ver == type) {
+			if (mrc.len >= FRU_MULTIREC_MAC_OFFSET &&
+			    mac->ver == type) {
 				mac_len = mrc.len - FRU_MULTIREC_MAC_OFFSET;
+				if (mac_len % ETH_ALEN ||
+				    mac_len > sizeof(fru_data.mac.macid))
+					return -EINVAL;
+
 				memcpy(&fru_data.mac.macid, mac->macid, mac_len);
 			}
 		}
Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 25 lines · Pranav Tilak

In fru_parse_multirec() the OEM MAC memcpy uses the EEPROM record length minus the IANA/version prefix with no check against the destination. A short record makes that length negative and it is converted to a large unsigned size by memcpy(), while an oversized record writes past the stored MAC array.

Validate the OEM MAC record length before calculating the copy size. Return -EINVAL when the MAC payload is not a whole number of MAC addresses or exceeds the destination buffer.

Fixes 7a036b674fc8 ("fru: ops: Add support to read mac addresses from multirecord")
---
  board/xilinx/common/fru_ops.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
board/xilinx/common/fru_ops.c +0 -1
index 610293bccf7..24b135f7666 100644
@@ -260,8 +260,13 @@ static int fru_parse_multirec(unsigned long addr)
  			if (CONFIG_IS_ENABLED(FRU_SC))
  				type = FRU_SC_MACID;
 
-			if (mac->ver == type) {

board/xilinx/common/fru_ops.c static int fru_parse_multirec(unsigned long addr) · line 272

Quoted 10 lines
board/xilinx/common/fru_ops.c +6 -0
+			if (mrc.len >= FRU_MULTIREC_MAC_OFFSET &&
+			    mac->ver == type) {
  				mac_len = mrc.len - FRU_MULTIREC_MAC_OFFSET;
+				if (mac_len % ETH_ALEN ||
+				    mac_len > sizeof(fru_data.mac.macid))
+					return -EINVAL;
+
  				memcpy(&fru_data.mac.macid, mac->macid, mac_len);
  			}
  		}

Applied.
M