Fix non-lazy GS handling in sys_vm86()
PATCH 1/1 Fix non-lazy GS handling in sys_vm86()
This fixes a stack corruption panic or null dereference oops due to a bad GS in resume_userspace() when returning from sys_vm86() and calling lockdep_sys_exit().
Only a problem when CONFIG_LOCKDEP and CONFIG_CC_STACKPROTECTOR enabled.
--- arch/x86/kernel/vm86_32.c | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-)
arch/x86/kernel/vm86_32.c +7 -6
@@ -287,10 +287,9 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk info->regs.pt.ds =0 ; info->regs.pt.es =0 ; info->regs.pt.fs =0 ; - -/* we are clearing gs later just before "jmp resume_userspace", -* because it is not saved/restored. -*/ +#ifndef CONFIG_X86_32_LAZY_GS + info->regs.pt.gs =0 ; +#endif /* * The flags register is also special: we cannot trust that the user
@@ -343,10 +342,12 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk __asm__ __volatile__( "movl %0,%%esp\n\t" "movl %1,%%ebp\n\t" -"mov %2, %%gs\n\t" +#ifdef CONFIG_X86_32_LAZY_GS + "mov $0, %%gs\n\t" +#endif"jmp resume_userspace" :/* no outputs */ - :"r" (&info->regs),"r" (task_thread_info (tsk)),"r" (0 )); + :"r" (&info->regs),"r" (task_thread_info (tsk)));/* we never return here */ }
Signature · 1 line
"Excuse all the blood" -- Dead
Quoted 30 lines · Lubomir Rintel
This fixes a stack corruption panic or null dereference oops due to a bad GS in
resume_userspace()when returning fromsys_vm86()and callinglockdep_sys_exit().Only a problem when
CONFIG_LOCKDEPandCONFIG_CC_STACKPROTECTORenabled.Signed-off-by Lubomir Rintel <[email protected]>--- arch/x86/kernel/vm86_32.c | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-)arch/x86/kernel/vm86_32.c +3
-4@@ -287,10 +287,9 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk info->regs.pt.ds =0 ; info->regs.pt.es =0 ; info->regs.pt.fs =0 ; - -/* we are clearing gs later just before "jmp resume_userspace", -* because it is not saved/restored. -*/ +#ifndef CONFIG_X86_32_LAZY_GS + info->regs.pt.gs =0 ; +#endif /* * The flags register is also special: we cannot trust that the user
arch/x86/kernel/vm86_32.c static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk · line 347
Quoted 7 lines
arch/x86/kernel/vm86_32.c +3
-1@@ -343,10 +342,12 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk __asm__ __volatile__( "movl %0,%%esp\n\t" "movl %1,%%ebp\n\t" - "mov %2, %%gs\n\t" +#ifdef CONFIG_X86_32_LAZY_GS + "mov $0, %%gs\n\t" +#endif
That bit looks rather untested - i dont think there's an immediate constant instruction variant for segment register moves ...
Ingo
Quoted 9 lines · Ingo Molnar
Review
Quoted 4 lines · Lubomir Rintel
(quoted diff) +3
-1- "mov %2, %%gs\n\t" +#ifdef CONFIG_X86_32_LAZY_GS + "mov $0, %%gs\n\t" +#endifThat bit looks rather untested - i dont think there's an immediate constant instruction variant for segment register moves ...
Right. Sorry, I only tested (dosbox & svgalib) with stackprotector enabled. This time I ensured it compiles and runs dosbox & mode3 (from svgalib) both with and without stackprotector:
Quoted 1 line
From
8bdb7e27766be7bf2902cf6d6938f3e5868d0aacMon Sep 17 00:00:00 2001
From: Lubomir Rintel <[email protected]>
Date: Sat, 6 Jun 2009 20:09:17 +0200
Subject: [PATCH] Fix non-lazy GS handling in sys_vm86()
This fixes a stack corruption panic or null dereference oops due to a bad GS in resume_userspace() when returning from sys_vm86() and calling lockdep_sys_exit().
Only a problem when CONFIG_LOCKDEP and CONFIG_CC_STACKPROTECTOR enabled.
--- arch/x86/kernel/vm86_32.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
arch/x86/kernel/vm86_32.c +5 -4
@@ -287,10 +287,9 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk info->regs.pt.ds =0 ; info->regs.pt.es =0 ; info->regs.pt.fs =0 ; - -/* we are clearing gs later just before "jmp resume_userspace", -* because it is not saved/restored. -*/ +#ifndef CONFIG_X86_32_LAZY_GS + info->regs.pt.gs =0 ; +#endif /* * The flags register is also special: we cannot trust that the user
@@ -343,7 +342,9 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk __asm__ __volatile__( "movl %0,%%esp\n\t" "movl %1,%%ebp\n\t" +#ifdef CONFIG_X86_32_LAZY_GS "mov %2, %%gs\n\t" +#endif"jmp resume_userspace" :/* no outputs */ :"r" (&info->regs),"r" (task_thread_info (tsk)),"r" (0 ));
Signature · 4 lines
1.6.2.2 -- "Excuse all the blood" -- Dead
[tip:x86/urgent] x86: Fix non-lazy GS handling in sys_vm86()
Commit-ID: 3aa6b186f86c5d06d6d92d14311ffed51f091f40 Gitweb: http://git.kernel.org/tip/3aa6b186f86c5d06d6d92d14311ffed51f091f40 Author: Lubomir Rintel <[email protected]> AuthorDate: Sun, 7 Jun 2009 16:23:48 +0200 Committer: Ingo Molnar <[email protected]> CommitDate: Sun, 7 Jun 2009 16:31:23 +0200
x86: Fix non-lazy GS handling in sys_vm86()
This fixes a stack corruption panic or null dereference oops due to a bad GS in resume_userspace() when returning from sys_vm86() and calling lockdep_sys_exit().
Only a problem when CONFIG_LOCKDEP and CONFIG_CC_STACKPROTECTOR enabled.
LKML-Reference: <1244384628.2323.4.camel@bimbo>
--- arch/x86/kernel/vm86_32.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
arch/x86/kernel/vm86_32.c +5 -4
@@ -287,10 +287,9 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk info->regs.pt.ds =0 ; info->regs.pt.es =0 ; info->regs.pt.fs =0 ; - -/* we are clearing gs later just before "jmp resume_userspace", -* because it is not saved/restored. -*/ +#ifndef CONFIG_X86_32_LAZY_GS + info->regs.pt.gs =0 ; +#endif /* * The flags register is also special: we cannot trust that the user
@@ -343,7 +342,9 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk __asm__ __volatile__( "movl %0,%%esp\n\t" "movl %1,%%ebp\n\t" +#ifdef CONFIG_X86_32_LAZY_GS "mov %2, %%gs\n\t" +#endif"jmp resume_userspace" :/* no outputs */ :"r" (&info->regs),"r" (task_thread_info (tsk)),"r" (0 ));