From 51ffa7e810ee243b24848a25c8f5193910886b32 Mon Sep 17 00:00:00 2001 From: Joel Kitching Date: Sat, 16 Mar 2019 16:58:27 +0800 Subject: vboot: move assert in vboot_migrate_cbmem Fix a potential null pointer dereference when calling memcpy. assert should be before the memcpy call, and not after. BUG=b:124141368, b:124192753 TEST=util/lint/checkpatch.pl -g origin/master..HEAD TEST=util/abuild/abuild -B -e -y -c 50 -p none -x TEST=make clean && make test-abuild BRANCH=none Change-Id: I5a2a99e906b9aa3bb33e1564d8d33a0aca7d06ac Signed-off-by: Joel Kitching Reviewed-on: https://review.coreboot.org/c/coreboot/+/31923 Reviewed-by: Furquan Shaikh Tested-by: build bot (Jenkins) --- src/security/vboot/common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/security/vboot/common.c b/src/security/vboot/common.c index 496ab782ab..47e1aa4f56 100644 --- a/src/security/vboot/common.c +++ b/src/security/vboot/common.c @@ -163,11 +163,12 @@ static void vboot_migrate_cbmem(int unused) size_t cbmem_size = wd_preram->buffer_offset + wd_preram->buffer_size; struct vboot_working_data *wd_cbmem = cbmem_add(CBMEM_ID_VBOOT_WORKBUF, cbmem_size); + assert(wd_cbmem != NULL); + printk(BIOS_DEBUG, "VBOOT: copying vboot_working_data (%zu bytes) to CBMEM...\n", cbmem_size); memcpy(wd_cbmem, wd_preram, cbmem_size); - assert(wd_cbmem != NULL); } ROMSTAGE_CBMEM_INIT_HOOK(vboot_migrate_cbmem) #elif CONFIG(VBOOT_STARTS_IN_ROMSTAGE) -- cgit v1.2.3