Skip to content

Commit bfbaafa

Browse files
jdelvareMatt Fleming
authored andcommitted
firmware: dmi_scan: Prevent dmi_num integer overflow
dmi_num is a u16, dmi_len is a u32, so this construct: dmi_num = dmi_len / 4; would result in an integer overflow for a DMI table larger than 256 kB. I've never see such a large table so far, but SMBIOS 3.0 makes it possible so maybe we'll see such tables in the future. So instead of faking a structure count when the entry point does not provide it, adjust the loop condition in dmi_table() to properly deal with the case where dmi_num is not set. This bug was introduced with the initial SMBIOS 3.0 support in commit fc43026 ("dmi: add support for SMBIOS 3.0 64-bit entry point"). Signed-off-by: Jean Delvare <jdelvare@suse.de> Cc: Matt Fleming <matt.fleming@intel.com> Cc: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org> Cc: <stable@vger.kernel.org> Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Matt Fleming <matt.fleming@intel.com>
1 parent 6d9ff47 commit bfbaafa

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

drivers/firmware/dmi_scan.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,13 @@ static void dmi_table(u8 *buf, u32 len, int num,
8686
int i = 0;
8787

8888
/*
89-
* Stop when we see all the items the table claimed to have
90-
* OR we run off the end of the table (also happens)
89+
* Stop when we have seen all the items the table claimed to have
90+
* (SMBIOS < 3.0 only) OR we reach an end-of-table marker OR we run
91+
* off the end of the table (should never happen but sometimes does
92+
* on bogus implementations.)
9193
*/
92-
while ((i < num) && (data - buf + sizeof(struct dmi_header)) <= len) {
94+
while ((!num || i < num) &&
95+
(data - buf + sizeof(struct dmi_header)) <= len) {
9396
const struct dmi_header *dm = (const struct dmi_header *)data;
9497

9598
/*
@@ -529,21 +532,10 @@ static int __init dmi_smbios3_present(const u8 *buf)
529532
if (memcmp(buf, "_SM3_", 5) == 0 &&
530533
buf[6] < 32 && dmi_checksum(buf, buf[6])) {
531534
dmi_ver = get_unaligned_be16(buf + 7);
535+
dmi_num = 0; /* No longer specified */
532536
dmi_len = get_unaligned_le32(buf + 12);
533537
dmi_base = get_unaligned_le64(buf + 16);
534538

535-
/*
536-
* The 64-bit SMBIOS 3.0 entry point no longer has a field
537-
* containing the number of structures present in the table.
538-
* Instead, it defines the table size as a maximum size, and
539-
* relies on the end-of-table structure type (#127) to be used
540-
* to signal the end of the table.
541-
* So let's define dmi_num as an upper bound as well: each
542-
* structure has a 4 byte header, so dmi_len / 4 is an upper
543-
* bound for the number of structures in the table.
544-
*/
545-
dmi_num = dmi_len / 4;
546-
547539
if (dmi_walk_early(dmi_decode) == 0) {
548540
pr_info("SMBIOS %d.%d present.\n",
549541
dmi_ver >> 8, dmi_ver & 0xFF);

0 commit comments

Comments
 (0)