Skip to contentSkip to conversation

x86 efi: bugfix interrupt disabling sequence

PATCH In review Bart Kuivenhoven 3 participants 6 messages Sep 18, 2013 – Sep 23, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86 efi: bugfix interrupt disabling sequence

The problem in efi_main was that the idt was cleared before the interrupts were disabled.

The UEFI spec states that interrupts aren't used so this shouldn't be too much of a problem. Peripherals however don't necessarily know about this and thus might cause interrupts to happen anyway. Even if ExitBootServices() has been called.

This means there is a risk of an interrupt being triggered while the IDT register is nullified and the interrupt bit hasn't been cleared, allowing for a triple fault.

This patch fixes this by clearing the interrupt bit before the lidt instruction.

---
 arch/x86/boot/compressed/eboot.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/boot/compressed/eboot.c +2 -2
index b7388a4..100b812 100644
@@ -1267,11 +1267,11 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table,
 	desc->base2 = 0x00;
 #endif /* CONFIG_X86_64 */
 
+	asm volatile("cli");
+
 	asm volatile ("lidt %0" : : "m" (*idt));
 	asm volatile ("lgdt %0" : : "m" (*gdt));
 
-	asm volatile("cli");
-
 	return boot_params;
 fail:
 	return NULL;
Signature · 1 line
1.8.4
#1 lore raw
Quoted 11 lines · Bart Kuivenhoven

The problem in efi_main was that the idt was cleared before the interrupts were disabled.

The UEFI spec states that interrupts aren't used so this shouldn't be too much of a problem. Peripherals however don't necessarily know about this and thus might cause interrupts to happen anyway. Even if ExitBootServices() has been called.

This means there is a risk of an interrupt being triggered while the IDT register is nullified and the interrupt bit hasn't been cleared, allowing for a triple fault.

Just to be clear, you haven't witnessed a triple fault, correct?

Quoted 2 lines

This patch fixes this by clearing the interrupt bit before the lidt instruction.

I think we can go even further than this and get rid of all of the IDT code in the EFI boot stub. The kernel maintains its own IDT anyway.

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
#2 lore raw
Quoted 13 lines · Matt Fleming
Quoted 11 lines · Bart Kuivenhoven

The problem in efi_main was that the idt was cleared before the interrupts were disabled.

The UEFI spec states that interrupts aren't used so this shouldn't be too much of a problem. Peripherals however don't necessarily know about this and thus might cause interrupts to happen anyway. Even if ExitBootServices() has been called.

This means there is a risk of an interrupt being triggered while the IDT register is nullified and the interrupt bit hasn't been cleared, allowing for a triple fault.

Quoted 8 lines

Just to be clear, you haven't witnessed a triple fault, correct?

Quoted 2 lines

This patch fixes this by clearing the interrupt bit before the lidt instruction.

I think we can go even further than this and get rid of all of the IDT code in the EFI boot stub. The kernel maintains its own IDT anyway.

Well, isn't it so, that the kernel expects a setup in which interrupts are disabled before the decompressed image is loaded?

What we can do is remove the lidt instruction and IDT pointer, but that still doesn't change anything with regards to the kernels expectations.

And no, I haven't witnessed a triple fault, this is purely theoretical, with a very slim chance of it actually happening. That does not mean that it can't happen though.

Signature · 5 lines
Kind regards/Met vriendelijke groet,
Bart Kuivenhoven.

Intern Fedora ARM,
Red Hat.
#3 lore raw
Quoted 26 lines · Bart Kuivenhoven
Quoted 13 lines · Matt Fleming
Quoted 11 lines · Bart Kuivenhoven

The problem in efi_main was that the idt was cleared before the interrupts were disabled.

The UEFI spec states that interrupts aren't used so this shouldn't be too much of a problem. Peripherals however don't necessarily know about this and thus might cause interrupts to happen anyway. Even if ExitBootServices() has been called.

This means there is a risk of an interrupt being triggered while the IDT register is nullified and the interrupt bit hasn't been cleared, allowing for a triple fault.

Quoted 8 lines

Just to be clear, you haven't witnessed a triple fault, correct?

Quoted 2 lines

This patch fixes this by clearing the interrupt bit before the lidt instruction.

I think we can go even further than this and get rid of all of the IDT code in the EFI boot stub. The kernel maintains its own IDT anyway.

Well, isn't it so, that the kernel expects a setup in which interrupts are disabled before the decompressed image is loaded?

Quoted 6 lines

What we can do is remove the lidt instruction and IDT pointer, but that still doesn't change anything with regards to the kernels expectations.

And no, I haven't witnessed a triple fault, this is purely theoretical, with a very slim chance of it actually happening. That does not mean that it can't happen though.

it would also be very hard to prove that it occured (outside of special debug environments) - spurious, low probability triple faults are as undebuggable as it gets.

Thanks,

Ingo

#4 lore raw
In reply to Bart Kuivenhoven
Quoted 2 lines · Bart Kuivenhoven

Well, isn't it so, that the kernel expects a setup in which interrupts are disabled before the decompressed image is loaded?

Yes, but I wasn't advocating leaving interrupts enabled, rather, because interrupts are disabled we don't need to build an empty IDT, which will never be used.

Quoted 6 lines

What we can do is remove the lidt instruction and IDT pointer, but that still doesn't change anything with regards to the kernels expectations.

And no, I haven't witnessed a triple fault, this is purely theoretical, with a very slim chance of it actually happening. That does not mean that it can't happen though.

Right, but the answer to my question will dictate how aggressively we apply your patch - whether it goes in the 'urgent' queue to be pushed quickly or whether we give it more testing. Patches that fix serious issues that users are hitting tend to make it into the next release. For patches that fix theoretical bugs, we'll usually put it through more strenuous testing first.

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center
#5 lore raw
Quoted 7 lines · Matt Fleming
Quoted 2 lines · Bart Kuivenhoven

Well, isn't it so, that the kernel expects a setup in which interrupts are disabled before the decompressed image is loaded?

Yes, but I wasn't advocating leaving interrupts enabled, rather, because interrupts are disabled we don't need to build an empty IDT, which will never be used.

Ah, well in that case I think you'll like the new version of my patch that I'll send out soon.

Quoted 7 lines
Quoted 6 lines

What we can do is remove the lidt instruction and IDT pointer, but that still doesn't change anything with regards to the kernels expectations.

And no, I haven't witnessed a triple fault, this is purely theoretical, with a very slim chance of it actually happening. That does not mean that it can't happen though.

Quoted 6 lines

Right, but the answer to my question will dictate how aggressively we apply your patch - whether it goes in the 'urgent' queue to be pushed quickly or whether we give it more testing. Patches that fix serious issues that users are hitting tend to make it into the next release. For patches that fix theoretical bugs, we'll usually put it through more strenuous testing first.

I haven't seen it happen.

Even if it happens, the CPU will just reset and try again, with a very high likelihood that it will succeed that time.

Given these circumstances, I'd say you're more than welcome to put my work through some serious tests rather than giving it 'urgent' status.

Signature · 5 lines
Kind regards/Met vriendelijke groet,
Bart Kuivenhoven.

Intern Fedora ARM,
Red Hat.