linux-stable/arch
David Woodhouse 07fa619f2a x86/kexec: Restore GDT on return from ::preserve_context kexec
The restore_processor_state() function explicitly states that "the asm code
that gets us here will have restored a usable GDT". That wasn't true in the
case of returning from a ::preserve_context kexec. Make it so.

Without this, the kernel was depending on the called function to reload a
GDT which is appropriate for the kernel before returning.

Test program:

 #include <unistd.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <linux/kexec.h>
 #include <linux/reboot.h>
 #include <sys/reboot.h>
 #include <sys/syscall.h>

 int main (void)
 {
        struct kexec_segment segment = {};
	unsigned char purgatory[] = {
		0x66, 0xba, 0xf8, 0x03,	// mov $0x3f8, %dx
		0xb0, 0x42,		// mov $0x42, %al
		0xee,			// outb %al, (%dx)
		0xc3,			// ret
	};
	int ret;

	segment.buf = &purgatory;
	segment.bufsz = sizeof(purgatory);
	segment.mem = (void *)0x400000;
	segment.memsz = 0x1000;
	ret = syscall(__NR_kexec_load, 0x400000, 1, &segment, KEXEC_PRESERVE_CONTEXT);
	if (ret) {
		perror("kexec_load");
		exit(1);
	}

	ret = syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_KEXEC);
	if (ret) {
		perror("kexec reboot");
		exit(1);
	}
	printf("Success\n");
	return 0;
 }

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20241205153343.3275139-2-dwmw2@infradead.org
2024-12-06 10:35:49 +01:00
..
alpha Driver core changes for 6.13-rc1 2024-11-29 11:43:29 -08:00
arc - The series "zram: optimal post-processing target selection" from 2024-11-23 09:58:07 -08:00
arm Kbuild updates for v6.13 2024-11-30 13:41:50 -08:00
arm64 i2c-for-6.13-rc1-part3 2024-12-01 13:38:24 -08:00
csky - The series "zram: optimal post-processing target selection" from 2024-11-23 09:58:07 -08:00
hexagon - The series "resource: A couple of cleanups" from Andy Shevchenko 2024-11-25 16:09:48 -08:00
loongarch dmaengine updates for v6.13 2024-11-27 13:25:47 -08:00
m68k RTC for 6.13 2024-11-30 11:18:16 -08:00
microblaze - The series "zram: optimal post-processing target selection" from 2024-11-23 09:58:07 -08:00
mips Kbuild updates for v6.13 2024-11-30 13:41:50 -08:00
nios2 - The series "zram: optimal post-processing target selection" from 2024-11-23 09:58:07 -08:00
openrisc - The series "zram: optimal post-processing target selection" from 2024-11-23 09:58:07 -08:00
parisc parisc architecture fixes for kernel v6.13-rc1: 2024-11-26 14:49:20 -08:00
powerpc Kbuild updates for v6.13 2024-11-30 13:41:50 -08:00
riscv ARM: 2024-11-30 14:51:08 -08:00
s390 more s390 updates for 6.13 merge window 2024-11-29 10:40:52 -08:00
sh sh updates for v6.13 2024-11-30 14:45:29 -08:00
sparc Kbuild updates for v6.13 2024-11-30 13:41:50 -08:00
um This pull request contains the following changes for UML: 2024-11-30 10:34:54 -08:00
x86 x86/kexec: Restore GDT on return from ::preserve_context kexec 2024-12-06 10:35:49 +01:00
xtensa - The series "resource: A couple of cleanups" from Andy Shevchenko 2024-11-25 16:09:48 -08:00
.gitignore
Kconfig Kbuild updates for v6.13 2024-11-30 13:41:50 -08:00