Skip to content

Commit 2cb7878

Browse files
rustyrusselltorvalds
authored andcommitted
lguest: fix 'unhandled trap 13' with CONFIG_CC_STACKPROTECTOR
We don't set up the canary; let's disable stack protector on boot.c so we can get into lguest_init, then set it up. As a side effect, switch_to_new_gdt() sets up %fs for us properly too. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9fa7eb2 commit 2cb7878

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎arch/x86/lguest/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
obj-y := i386_head.o boot.o
2+
CFLAGS_boot.o := $(call cc-option, -fno-stack-protector)

‎arch/x86/lguest/boot.c‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#include <asm/mce.h>
6868
#include <asm/io.h>
6969
#include <asm/i387.h>
70+
#include <asm/stackprotector.h>
7071
#include <asm/reboot.h> /* for struct machine_ops */
7172

7273
/*G:010 Welcome to the Guest!
@@ -1088,13 +1089,21 @@ __init void lguest_init(void)
10881089
* lguest_init() where the rest of the fairly chaotic boot setup
10891090
* occurs. */
10901091

1092+
/* The stack protector is a weird thing where gcc places a canary
1093+
* value on the stack and then checks it on return. This file is
1094+
* compiled with -fno-stack-protector it, so we got this far without
1095+
* problems. The value of the canary is kept at offset 20 from the
1096+
* %gs register, so we need to set that up before calling C functions
1097+
* in other files. */
1098+
setup_stack_canary_segment(0);
1099+
/* We could just call load_stack_canary_segment(), but we might as
1100+
* call switch_to_new_gdt() which loads the whole table and sets up
1101+
* the per-cpu segment descriptor register %fs as well. */
1102+
switch_to_new_gdt(0);
1103+
10911104
/* As described in head_32.S, we map the first 128M of memory. */
10921105
max_pfn_mapped = (128*1024*1024) >> PAGE_SHIFT;
10931106

1094-
/* Load the %fs segment register (the per-cpu segment register) with
1095-
* the normal data segment to get through booting. */
1096-
asm volatile ("mov %0, %%fs" : : "r" (__KERNEL_DS) : "memory");
1097-
10981107
/* The Host<->Guest Switcher lives at the top of our address space, and
10991108
* the Host told us how big it is when we made LGUEST_INIT hypercall:
11001109
* it put the answer in lguest_data.reserve_mem */

0 commit comments

Comments
 (0)