Skip to content

Commit 59476f8

Browse files
nivedita76ardbiesheuvel
authored andcommitted
efi/x86: Only copy upto the end of setup_header
When copying the setup_header into the boot_params buffer, only the data that is actually part of the setup_header should be copied. efi_pe_entry() currently copies the entire second sector, which initializes some of the fields in boot_params beyond the setup_header with garbage (i.e. part of the real-mode boot code gets copied into those fields). This does not cause any issues currently because the fields that are overwritten are padding, BIOS EDD information that won't get used, and the E820 table which will get properly filled in later. Fix this to only copy data that is actually part of the setup_header structure. Signed-off-by: Arvind Sankar <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 0bda49f commit 59476f8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/firmware/efi/libstub/x86-stub.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <linux/efi.h>
1010
#include <linux/pci.h>
11+
#include <linux/stddef.h>
1112

1213
#include <asm/efi.h>
1314
#include <asm/e820/types.h>
@@ -388,8 +389,9 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
388389

389390
hdr = &boot_params->hdr;
390391

391-
/* Copy the second sector to boot_params */
392-
memcpy(&hdr->jump, image_base + 512, 512);
392+
/* Copy the setup header from the second sector to boot_params */
393+
memcpy(&hdr->jump, image_base + 512,
394+
sizeof(struct setup_header) - offsetof(struct setup_header, jump));
393395

394396
/*
395397
* Fill out some of the header fields ourselves because the

0 commit comments

Comments
 (0)