Skip to contentSkip to conversation

Revert commit 5dcd14ecd4 - breaks EFI boot with SLES11 elilo.efi

PATCH In review Robin Holt 7 participants 26 messages Feb 28, 2013 – Mar 7, 2013

Subsystems (2)
lore
Share & tools
lore

Robin Holt

author
#0 lore raw

If I revert that commit (5dcd14ecd4), It completes boot fine. With that commit applied, by ACPI tables (as well as much else) seems to be completely messed up. The ACPI XSDT table is removed, all the SRAT is gone. Much of the remaining ACPI table is messed up. Some of the EFI memory map is whacked.

If I change the following, things work:

arch/x86/include/asm/bootparam_utils.h +2 -0
index 5b5e9cb..85337ab 100644
@@ -19,9 +19,11 @@ static void sanitize_boot_params(struct boot_params *boot_params)
 {
        if (boot_params->sentinel) {
                /*fields in boot_params are not valid, clear them */
+#if 0
                memset(&boot_params->olpc_ofw_header, 0,
                       (char *)&boot_params->alt_mem_k -
                        (char *)&boot_params->olpc_ofw_header);
+#endif
                memset(&boot_params->kbd_status, 0,
                       (char *)&boot_params->hdr -
                       (char *)&boot_params->kbd_status);

Thanks,
Robin

#1 lore raw
Quoted 14 lines · Robin Holt

If I revert that commit (5dcd14ecd4), It completes boot fine. With that commit applied, by ACPI tables (as well as much else) seems to be completely messed up. The ACPI XSDT table is removed, all the SRAT is gone. Much of the remaining ACPI table is messed up. Some of the EFI memory map is whacked.

If I change the following, things work:

arch/x86/include/asm/bootparam_utils.h +0 -0
index 5b5e9cb..85337ab 100644
@@ -19,9 +19,11 @@ static void sanitize_boot_params(struct boot_params *boot_params)
 {

arch/x86/include/asm/bootparam_utils.h static void sanitize_boot_params(struct boot_params *boot_params) · line 29

Quoted 10 lines
arch/x86/include/asm/bootparam_utils.h +2 -0
        if (boot_params->sentinel) {
                /*fields in boot_params are not valid, clear them */
+#if 0
                memset(&boot_params->olpc_ofw_header, 0,
                       (char *)&boot_params->alt_mem_k -
                        (char *)&boot_params->olpc_ofw_header);
+#endif
                memset(&boot_params->kbd_status, 0,
                       (char *)&boot_params->hdr -
                       (char *)&boot_params->kbd_status);

Sounds like ELILO needs to be fixed to pass the boot_params correctly.

To support existing ELILO, it would be good to know exactly *which* fields ELILO pass in as garbage (because it does, that is why ->sentinel is nonzero) and use its bootloader ID to apply the proper brainwhack for the legacy versions.

-hpa

author
#2 lore raw
Quoted 28 lines · H. Peter Anvin
Quoted 14 lines · Robin Holt

If I revert that commit (5dcd14ecd4), It completes boot fine. With that commit applied, by ACPI tables (as well as much else) seems to be completely messed up. The ACPI XSDT table is removed, all the SRAT is gone. Much of the remaining ACPI table is messed up. Some of the EFI memory map is whacked.

If I change the following, things work:

arch/x86/include/asm/bootparam_utils.h +0 -0
index 5b5e9cb..85337ab 100644
@@ -19,9 +19,11 @@ static void sanitize_boot_params(struct boot_params *boot_params)
 {

arch/x86/include/asm/bootparam_utils.h static void sanitize_boot_params(struct boot_params *boot_params) · line 29

Quoted 10 lines
arch/x86/include/asm/bootparam_utils.h +2 -0
        if (boot_params->sentinel) {
                /*fields in boot_params are not valid, clear them */
+#if 0
                memset(&boot_params->olpc_ofw_header, 0,
                       (char *)&boot_params->alt_mem_k -
                        (char *)&boot_params->olpc_ofw_header);
+#endif
                memset(&boot_params->kbd_status, 0,
                       (char *)&boot_params->hdr -
                       (char *)&boot_params->kbd_status);

Sounds like ELILO needs to be fixed to pass the boot_params correctly.

Quoted 4 lines

To support existing ELILO, it would be good to know exactly *which* fields ELILO pass in as garbage (because it does, that is why ->sentinel is nonzero) and use its bootloader ID to apply the proper brainwhack for the legacy versions.

Any idea how I can dump that information?

Robin

#3 lore raw
Quoted 10 lines · Robin Holt
Quoted 7 lines

Sounds like ELILO needs to be fixed to pass the boot_params correctly.

To support existing ELILO, it would be good to know exactly *which* fields ELILO pass in as garbage (because it does, that is why ->sentinel is nonzero) and use its bootloader ID to apply the proper brainwhack for the legacy versions.

Any idea how I can dump that information?

Look at the source code and look at what fields it actually initializes.
Give us that list, and then we can work around elilo braindamage in the
kernel.

Then make it follow the boot spec:

Quoted 9 lines

In 32-bit boot protocol, the first step in loading a Linux kernel should be to setup the boot parameters (struct boot_params, traditionally known as "zero page"). The memory for struct boot_params should be allocated and initialized to all zero. Then the setup header from offset 0x01f1 of kernel image on should be loaded into struct boot_params and examined. The end of setup header can be calculated as follow:

        0x0202 + byte value at offset 0x0201

... so we don't have to.

-hpa

#4 lore raw
Quoted 26 lines · H. Peter Anvin
Quoted 10 lines · Robin Holt
Quoted 7 lines

Sounds like ELILO needs to be fixed to pass the boot_params correctly.

To support existing ELILO, it would be good to know exactly *which* fields ELILO pass in as garbage (because it does, that is why ->sentinel is nonzero) and use its bootloader ID to apply the proper brainwhack for the legacy versions.

Any idea how I can dump that information?

Look at the source code and look at what fields it actually initializes.
Give us that list, and then we can work around elilo braindamage in the
kernel.

Then make it follow the boot spec:

Quoted 8 lines

In 32-bit boot protocol, the first step in loading a Linux kernel should be to setup the boot parameters (struct boot_params, traditionally known as "zero page"). The memory for struct boot_params should be allocated and initialized to all zero. Then the setup header from offset 0x01f1 of kernel image on should be loaded into struct boot_params and examined. The end of setup header can be calculated as follow:

Quoted 3 lines
Quoted 1 line
        0x0202 + byte value at offset 0x0201

... so we don't have to.

Good, kexec is not only one.

ELILO has one.
5 ELILO

We need switch/case to have different fields set for it.

Thanks

Yinghai

#5 lore raw
Quoted 8 lines · Yinghai Lu

Good, kexec is not only one.

ELILO has one.
5 ELILO

We need switch/case to have different fields set for it.

I wouldn't consider that "good", but it's a bloody good thing we have bootloader IDs.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
author
#6 lore raw
Quoted 4 lines · H. Peter Anvin
Quoted 3 lines · Yinghai Lu

Good, kexec is not only one.

Quoted 8 lines
Quoted 5 lines

ELILO has one.
5 ELILO

We need switch/case to have different fields set for it.

I wouldn't consider that "good", but it's a bloody good thing we have bootloader IDs.

What is the planned course of action here. With this commit applied, I still cannot boot. Is there something you are waiting for from me?

Thanks,
Robin

#7 lore raw

Yes, please do the analysis I asked for.

Quoted 19 lines · Robin Holt
Quoted 4 lines · H. Peter Anvin
Quoted 3 lines · Yinghai Lu

Good, kexec is not only one.

Quoted 8 lines
Quoted 5 lines

ELILO has one.
5 ELILO

We need switch/case to have different fields set for it.

I wouldn't consider that "good", but it's a bloody good thing we have bootloader IDs.

What is the planned course of action here. With this commit applied, I still cannot boot. Is there something you are waiting for from me?

Thanks,
Robin

Signature · 1 line
Sent from my mobile phone. Please excuse brevity and lack of formatting.
#8 lore raw
Quoted 1 line · H. Peter Anvin

Yes, please do the analysis I asked for.

it uses first 2 pages in bzImage to bootparams.

then update the fields with ===> X

struct boot_params {
        struct screen_info screen_info;                 /* 0x000 */   ===> X
        struct apm_bios_info apm_bios_info;             /* 0x040 */   ===> X
        __u8  _pad2[4];                                 /* 0x054 */
        __u64  tboot_addr;                              /* 0x058 */
        struct ist_info ist_info;                       /* 0x060 */
        __u8  _pad3[16];                                /* 0x070 */
        __u8  hd0_info[16];     /* obsolete! */         /* 0x080 */   ===> X
        __u8  hd1_info[16];     /* obsolete! */         /* 0x090 */   ===> X
        struct sys_desc_table sys_desc_table;           /* 0x0a0 */   ===> X
        struct olpc_ofw_header olpc_ofw_header;         /* 0x0b0 */
        __u32 ext_ramdisk_image;                        /* 0x0c0 */
        __u32 ext_ramdisk_size;                         /* 0x0c4 */
        __u32 ext_cmd_line_ptr;                         /* 0x0c8 */
        __u8  _pad4[116];                               /* 0x0cc */
        struct edid_info edid_info;                     /* 0x140 */
        struct efi_info efi_info;                       /* 0x1c0 */   ===> X
        __u32 alt_mem_k;                                /* 0x1e0 */   ===> X
        __u32 scratch;          /* Scratch field! */    /* 0x1e4 */
        __u8  e820_entries;                             /* 0x1e8 */  ===> X
        __u8  eddbuf_entries;                           /* 0x1e9 */
        __u8  edd_mbr_sig_buf_entries;                  /* 0x1ea */
        __u8  kbd_status;                               /* 0x1eb */
        __u8  _pad5[3];                                 /* 0x1ec */
        /*
         * The sentinel is set to a nonzero value (0xff) in header.S.
         *
         * A bootloader is supposed to only take setup_header and put
         * it into a clean boot_params buffer. If it turns out that
         * it is clumsy or too generous with the buffer, it most
         * probably will pick up the sentinel variable too. The fact
         * that this variable then is still 0xff will let kernel
         * know that some variables in boot_params are invalid and
         * kernel should zero out certain portions of boot_params.
         */
        __u8  sentinel;                                 /* 0x1ef */
        __u8  _pad6[1];                                 /* 0x1f0 */
        struct setup_header hdr;    /* setup header */  /* 0x1f1 */  ===> X
        __u8  _pad7[0x290-0x1f1-sizeof(struct setup_header)];
        __u32 edd_mbr_sig_buffer[EDD_MBR_SIG_MAX];      /* 0x290 */
        struct e820entry e820_map[E820MAX];             /* 0x2d0 */  ===> X
        __u8  _pad8[48];                                /* 0xcd0 */
        struct edd_info eddbuf[EDDMAXNR];               /* 0xd00 */
        __u8  _pad9[276];                               /* 0xeec */

so sentinel will be kept as 0xff, so efi_info get cleared by kernel...

Attached patches should avoid the clearing of efi_info when elilo is used.

Do we need to clear edd and pad2 and pad3 for elilo?

Thanks

Yinghai

---
 arch/x86/include/asm/bootparam_utils.h |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/include/asm/bootparam_utils.h +4 -1
Index: linux-2.6/arch/x86/include/asm/bootparam_utils.h
===================================================================
@@ -20,8 +20,11 @@ static void sanitize_boot_params(struct
 	if (boot_params->sentinel) {
 		/*fields in boot_params are not valid, clear them */
 		memset(&boot_params->olpc_ofw_header, 0,
-		       (char *)&boot_params->alt_mem_k -
+		       (char *)&boot_params->efi_info -
 			(char *)&boot_params->olpc_ofw_header);
+		if (boot_params->hdr.type_of_loader != 0x50) /* not eflio */
+			memset(&boot_params->efi_info, 0,
+					 sizeof(boot_params->efi_info));
 		memset(&boot_params->kbd_status, 0,
 		       (char *)&boot_params->hdr -
 		       (char *)&boot_params->kbd_status);
author
#9 lore raw

That fixed it for me.

Can you help me understand why sentinel is non-zero? It looks to me like 3.14 allocates 16kB plus strlen of the command line, zeros it, and then proceeds to fill in fields, some differing from what is in the boot_params structure. That said, it looks like the sentinel field should remain 0. I am still trying to understand, but if this patch makes it in, I am happy.

Thanks,
Robin

Quoted 61 lines · Yinghai Lu
Quoted 1 line · H. Peter Anvin

Yes, please do the analysis I asked for.

it uses first 2 pages in bzImage to bootparams.

then update the fields with ===> X

struct boot_params {
        struct screen_info screen_info;                 /* 0x000 */   ===> X
        struct apm_bios_info apm_bios_info;             /* 0x040 */   ===> X
        __u8  _pad2[4];                                 /* 0x054 */
        __u64  tboot_addr;                              /* 0x058 */
        struct ist_info ist_info;                       /* 0x060 */
        __u8  _pad3[16];                                /* 0x070 */
        __u8  hd0_info[16];     /* obsolete! */         /* 0x080 */   ===> X
        __u8  hd1_info[16];     /* obsolete! */         /* 0x090 */   ===> X
        struct sys_desc_table sys_desc_table;           /* 0x0a0 */   ===> X
        struct olpc_ofw_header olpc_ofw_header;         /* 0x0b0 */
        __u32 ext_ramdisk_image;                        /* 0x0c0 */
        __u32 ext_ramdisk_size;                         /* 0x0c4 */
        __u32 ext_cmd_line_ptr;                         /* 0x0c8 */
        __u8  _pad4[116];                               /* 0x0cc */
        struct edid_info edid_info;                     /* 0x140 */
        struct efi_info efi_info;                       /* 0x1c0 */   ===> X
        __u32 alt_mem_k;                                /* 0x1e0 */   ===> X
        __u32 scratch;          /* Scratch field! */    /* 0x1e4 */
        __u8  e820_entries;                             /* 0x1e8 */  ===> X
        __u8  eddbuf_entries;                           /* 0x1e9 */
        __u8  edd_mbr_sig_buf_entries;                  /* 0x1ea */
        __u8  kbd_status;                               /* 0x1eb */
        __u8  _pad5[3];                                 /* 0x1ec */
        /*
         * The sentinel is set to a nonzero value (0xff) in header.S.
         *
         * A bootloader is supposed to only take setup_header and put
         * it into a clean boot_params buffer. If it turns out that
         * it is clumsy or too generous with the buffer, it most
         * probably will pick up the sentinel variable too. The fact
         * that this variable then is still 0xff will let kernel
         * know that some variables in boot_params are invalid and
         * kernel should zero out certain portions of boot_params.
         */
        __u8  sentinel;                                 /* 0x1ef */
        __u8  _pad6[1];                                 /* 0x1f0 */
        struct setup_header hdr;    /* setup header */  /* 0x1f1 */  ===> X
        __u8  _pad7[0x290-0x1f1-sizeof(struct setup_header)];
        __u32 edd_mbr_sig_buffer[EDD_MBR_SIG_MAX];      /* 0x290 */
        struct e820entry e820_map[E820MAX];             /* 0x2d0 */  ===> X
        __u8  _pad8[48];                                /* 0xcd0 */
        struct edd_info eddbuf[EDDMAXNR];               /* 0xd00 */
        __u8  _pad9[276];                               /* 0xeec */

so sentinel will be kept as 0xff, so efi_info get cleared by kernel...

Attached patches should avoid the clearing of efi_info when elilo is used.

Do we need to clear edd and pad2 and pad3 for elilo?

Thanks

Yinghai

#10 lore raw
Quoted 8 lines · Robin Holt

That fixed it for me.

Can you help me understand why sentinel is non-zero? It looks to me like 3.14 allocates 16kB plus strlen of the command line, zeros it, and then proceeds to fill in fields, some differing from what is in the boot_params structure. That said, it looks like the sentinel field should remain 0. I am still trying to understand, but if this patch makes it in, I am happy.

sentinel is out of setup_header.
it is 0x1ef. setup_header is from 0x1f1.

it will be 0xff from arch/x86/boot/header.S for bzImage.

        .section ".header", "a"
        .globl  sentinel

sentinel: .byte 0xff, 0xff /* Used to detect broken loaders */

elilo first copy first page, and get 0x1f1 for setup code sector number. then it copies all setup code ( include setup header).

after that sysdeps_create_boot_params will copy first two pages to bp... CopyMem(bp, param_start, 0x2000);

in that case, it will keep all fields in boot_params around setup_header as with setup code...thus 0x1ef will be 0xff.

elilo need attached fix.

Thanks

Yinghai

---
 ia32/system.c   |    9 ++++++++-
 x86_64/system.c |    9 ++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)
ia32/system.c +8 -1
Index: elilo/ia32/system.c
===================================================================
@@ -487,7 +487,14 @@ sysdeps_create_boot_params(
 	 * can be used by the command line.
 	 */
 	if (param_start != NULL) {
-		CopyMem(bp, param_start, 0x2000);
+		unsigned char *p = param_start;
+		unsigned long setup_header_size = p[0x201] + 0x202 - 0x1f1;
+
+		/* only copy setup_header */
+		if (setup_header_size > 0x7f)
+			setup_header_size = 0x7f;
+		CopyMem((unsigned char *)bp + 0x1f1, p + 0x1f1,
+			setup_header_size);
 		free(param_start);
 		param_start = NULL;
 		param_size = 0;
x86_64/system.c +8 -1
Index: elilo/x86_64/system.c
===================================================================
@@ -640,7 +640,14 @@ sysdeps_create_boot_params(
 	 * can be used by the command line.
 	 */
 	if (param_start != NULL) {
-		CopyMem(bp, param_start, 0x2000);
+		unsigned char *p = param_start;
+		unsigned long setup_header_size = p[0x201] + 0x202 - 0x1f1;
+
+		/* only copy setup_header */
+		if (setup_header_size > 0x7f)
+			setup_header_size = 0x7f;
+		CopyMem((unsigned char *)bp + 0x1f1, p + 0x1f1,
+			setup_header_size);
 		free(param_start);
 		param_start = NULL;
 		param_size = 0;
author
#11 lore raw
Quoted 17 lines · Yinghai Lu
Quoted 8 lines · Robin Holt

That fixed it for me.

Can you help me understand why sentinel is non-zero? It looks to me like 3.14 allocates 16kB plus strlen of the command line, zeros it, and then proceeds to fill in fields, some differing from what is in the boot_params structure. That said, it looks like the sentinel field should remain 0. I am still trying to understand, but if this patch makes it in, I am happy.

sentinel is out of setup_header.
it is 0x1ef. setup_header is from 0x1f1.

it will be 0xff from arch/x86/boot/header.S for bzImage.

        .section ".header", "a"
        .globl  sentinel
Quoted 7 lines

sentinel: .byte 0xff, 0xff /* Used to detect broken loaders */

elilo first copy first page, and get 0x1f1 for setup code sector number. then it copies all setup code ( include setup header).

after that sysdeps_create_boot_params will copy first two pages to bp... CopyMem(bp, param_start, 0x2000);

Had not gotten that far in my understanding of elilo. Now I understand.

Robin

#12 lore raw
In reply to Yinghai Lu
Quoted 52 lines · Yinghai Lu
Quoted 1 line · H. Peter Anvin

Yes, please do the analysis I asked for.

it uses first 2 pages in bzImage to bootparams.

then update the fields with ===> X

struct boot_params {
        struct screen_info screen_info;                 /* 0x000 */   ===> X
        struct apm_bios_info apm_bios_info;             /* 0x040 */   ===> X
        __u8  _pad2[4];                                 /* 0x054 */
        __u64  tboot_addr;                              /* 0x058 */
        struct ist_info ist_info;                       /* 0x060 */
        __u8  _pad3[16];                                /* 0x070 */
        __u8  hd0_info[16];     /* obsolete! */         /* 0x080 */   ===> X
        __u8  hd1_info[16];     /* obsolete! */         /* 0x090 */   ===> X
        struct sys_desc_table sys_desc_table;           /* 0x0a0 */   ===> X
        struct olpc_ofw_header olpc_ofw_header;         /* 0x0b0 */
        __u32 ext_ramdisk_image;                        /* 0x0c0 */
        __u32 ext_ramdisk_size;                         /* 0x0c4 */
        __u32 ext_cmd_line_ptr;                         /* 0x0c8 */
        __u8  _pad4[116];                               /* 0x0cc */
        struct edid_info edid_info;                     /* 0x140 */
        struct efi_info efi_info;                       /* 0x1c0 */   ===> X
        __u32 alt_mem_k;                                /* 0x1e0 */   ===> X
        __u32 scratch;          /* Scratch field! */    /* 0x1e4 */
        __u8  e820_entries;                             /* 0x1e8 */  ===> X
        __u8  eddbuf_entries;                           /* 0x1e9 */
        __u8  edd_mbr_sig_buf_entries;                  /* 0x1ea */
        __u8  kbd_status;                               /* 0x1eb */
        __u8  _pad5[3];                                 /* 0x1ec */
        /*
         * The sentinel is set to a nonzero value (0xff) in header.S.
         *
         * A bootloader is supposed to only take setup_header and put
         * it into a clean boot_params buffer. If it turns out that
         * it is clumsy or too generous with the buffer, it most
         * probably will pick up the sentinel variable too. The fact
         * that this variable then is still 0xff will let kernel
         * know that some variables in boot_params are invalid and
         * kernel should zero out certain portions of boot_params.
         */
        __u8  sentinel;                                 /* 0x1ef */
        __u8  _pad6[1];                                 /* 0x1f0 */
        struct setup_header hdr;    /* setup header */  /* 0x1f1 */  ===> X
        __u8  _pad7[0x290-0x1f1-sizeof(struct setup_header)];
        __u32 edd_mbr_sig_buffer[EDD_MBR_SIG_MAX];      /* 0x290 */
        struct e820entry e820_map[E820MAX];             /* 0x2d0 */  ===> X
        __u8  _pad8[48];                                /* 0xcd0 */
        struct edd_info eddbuf[EDDMAXNR];               /* 0xd00 */
        __u8  _pad9[276];                               /* 0xeec */
Quoted 5 lines

so sentinel will be kept as 0xff, so efi_info get cleared by kernel...

Attached patches should avoid the clearing of efi_info when elilo is used.

Do we need to clear edd and pad2 and pad3 for elilo?

I don't think this is limited to elilo. I have a UEFI machine booting with grub2 that also fails to boot because of this patch. I was in the middle of bisecting when I found this thread and if I revert 5dcd14ecd4 the machine boots again. Put that commit back in and it doesn't. We've had three other reports in Fedora of similar cases.

I discussed this with Peter Jones this morning. He was looking into what grub2 does for boot_params and it seems to be read-modify-write instead of clearing the whole thing. (CC'd Peter now.)

The patch for elilo probably works, but if grub2 is hitting this then I'm curious if most bootloaders will. I'll finish my bisect just to be extra sure, but something probably needs to be done in a more generic fashion here.

josh

#23 lore raw
In reply to H. Peter Anvin
Quoted 10 lines · H. Peter Anvin

Then make it follow the boot spec:

Quoted 8 lines

In 32-bit boot protocol, the first step in loading a Linux kernel should be to setup the boot parameters (struct boot_params, traditionally known as "zero page"). The memory for struct boot_params should be allocated and initialized to all zero. Then the setup header from offset 0x01f1 of kernel image on should be loaded into struct boot_params and examined. The end of setup header can be calculated as follow:

Quoted 3 lines
Quoted 1 line
        0x0202 + byte value at offset 0x0201

... so we don't have to.

So, the problem here seems to be that there's never been widespread compliance with this paragraph, but this patch assumes there has. A brief survey concludes:

grub 1 on bios - loads the kernel and edits the parameters it cares
about in place
grub 1 on efi - allocates a buffer (fails to clear it) and modifies
the parameters it cares about, then copies it back
grub 2 on bios - clears the buffer, writes what it cares about grub 2 on efi (using efi boot stub) - reads the buffer, modifies fields
it cares about, passes the pointer to the boot stub
elilo - allocates a new buffer, copies the kernel structure in to it,
allocates another buffer, clears it, copies the first structure in to it, frees the first buffer, modifies fields it cares about in the second buffer, clears some other fields in the second structure, and passes the pointer in when it calls the old entry point
(It's possible that there's some newer version of elilo than 3.14, which I had handy, but I'm not going to do deeper research on a project that keeps a link to its CVS repo on the most obvious google result, lest I lose the will to live.)
syslinux - I'm just going to assume that your code matches the spec.

So it's certainly worth trying to find a better way to check this, but I don't think this patch is it. If we're going to enforce it, we have to make sure that a bootloader that's conforming to what was de facto the standard in 0x020b still works. Otherwise we're just breaking bootloaders for no reason, and that will end poorly.

I'd suggest we add a field for the bootloader to make a positive declaration of what version it is using, and only check for the sentinel if the field claims it's doing 0x020c or newer.

Signature · 1 line
        Peter
#24 lore raw
Quoted 5 lines · Peter Jones

So, the problem here seems to be that there's never been widespread compliance with this paragraph, but this patch assumes there has. A brief survey concludes:

No, this patch doesn't assume there is widespread compliance, it is trying to address the bits that are not complied with.

Quoted 5 lines

grub 1 on bios - loads the kernel and edits the parameters it cares
about in place
grub 1 on efi - allocates a buffer (fails to clear it) and modifies
the parameters it cares about, then copies it back
grub 2 on bios - clears the buffer, writes what it cares about

On BIOS, anything that invokes the 16-bit entry point will be correct, because it is the 16-bit code that sets up struct boot_params.

Quoted 20 lines

grub 2 on efi (using efi boot stub) - reads the buffer, modifies fields
it cares about, passes the pointer to the boot stub
elilo - allocates a new buffer, copies the kernel structure in to it,
allocates another buffer, clears it, copies the first structure in to it, frees the first buffer, modifies fields it cares about in the second buffer, clears some other fields in the second structure, and passes the pointer in when it calls the old entry point
(It's possible that there's some newer version of elilo than 3.14, which I had handy, but I'm not going to do deeper research on a project that keeps a link to its CVS repo on the most obvious google result, lest I lose the will to live.)
syslinux - I'm just going to assume that your code matches the spec.

So it's certainly worth trying to find a better way to check this, but I don't think this patch is it. If we're going to enforce it, we have to make sure that a bootloader that's conforming to what was de facto the standard in 0x020b still works. Otherwise we're just breaking bootloaders for no reason, and that will end poorly.

Quoted 3 lines

I'd suggest we add a field for the bootloader to make a positive declaration of what version it is using, and only check for the sentinel if the field claims it's doing 0x020c or newer.

Except it doesn't quite work. The problem is that these broken bootloaders aren't just a matter of 2.11 vs 2.12, they are implicitly assuming that the kernel image itself doesn't happen to contain anything harmful in the fields that they don't bother initializing. This would be nice and good, except that the demands for the boot sector space is fairly high and it gets very cantankerous to turn that into a minefield.

In fact, your suggestion is exactly equivalent to the sentinel, except you want it to be pre-initialized with 0x20b instead of 0xffff.

As such, I don't really know anything better we can do other than:

1. detect the *properly working* case of the structure properly initialized;
2. doing legacy bootloader-specific clearing based on the bootloader ID if the sentinel triggers -- if you can think of better heuristics then that would be good;
3. try to get bootloaders switched from case #2 to case #1.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#13 lore raw
In reply to Josh Boyer
Quoted 7 lines · Josh Boyer

I don't think this is limited to elilo. I have a UEFI machine booting with grub2 that also fails to boot because of this patch. I was in the middle of bisecting when I found this thread and if I revert 5dcd14ecd4 the machine boots again. Put that commit back in and it doesn't. We've had three other reports in Fedora of similar cases.

Quoted 9 lines

I discussed this with Peter Jones this morning. He was looking into what grub2 does for boot_params and it seems to be read-modify-write instead of clearing the whole thing. (CC'd Peter now.)

The patch for elilo probably works, but if grub2 is hitting this then I'm curious if most bootloaders will. I'll finish my bisect just to be extra sure, but something probably needs to be done in a more generic fashion here.

Come to think about it...

The EFI field actually has a magic, unless just about all the rest of them, so clearing it is probabilistically redundant; in other words we almost certainly should exclude it from the clearing, unconditionally.

Does the "elilo" patch made unconditional work for you?

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#25 lore raw
In reply to H. Peter Anvin
Quoted 8 lines · H. Peter Anvin
Quoted 4 lines · Peter Jones

So, the problem here seems to be that there's never been widespread compliance with this paragraph, but this patch assumes there has. A brief survey concludes:

No, this patch doesn't assume there is widespread compliance, it is trying to address the bits that are not complied with.

Right, but that's basically every x86_64 UEFI machine ever deployed.

[lots trimmed]

Quoted 10 lines
Quoted 9 lines

So it's certainly worth trying to find a better way to check this, but I don't think this patch is it. If we're going to enforce it, we have to make sure that a bootloader that's conforming to what was de facto the standard in 0x020b still works. Otherwise we're just breaking bootloaders for no reason, and that will end poorly.

I'd suggest we add a field for the bootloader to make a positive declaration of what version it is using, and only check for the sentinel if the field claims it's doing 0x020c or newer.

Quoted 6 lines

Except it doesn't quite work. The problem is that these broken bootloaders aren't just a matter of 2.11 vs 2.12, they are implicitly assuming that the kernel image itself doesn't happen to contain anything harmful in the fields that they don't bother initializing. This would be nice and good, except that the demands for the boot sector space is fairly high and it gets very cantankerous to turn that into a minefield.

If your only objection is real estate, we can find a way to be clever about what we do that uses already existing space. For instance, write back the version number that's supported in the version field, but byte-swapped, so we can tell it changed (we don't anticipate ever supporting protocol 0x20b from a kernel that advertises 0xb02, right?)

Just one example - we don't have to do this the exact way I said; we just need a positive assertion from the bootloader to start doing enforcement. Versions would be nice, but they're not strictly required.

Quoted 2 lines

In fact, your suggestion is exactly equivalent to the sentinel, except you want it to be pre-initialized with 0x20b instead of 0xffff.

No, I want the bootloader to communicate that it understands the boot protocol revision is 0x020c, so we can /safely/ enter a world where we're forbidding booting from an older bootloader.

Quoted 4 lines

As such, I don't really know anything better we can do other than:

1. detect the *properly working* case of the structure properly initialized

Which is easy, but it doesn't seem to be anything anybody has ever shipped on UEFI machines.

Quoted 3 lines

2. doing legacy bootloader-specific clearing based on the bootloader ID if the sentinel triggers -- if you can think of better heuristics then that would be good;

This heuristic is "all UEFI bootloaders anybody uses". You can list them individually, but it's the same as reverting the patch, just with more code.

Quoted 1 line

3. try to get bootloaders switched from case #2 to case #1.

And I'm for that, but I think we should delay enforcement until they've got a way to express that.

Signature · 1 line
        Peter
#14 lore raw
In reply to H. Peter Anvin
Quoted 18 lines · H. Peter Anvin
Quoted 7 lines · Josh Boyer

I don't think this is limited to elilo. I have a UEFI machine booting with grub2 that also fails to boot because of this patch. I was in the middle of bisecting when I found this thread and if I revert 5dcd14ecd4 the machine boots again. Put that commit back in and it doesn't. We've had three other reports in Fedora of similar cases.

Quoted 9 lines

I discussed this with Peter Jones this morning. He was looking into what grub2 does for boot_params and it seems to be read-modify-write instead of clearing the whole thing. (CC'd Peter now.)

The patch for elilo probably works, but if grub2 is hitting this then I'm curious if most bootloaders will. I'll finish my bisect just to be extra sure, but something probably needs to be done in a more generic fashion here.

Quoted 7 lines

Come to think about it...

The EFI field actually has a magic, unless just about all the rest of them, so clearing it is probabilistically redundant; in other words we almost certainly should exclude it from the clearing, unconditionally.

Does the "elilo" patch made unconditional work for you?

Something like this?

arch/x86/include/asm/bootparam_utils.h +1 -1
Index: linux-2.6/arch/x86/include/asm/bootparam_utils.h
===================================================================
@@ -20,8 +20,11 @@ static void sanitize_boot_params(struct
 	if (boot_params->sentinel) {
 		/*fields in boot_params are not valid, clear them */
 		memset(&boot_params->olpc_ofw_header, 0,
-		       (char *)&boot_params->alt_mem_k -
+		       (char *)&boot_params->efi_info -
 			(char *)&boot_params->olpc_ofw_header);
 		memset(&boot_params->kbd_status, 0,
 		       (char *)&boot_params->hdr -
 		       (char *)&boot_params->kbd_status);

I can try that in a bit.

josh

#15 lore raw
Quoted 18 lines · Josh Boyer

Something like this?

Index: linux-2.6/arch/x86/include/asm/bootparam_utils.h
===================================================================

arch/x86/include/asm/bootparam_utils.h +1 -1
@@ -20,8 +20,11 @@ static void sanitize_boot_params(struct
 	if (boot_params->sentinel) {
 		/*fields in boot_params are not valid, clear them */
 		memset(&boot_params->olpc_ofw_header, 0,
-		       (char *)&boot_params->alt_mem_k -
+		       (char *)&boot_params->efi_info -
 			(char *)&boot_params->olpc_ofw_header);
 		memset(&boot_params->kbd_status, 0,
 		       (char *)&boot_params->hdr -
 		       (char *)&boot_params->kbd_status);
Quoted 2 lines

I can try that in a bit.

Right.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#19 lore raw

PATCH 1/1 Be explicit about what the x86 0x020c boot parameter version requires.

In reply to H. Peter Anvin

This should help avoid making the incorrect change in non-compliant bootloaders.

---
 Documentation/x86/boot.txt             | 5 +++--
 arch/x86/include/asm/bootparam_utils.h | 7 +++++++
 2 files changed, 10 insertions(+), 2 deletions(-)
Documentation/x86/boot.txt +3 -2
index 3840b6f..72702db 100644
@@ -1110,7 +1110,8 @@ firmware, 'table' is the EFI system table - these are the first two
 arguments of the "handoff state" as described in section 2.3 of the
 UEFI specification. 'bp' is the boot loader-allocated boot params.
 
-The boot loader *must* fill out the following fields in bp,
+The boot loader *must* zero the entirity of bp, and then fill out the
+following fields:
 
     o hdr.code32_start
     o hdr.cmd_line_ptr
@@ -1118,4 +1119,4 @@ The boot loader *must* fill out the following fields in bp,
     o hdr.ramdisk_image (if applicable)
     o hdr.ramdisk_size  (if applicable)
 
-All other fields should be zero.
+All other fields should remain zero.
arch/x86/include/asm/bootparam_utils.h +7 -0
index 5b5e9cb..b4e8aa8 100644
@@ -17,6 +17,13 @@
  */
 static void sanitize_boot_params(struct boot_params *boot_params)
 {
+	/* Note: do not simply clear this field.  The purpose of this field is
+	 * to guarantee compliance with the x86 boot spec located in
+	 * Documentation/x86/boot.txt .  That spec says that the *whole*
+	 * structure should be cleared.  If you're having an issue because
+	 * the sentinel is set, you need to change the whole structure to be
+	 * cleared, not this (or any other) indidivual field.
+	 */
 	if (boot_params->sentinel) {
 		/*fields in boot_params are not valid, clear them */
 		memset(&boot_params->olpc_ofw_header, 0,
Signature · 1 line
1.8.1.4
#16 lore raw
In reply to H. Peter Anvin
Quoted 19 lines · H. Peter Anvin
Quoted 18 lines · Josh Boyer

Something like this?

Index: linux-2.6/arch/x86/include/asm/bootparam_utils.h
===================================================================

arch/x86/include/asm/bootparam_utils.h +1 -1
@@ -20,8 +20,11 @@ static void sanitize_boot_params(struct
      if (boot_params->sentinel) {
              /*fields in boot_params are not valid, clear them */
              memset(&boot_params->olpc_ofw_header, 0,
-                    (char *)&boot_params->alt_mem_k -
+                    (char *)&boot_params->efi_info -
                      (char *)&boot_params->olpc_ofw_header);
              memset(&boot_params->kbd_status, 0,
                     (char *)&boot_params->hdr -
                     (char *)&boot_params->kbd_status);
Quoted 4 lines
Quoted 2 lines

I can try that in a bit.

Right.

OK. Doing that on top of 3.9-rc1 results in me having a booting machine again. I'd suggest we get that into upstream quick-ish.

josh

#17 lore raw

Yeah. I'll queue it up today and send to Linus in the next batch.

Quoted 30 lines · Josh Boyer
Quoted 19 lines · H. Peter Anvin
Quoted 18 lines · Josh Boyer

Something like this?

Index: linux-2.6/arch/x86/include/asm/bootparam_utils.h
===================================================================

arch/x86/include/asm/bootparam_utils.h +1 -1
@@ -20,8 +20,11 @@ static void sanitize_boot_params(struct
      if (boot_params->sentinel) {
              /*fields in boot_params are not valid, clear them */
              memset(&boot_params->olpc_ofw_header, 0,
-                    (char *)&boot_params->alt_mem_k -
+                    (char *)&boot_params->efi_info -
                      (char *)&boot_params->olpc_ofw_header);
              memset(&boot_params->kbd_status, 0,
                     (char *)&boot_params->hdr -
                     (char *)&boot_params->kbd_status);
Quoted 4 lines
Quoted 2 lines

I can try that in a bit.

Right.

OK. Doing that on top of 3.9-rc1 results in me having a booting machine
again. I'd suggest we get that into upstream quick-ish.

josh

Signature · 1 line
Sent from my mobile phone. Please excuse brevity and lack of formatting.
#20 lore raw

Re: [PATCH] Be explicit about what the x86 0x020c boot parameter version requires.

In reply to Peter Jones
Quoted 24 lines · Peter Jones

This should help avoid making the incorrect change in non-compliant bootloaders.

---
 Documentation/x86/boot.txt             | 5 +++--
 arch/x86/include/asm/bootparam_utils.h | 7 +++++++
 2 files changed, 10 insertions(+), 2 deletions(-)
Documentation/x86/boot.txt +2 -1
index 3840b6f..72702db 100644
@@ -1110,7 +1110,8 @@ firmware, 'table' is the EFI system table - these are the first two
 arguments of the "handoff state" as described in section 2.3 of the
 UEFI specification. 'bp' is the boot loader-allocated boot params.
 
-The boot loader *must* fill out the following fields in bp,
+The boot loader *must* zero the entirity of bp, and then fill out the
+following fields:
 
     o hdr.code32_start
     o hdr.cmd_line_ptr

Documentation/x86/boot.txt The boot loader *must* fill out the following fields in bp, · line 1121

Quoted 3 lines
Documentation/x86/boot.txt +0 -0
@@ -1118,4 +1119,4 @@ The boot loader *must* fill out the following fields in bp,
     o hdr.ramdisk_image (if applicable)
     o hdr.ramdisk_size  (if applicable)
 

Wait a bloody minute here... I seem to have managed to miss something big.

Matt, should we not be copying the setup part of the structure just as we do for the normal 32/64-bit protocol? If not, why not?

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#18 lore raw

[tip:x86/urgent] x86: Don' t clear efi_info even if the sentinel hits

In reply to Josh Boyer
x86: Don't clear efi_info even if the sentinel hits
Commit-ID:  2e604c0f19dcdd433b3863ffc3da9bc0787ca765
Gitweb:     http://git.kernel.org/tip/2e604c0f19dcdd433b3863ffc3da9bc0787ca765
Author:     Josh Boyer <[email protected]>
AuthorDate: Wed, 6 Mar 2013 20:23:30 -0800
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Wed, 6 Mar 2013 20:23:30 -0800

x86: Don't clear efi_info even if the sentinel hits

When boot_params->sentinel is set, all we really know is that some undefined set of fields in struct boot_params contain garbage. In the particular case of efi_info, however, there is a private magic for that substructure, so it is generally safe to leave it even if the bootloader is broken.

kexec (for which we did the initial analysis) did not initialize this field, but of course all the EFI bootloaders do, and most EFI bootloaders are broken in this respect (and should be fixed.)

---
 arch/x86/include/asm/bootparam_utils.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/include/asm/bootparam_utils.h +3 -1
index 5b5e9cb..ff808ef 100644
@@ -14,13 +14,15 @@
  * analysis of kexec-tools; if other broken bootloaders initialize a
  * different set of fields we will need to figure out how to disambiguate.
  *
+ * Note: efi_info is commonly left uninitialized, but that field has a
+ * private magic, so it is better to leave it unchanged.
  */
 static void sanitize_boot_params(struct boot_params *boot_params)
 {
 	if (boot_params->sentinel) {
 		/*fields in boot_params are not valid, clear them */
 		memset(&boot_params->olpc_ofw_header, 0,
-		       (char *)&boot_params->alt_mem_k -
+		       (char *)&boot_params->efi_info -
 			(char *)&boot_params->olpc_ofw_header);
 		memset(&boot_params->kbd_status, 0,
 		       (char *)&boot_params->hdr -
#22 lore raw

[tip:x86/urgent] x86, doc: Be explicit about what the x86 struct boot_params requires

In reply to Peter Jones
x86, doc: Be explicit about what the x86 struct boot_params requires
Commit-ID:  3c4aff6b9a183b4f24eb7b8dd6c8a92cdba3bc75
Gitweb:     http://git.kernel.org/tip/3c4aff6b9a183b4f24eb7b8dd6c8a92cdba3bc75
Author:     Peter Jones <[email protected]>
AuthorDate: Wed, 6 Mar 2013 13:00:23 -0500
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Wed, 6 Mar 2013 20:34:43 -0800

x86, doc: Be explicit about what the x86 struct boot_params requires

If the sentinel triggers, we do not want the boot loader authors to just poke it and make the error go away, we want them to actually fix the problem.

This should help avoid making the incorrect change in non-compliant bootloaders.

[ hpa: dropped the Documentation/x86/boot.txt hunk pending
clarifications ]

---
 arch/x86/include/asm/bootparam_utils.h | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
arch/x86/include/asm/bootparam_utils.h +15 -1
index ff808ef..653668d 100644
@@ -19,8 +19,22 @@
  */
 static void sanitize_boot_params(struct boot_params *boot_params)
 {
+	/* 
+	 * IMPORTANT NOTE TO BOOTLOADER AUTHORS: do not simply clear
+	 * this field.  The purpose of this field is to guarantee
+	 * compliance with the x86 boot spec located in
+	 * Documentation/x86/boot.txt .  That spec says that the
+	 * *whole* structure should be cleared, after which only the
+	 * portion defined by struct setup_header (boot_params->hdr)
+	 * should be copied in.
+	 *
+	 * If you're having an issue because the sentinel is set, you
+	 * need to change the whole structure to be cleared, not this
+	 * (or any other) individual field, or you will soon have
+	 * problems again.
+	 */
 	if (boot_params->sentinel) {
-		/*fields in boot_params are not valid, clear them */
+		/* fields in boot_params are left uninitialized, clear them */
 		memset(&boot_params->olpc_ofw_header, 0,
 		       (char *)&boot_params->efi_info -
 			(char *)&boot_params->olpc_ofw_header);
#21 lore raw

Re: [PATCH] Be explicit about what the x86 0x020c boot parameter version requires.

In reply to H. Peter Anvin
Quoted 31 lines · H. Peter Anvin
Quoted 24 lines · Peter Jones

This should help avoid making the incorrect change in non-compliant bootloaders.

---
 Documentation/x86/boot.txt             | 5 +++--
 arch/x86/include/asm/bootparam_utils.h | 7 +++++++
 2 files changed, 10 insertions(+), 2 deletions(-)
Documentation/x86/boot.txt +2 -1
index 3840b6f..72702db 100644
@@ -1110,7 +1110,8 @@ firmware, 'table' is the EFI system table - these are the first two
 arguments of the "handoff state" as described in section 2.3 of the
 UEFI specification. 'bp' is the boot loader-allocated boot params.
 
-The boot loader *must* fill out the following fields in bp,
+The boot loader *must* zero the entirity of bp, and then fill out the
+following fields:
 
     o hdr.code32_start
     o hdr.cmd_line_ptr

Documentation/x86/boot.txt The boot loader *must* fill out the following fields in bp, · line 1121

Quoted 3 lines
Documentation/x86/boot.txt +0 -0
@@ -1118,4 +1119,4 @@ The boot loader *must* fill out the following fields in bp,
     o hdr.ramdisk_image (if applicable)
     o hdr.ramdisk_size  (if applicable)
 

Wait a bloody minute here... I seem to have managed to miss something big.

Quoted 2 lines

Matt, should we not be copying the setup part of the structure just as we do for the normal 32/64-bit protocol? If not, why not?

The structure that contains the hdr.version? Yeah, we should be copying that.