xilinx: fru: fix OOB access in OEM MAC record parsing
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.
--- board/xilinx/common/fru_ops.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
board/xilinx/common/fru_ops.c +6 -1
@@ -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
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 bymemcpy(), while an oversized record writes past the stored MAC array.Validate the OEM MAC record length before calculating the copy size. Return
-EINVALwhen 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")Signed-off-by Pranav Tilak <[email protected]>--- board/xilinx/common/fru_ops.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)board/xilinx/common/fru_ops.c +0
-1@@ -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