Skip to contentSkip to conversation

smbios: Add an explicit bounds check for Type 9 length

PATCH In review Raymond Mao 3 participants 3 messages Apr 22 – Apr 25 Library code

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 smbios: Add an explicit bounds check for Type 9 length

From: Raymond Mao <[email protected]>

Fix Coverity Scan defect on Type 9 length.
Type 9 formatted length is built dynamically from peer_grouping_count. Although peer_grouping_count is a byte, the resulting formatted area still must fit in the SMBIOS header length field (u8).
Add an explicit bounds check before extending len, so the size used by map_sysmem() and memset() is guaranteed to be valid and consistent with hdr.length.

Fixes a8442c226635 ("smbios: add support for dynamic generation of Type 9 system slot tables")

Addresses-Coverity-ID: CID 645487: Insecure data handling (TAINTED_SCALAR)

---
Changes in v2:
- return len 0 for errors to align with the existing convention of the file.

 lib/smbios.c | 3 +++
 1 file changed, 3 insertions(+)
lib/smbios.c +3 -0
index d5f18c8bd69..fdab5948aad 100644
@@ -1093,6 +1093,9 @@ static int smbios_write_type9_1slot(ulong *current, int handle,
 	 * TODO:
 	 * peer_groups = <peer_grouping_count> * SMBIOS_TYPE9_PGROUP_SIZE
 	 */
+	if (len + pgroups_size > U8_MAX)
+		return 0;
+
 	len += pgroups_size;
 
 	t = map_sysmem(*current, len);
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#1 lore raw

Thanks Raynond,

Quoted 11 lines · Raymond Mao

From: Raymond Mao <[email protected]>

Fix Coverity Scan defect on Type 9 length.
Type 9 formatted length is built dynamically from peer_grouping_count. Although peer_grouping_count is a byte, the resulting formatted area still must fit in the SMBIOS header length field (u8).
Add an explicit bounds check before extending len, so the size used by map_sysmem() and memset() is guaranteed to be valid and consistent with hdr.length.

Quoted 4 lines
Fixes a8442c226635 ("smbios: add support for dynamic generation of Type 9 system slot tables")

Addresses-Coverity-ID: CID 645487: Insecure data handling (TAINTED_SCALAR)

---

Quoted 24 lines

Changes in v2:
- return len 0 for errors to align with the existing convention of the file.

 lib/smbios.c | 3 +++
 1 file changed, 3 insertions(+)
lib/smbios.c +3 -1
index d5f18c8bd69..fdab5948aad 100644
@@ -1093,6 +1093,9 @@ static int smbios_write_type9_1slot(ulong *current, int handle,
         * TODO:
         * peer_groups = <peer_grouping_count> * SMBIOS_TYPE9_PGROUP_SIZE
         */
+       if (len + pgroups_size > U8_MAX)
+               return 0;
+
        len += pgroups_size;
 
        t = map_sysmem(*current, len);
--

2.25.1

Reviewed-by on v2 1/1
#2 lore raw
In reply to Raymond Mao
Quoted 10 lines · Raymond Mao

smbios: Add an explicit bounds check for Type 9 length

Fix Coverity Scan defect on Type 9 length.
Type 9 formatted length is built dynamically from peer_grouping_count. Although peer_grouping_count is a byte, the resulting formatted area still must fit in the SMBIOS header length field (u8).
Add an explicit bounds check before extending len, so the size used by map_sysmem() and memset() is guaranteed to be valid and consistent with hdr.length.

Quoted 6 lines
Fixes a8442c226635 ("smbios: add support for dynamic generation of Type 9 system slot tables")

Addresses-Coverity-ID: CID 645487: Insecure data handling (TAINTED_SCALAR)

lib/smbios.c | 3 +++

 1 file changed, 3 insertions(+)