Skip to content

Commit 3efaa9c

Browse files
committed
linux/smbios: enforce memory header from spec 2.3 only
Allow optional fields for later specs. Signed-off-by: Brice Goglin <[email protected]>
1 parent db52ca9 commit 3efaa9c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

hwloc/topology-linux.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <sys/mman.h>
3838
#include <sys/syscall.h>
3939
#include <mntent.h>
40+
#include <stddef.h>
4041

4142
struct hwloc_linux_backend_data_s {
4243
char *root_path; /* NULL if unused */
@@ -6890,8 +6891,10 @@ struct hwloc_firmware_dmi_mem_device_header {
68906891
unsigned char serial_str_num;
68916892
unsigned char asset_tag_str_num;
68926893
unsigned char part_num_str_num;
6893-
/* don't include the following fields since we don't need them,
6894-
* some old implementations may miss them.
6894+
/* Here is the end of SMBIOS 2.3 fields (27 bytes),
6895+
* those are required for hwloc.
6896+
* Anything below (SMBIOS 2.6+) is optional for hwloc,
6897+
* we must to check header->length before reading them.
68956898
*/
68966899
};
68976900

@@ -7041,7 +7044,9 @@ hwloc__get_firmware_dmi_memory_info(struct hwloc_topology *topology,
70417044
fclose(fd);
70427045
break;
70437046
}
7044-
if (header.length < sizeof(header)) {
7047+
7048+
HWLOC_BUILD_ASSERT(offsetof(struct hwloc_firmware_dmi_mem_device_header, part_num_str_num) + sizeof(header.part_num_str_num) == 27);
7049+
if (header.length < 27) {
70457050
/* invalid, or too old entry/spec that doesn't contain what we need */
70467051
fclose(fd);
70477052
break;

0 commit comments

Comments
 (0)