Skip to content

Commit 3b29348

Browse files
committed
firmware: coreboot: Check size of table entry and use flex-array
The memcpy() of the data following a coreboot_table_entry couldn't be evaluated by the compiler under CONFIG_FORTIFY_SOURCE. To make it easier to reason about, add an explicit flexible array member to struct coreboot_device so the entire entry can be copied at once. Additionally, validate the sizes before copying. Avoids this run-time false positive warning: memcpy: detected field-spanning write (size 168) of single field "&device->entry" at drivers/firmware/google/coreboot_table.c:103 (size 8) Reported-by: Paul Menzel <[email protected]> Link: https://lore.kernel.org/all/[email protected]/ Cc: Jack Rosenthal <[email protected]> Cc: Guenter Roeck <[email protected]> Cc: Julius Werner <[email protected]> Cc: Brian Norris <[email protected]> Cc: Stephen Boyd <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Julius Werner <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Stephen Boyd <[email protected]> Reviewed-by: Jack Rosenthal <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 88603b6 commit 3b29348

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

drivers/firmware/google/coreboot_table.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,19 @@ static int coreboot_table_populate(struct device *dev, void *ptr)
9393
for (i = 0; i < header->table_entries; i++) {
9494
entry = ptr_entry;
9595

96-
device = kzalloc(sizeof(struct device) + entry->size, GFP_KERNEL);
96+
if (entry->size < sizeof(*entry)) {
97+
dev_warn(dev, "coreboot table entry too small!\n");
98+
return -EINVAL;
99+
}
100+
101+
device = kzalloc(sizeof(device->dev) + entry->size, GFP_KERNEL);
97102
if (!device)
98103
return -ENOMEM;
99104

100105
device->dev.parent = dev;
101106
device->dev.bus = &coreboot_bus_type;
102107
device->dev.release = coreboot_device_release;
103-
memcpy(&device->entry, ptr_entry, entry->size);
108+
memcpy(device->raw, ptr_entry, entry->size);
104109

105110
switch (device->entry.tag) {
106111
case LB_TAG_CBMEM_ENTRY:

drivers/firmware/google/coreboot_table.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct coreboot_device {
7979
struct lb_cbmem_ref cbmem_ref;
8080
struct lb_cbmem_entry cbmem_entry;
8181
struct lb_framebuffer framebuffer;
82+
DECLARE_FLEX_ARRAY(u8, raw);
8283
};
8384
};
8485

0 commit comments

Comments
 (0)