Skip to content

Commit e5cefe3

Browse files
Ard Biesheuvelgregkh
authored andcommitted
efi: Avoid potential crashes, fix the 'struct efi_pci_io_protocol_32' definition for mixed mode
commit 0b3225a upstream. Mixed mode allows a kernel built for x86_64 to interact with 32-bit EFI firmware, but requires us to define all struct definitions carefully when it comes to pointer sizes. 'struct efi_pci_io_protocol_32' currently uses a 'void *' for the 'romimage' field, which will be interpreted as a 64-bit field on such kernels, potentially resulting in bogus memory references and subsequent crashes. Tested-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: <stable@vger.kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Matt Fleming <matt@codeblueprint.co.uk> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20180504060003.19618-13-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 83a39c0 commit e5cefe3

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎arch/x86/boot/compressed/eboot.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ __setup_efi_pci32(efi_pci_io_protocol_32 *pci, struct pci_setup_rom **__rom)
163163
if (status != EFI_SUCCESS)
164164
goto free_struct;
165165

166-
memcpy(rom->romdata, pci->romimage, pci->romsize);
166+
memcpy(rom->romdata, (void *)(unsigned long)pci->romimage,
167+
pci->romsize);
167168
return status;
168169

169170
free_struct:
@@ -269,7 +270,8 @@ __setup_efi_pci64(efi_pci_io_protocol_64 *pci, struct pci_setup_rom **__rom)
269270
if (status != EFI_SUCCESS)
270271
goto free_struct;
271272

272-
memcpy(rom->romdata, pci->romimage, pci->romsize);
273+
memcpy(rom->romdata, (void *)(unsigned long)pci->romimage,
274+
pci->romsize);
273275
return status;
274276

275277
free_struct:

‎include/linux/efi.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ typedef struct {
395395
u32 attributes;
396396
u32 get_bar_attributes;
397397
u32 set_bar_attributes;
398-
uint64_t romsize;
399-
void *romimage;
398+
u64 romsize;
399+
u32 romimage;
400400
} efi_pci_io_protocol_32;
401401

402402
typedef struct {
@@ -415,8 +415,8 @@ typedef struct {
415415
u64 attributes;
416416
u64 get_bar_attributes;
417417
u64 set_bar_attributes;
418-
uint64_t romsize;
419-
void *romimage;
418+
u64 romsize;
419+
u64 romimage;
420420
} efi_pci_io_protocol_64;
421421

422422
typedef struct {

0 commit comments

Comments
 (0)