Skip to content

Commit 67dc0b2

Browse files
committed
dmidecode: Fortify entry point length checks
Ensure that the SMBIOS entry point is long enough to include all the fields we need. Otherwise it is pointless to even attempt to verify its checksum. A similar check was added to the SMBIOS entry point parser in the Linux kernel. Signed-off-by: Jean Delvare <[email protected]>
1 parent f801673 commit 67dc0b2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

dmidecode.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5700,7 +5700,8 @@ static int smbios3_decode(u8 *buf, const char *devmem, u32 flags)
57005700
return 0;
57015701
}
57025702

5703-
if (!checksum(buf, buf[0x06]))
5703+
if (buf[0x06] < 0x18
5704+
|| !checksum(buf, buf[0x06]))
57045705
return 0;
57055706

57065707
ver = (buf[0x07] << 16) + (buf[0x08] << 8) + buf[0x09];
@@ -5747,7 +5748,12 @@ static int smbios_decode(u8 *buf, const char *devmem, u32 flags)
57475748
return 0;
57485749
}
57495750

5750-
if (!checksum(buf, buf[0x05])
5751+
/*
5752+
* The size of this structure is 0x1F bytes, but we also accept value
5753+
* 0x1E due to a mistake in SMBIOS specification version 2.1.
5754+
*/
5755+
if (buf[0x05] < 0x1E
5756+
|| !checksum(buf, buf[0x05])
57515757
|| memcmp(buf + 0x10, "_DMI_", 5) != 0
57525758
|| !checksum(buf + 0x10, 0x0F))
57535759
return 0;

0 commit comments

Comments
 (0)