2005-04-17 02:20:36 +04:00
/ *
2015-06-05 14:02:28 +03:00
* Compatibility m o d e s y s t e m c a l l e n t r y p o i n t f o r x86 - 6 4 .
*
2005-04-17 02:20:36 +04:00
* Copyright 2 0 0 0 - 2 0 0 2 A n d i K l e e n , S u S E L a b s .
2015-06-05 14:02:28 +03:00
* /
2015-06-03 19:29:26 +03:00
# include " c a l l i n g . h "
2005-09-09 23:28:48 +04:00
# include < a s m / a s m - o f f s e t s . h >
2005-04-17 02:20:36 +04:00
# include < a s m / c u r r e n t . h >
# include < a s m / e r r n o . h >
2015-06-05 14:02:28 +03:00
# include < a s m / i a32 _ u n i s t d . h >
# include < a s m / t h r e a d _ i n f o . h >
2005-04-17 02:20:36 +04:00
# include < a s m / s e g m e n t . h >
2006-07-03 11:24:45 +04:00
# include < a s m / i r q f l a g s . h >
2012-04-20 23:19:50 +04:00
# include < a s m / a s m . h >
2012-09-21 23:43:12 +04:00
# include < a s m / s m a p . h >
2005-04-17 02:20:36 +04:00
# include < l i n u x / l i n k a g e . h >
2012-01-03 23:23:06 +04:00
# include < l i n u x / e r r . h >
2005-04-17 02:20:36 +04:00
2011-03-07 21:10:39 +03:00
.section .entry .text , " ax"
2005-04-17 02:20:36 +04:00
/ *
2016-03-10 06:00:35 +03:00
* 3 2 - bit S Y S E N T E R e n t r y .
2005-04-17 02:20:36 +04:00
*
2016-03-10 06:00:35 +03:00
* 3 2 - bit s y s t e m c a l l s t h r o u g h t h e v D S O ' s _ _ k e r n e l _ v s y s c a l l e n t e r h e r e
* on 6 4 - b i t k e r n e l s r u n n i n g o n I n t e l C P U s .
*
* The S Y S E N T E R i n s t r u c t i o n , i n p r i n c i p l e , s h o u l d * o n l y * o c c u r i n t h e
* vDSO. I n p r a c t i c e , a s m a l l n u m b e r o f A n d r o i d d e v i c e s w e r e s h i p p e d
* with a c o p y o f B i o n i c t h a t i n l i n e d a S Y S E N T E R i n s t r u c t i o n . T h i s
* never h a p p e n e d i n a n y o f G o o g l e ' s B i o n i c v e r s i o n s - - i t o n l y h a p p e n e d
* in a n a r r o w r a n g e o f I n t e l - p r o v i d e d v e r s i o n s .
*
* SYSENTER l o a d s S S , R S P , C S , a n d R I P f r o m p r e v i o u s l y p r o g r a m m e d M S R s .
* IF a n d V M i n R F L A G S a r e c l e a r e d ( I O W : i n t e r r u p t s a r e o f f ) .
2015-02-27 01:40:32 +03:00
* SYSENTER d o e s n o t s a v e a n y t h i n g o n t h e s t a c k ,
2016-03-10 06:00:35 +03:00
* and d o e s n o t s a v e o l d R I P ( ! ! ! ) , R S P , o r R F L A G S .
2015-02-27 01:40:32 +03:00
*
2005-04-17 02:20:36 +04:00
* Arguments :
2015-02-27 01:40:32 +03:00
* eax s y s t e m c a l l n u m b e r
* ebx a r g 1
* ecx a r g 2
* edx a r g 3
* esi a r g 4
* edi a r g 5
* ebp u s e r s t a c k
* 0 ( % ebp) a r g 6
* /
2015-06-08 09:33:56 +03:00
ENTRY( e n t r y _ S Y S E N T E R _ c o m p a t )
2015-10-06 03:47:55 +03:00
/* Interrupts are off on entry. */
2015-03-27 13:36:20 +03:00
SWAPGS_ U N S A F E _ S T A C K
2015-04-24 18:31:35 +03:00
movq P E R _ C P U _ V A R ( c p u _ c u r r e n t _ t o p _ o f _ s t a c k ) , % r s p
2015-03-27 13:36:20 +03:00
2015-10-06 03:48:11 +03:00
/ *
* User t r a c i n g c o d e ( p t r a c e o r s i g n a l h a n d l e r s ) m i g h t a s s u m e t h a t
* the s a v e d R A X c o n t a i n s a 3 2 - b i t n u m b e r w h e n w e ' r e i n v o k i n g a 3 2 - b i t
* syscall. J u s t i n c a s e t h e h i g h b i t s a r e n o n z e r o , z e r o - e x t e n d
* the s y s c a l l n u m b e r . ( T h i s c o u l d a l m o s t c e r t a i n l y b e d e l e t e d
* with n o i l l e f f e c t s . )
* /
2015-03-27 13:36:21 +03:00
movl % e a x , % e a x
2015-03-31 20:00:04 +03:00
/* Construct struct pt_regs on stack */
x86/debug: Remove perpetually broken, unmaintainable dwarf annotations
So the dwarf2 annotations in low level assembly code have
become an increasing hindrance: unreadable, messy macros
mixed into some of the most security sensitive code paths
of the Linux kernel.
These debug info annotations don't even buy the upstream
kernel anything: dwarf driven stack unwinding has caused
problems in the past so it's out of tree, and the upstream
kernel only uses the much more robust framepointers based
stack unwinding method.
In addition to that there's a steady, slow bitrot going
on with these annotations, requiring frequent fixups.
There's no tooling and no functionality upstream that
keeps it correct.
So burn down the sick forest, allowing new, healthier growth:
27 files changed, 350 insertions(+), 1101 deletions(-)
Someone who has the willingness and time to do this
properly can attempt to reintroduce dwarf debuginfo in x86
assembly code plus dwarf unwinding from first principles,
with the following conditions:
- it should be maximally readable, and maximally low-key to
'ordinary' code reading and maintenance.
- find a build time method to insert dwarf annotations
automatically in the most common cases, for pop/push
instructions that manipulate the stack pointer. This could
be done for example via a preprocessing step that just
looks for common patterns - plus special annotations for
the few cases where we want to depart from the default.
We have hundreds of CFI annotations, so automating most of
that makes sense.
- it should come with build tooling checks that ensure that
CFI annotations are sensible. We've seen such efforts from
the framepointer side, and there's no reason it couldn't be
done on the dwarf side.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-28 13:21:47 +03:00
pushq $ _ _ U S E R 3 2 _ D S / * p t _ r e g s - > s s * /
2015-12-17 10:18:48 +03:00
pushq % r b p / * p t _ r e g s - > s p ( s t a s h e d i n b p ) * /
2015-10-06 03:47:55 +03:00
/ *
* Push f l a g s . T h i s i s n a s t y . F i r s t , i n t e r r u p t s a r e c u r r e n t l y
* off, b u t w e n e e d p t _ r e g s - > f l a g s t o h a v e I F s e t . S e c o n d , e v e n
* if T F w a s s e t w h e n S Y S E N T E R s t a r t e d , i t ' s c l e a r b y n o w . W e f i x
* that l a t e r u s i n g T I F _ S I N G L E S T E P .
* /
pushfq / * p t _ r e g s - > f l a g s ( e x c e p t I F = 0 ) * /
orl $ X 8 6 _ E F L A G S _ I F , ( % r s p ) / * F i x s a v e d f l a g s * /
x86/debug: Remove perpetually broken, unmaintainable dwarf annotations
So the dwarf2 annotations in low level assembly code have
become an increasing hindrance: unreadable, messy macros
mixed into some of the most security sensitive code paths
of the Linux kernel.
These debug info annotations don't even buy the upstream
kernel anything: dwarf driven stack unwinding has caused
problems in the past so it's out of tree, and the upstream
kernel only uses the much more robust framepointers based
stack unwinding method.
In addition to that there's a steady, slow bitrot going
on with these annotations, requiring frequent fixups.
There's no tooling and no functionality upstream that
keeps it correct.
So burn down the sick forest, allowing new, healthier growth:
27 files changed, 350 insertions(+), 1101 deletions(-)
Someone who has the willingness and time to do this
properly can attempt to reintroduce dwarf debuginfo in x86
assembly code plus dwarf unwinding from first principles,
with the following conditions:
- it should be maximally readable, and maximally low-key to
'ordinary' code reading and maintenance.
- find a build time method to insert dwarf annotations
automatically in the most common cases, for pop/push
instructions that manipulate the stack pointer. This could
be done for example via a preprocessing step that just
looks for common patterns - plus special annotations for
the few cases where we want to depart from the default.
We have hundreds of CFI annotations, so automating most of
that makes sense.
- it should come with build tooling checks that ensure that
CFI annotations are sensible. We've seen such efforts from
the framepointer side, and there's no reason it couldn't be
done on the dwarf side.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-28 13:21:47 +03:00
pushq $ _ _ U S E R 3 2 _ C S / * p t _ r e g s - > c s * /
2016-05-02 17:56:50 +03:00
pushq $ 0 / * p t _ r e g s - > i p = 0 ( p l a c e h o l d e r ) * /
x86/debug: Remove perpetually broken, unmaintainable dwarf annotations
So the dwarf2 annotations in low level assembly code have
become an increasing hindrance: unreadable, messy macros
mixed into some of the most security sensitive code paths
of the Linux kernel.
These debug info annotations don't even buy the upstream
kernel anything: dwarf driven stack unwinding has caused
problems in the past so it's out of tree, and the upstream
kernel only uses the much more robust framepointers based
stack unwinding method.
In addition to that there's a steady, slow bitrot going
on with these annotations, requiring frequent fixups.
There's no tooling and no functionality upstream that
keeps it correct.
So burn down the sick forest, allowing new, healthier growth:
27 files changed, 350 insertions(+), 1101 deletions(-)
Someone who has the willingness and time to do this
properly can attempt to reintroduce dwarf debuginfo in x86
assembly code plus dwarf unwinding from first principles,
with the following conditions:
- it should be maximally readable, and maximally low-key to
'ordinary' code reading and maintenance.
- find a build time method to insert dwarf annotations
automatically in the most common cases, for pop/push
instructions that manipulate the stack pointer. This could
be done for example via a preprocessing step that just
looks for common patterns - plus special annotations for
the few cases where we want to depart from the default.
We have hundreds of CFI annotations, so automating most of
that makes sense.
- it should come with build tooling checks that ensure that
CFI annotations are sensible. We've seen such efforts from
the framepointer side, and there's no reason it couldn't be
done on the dwarf side.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-28 13:21:47 +03:00
pushq % r a x / * p t _ r e g s - > o r i g _ a x * /
pushq % r d i / * p t _ r e g s - > d i * /
pushq % r s i / * p t _ r e g s - > s i * /
pushq % r d x / * p t _ r e g s - > d x * /
2015-12-17 10:18:48 +03:00
pushq % r c x / * p t _ r e g s - > c x * /
x86/debug: Remove perpetually broken, unmaintainable dwarf annotations
So the dwarf2 annotations in low level assembly code have
become an increasing hindrance: unreadable, messy macros
mixed into some of the most security sensitive code paths
of the Linux kernel.
These debug info annotations don't even buy the upstream
kernel anything: dwarf driven stack unwinding has caused
problems in the past so it's out of tree, and the upstream
kernel only uses the much more robust framepointers based
stack unwinding method.
In addition to that there's a steady, slow bitrot going
on with these annotations, requiring frequent fixups.
There's no tooling and no functionality upstream that
keeps it correct.
So burn down the sick forest, allowing new, healthier growth:
27 files changed, 350 insertions(+), 1101 deletions(-)
Someone who has the willingness and time to do this
properly can attempt to reintroduce dwarf debuginfo in x86
assembly code plus dwarf unwinding from first principles,
with the following conditions:
- it should be maximally readable, and maximally low-key to
'ordinary' code reading and maintenance.
- find a build time method to insert dwarf annotations
automatically in the most common cases, for pop/push
instructions that manipulate the stack pointer. This could
be done for example via a preprocessing step that just
looks for common patterns - plus special annotations for
the few cases where we want to depart from the default.
We have hundreds of CFI annotations, so automating most of
that makes sense.
- it should come with build tooling checks that ensure that
CFI annotations are sensible. We've seen such efforts from
the framepointer side, and there's no reason it couldn't be
done on the dwarf side.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-28 13:21:47 +03:00
pushq $ - E N O S Y S / * p t _ r e g s - > a x * /
2016-05-02 17:56:50 +03:00
pushq $ 0 / * p t _ r e g s - > r8 = 0 * /
pushq $ 0 / * p t _ r e g s - > r9 = 0 * /
pushq $ 0 / * p t _ r e g s - > r10 = 0 * /
pushq $ 0 / * p t _ r e g s - > r11 = 0 * /
2015-10-06 03:48:11 +03:00
pushq % r b x / * p t _ r e g s - > r b x * /
2015-12-17 10:18:48 +03:00
pushq % r b p / * p t _ r e g s - > r b p ( w i l l b e o v e r w r i t t e n ) * /
2016-05-02 17:56:50 +03:00
pushq $ 0 / * p t _ r e g s - > r12 = 0 * /
pushq $ 0 / * p t _ r e g s - > r13 = 0 * /
pushq $ 0 / * p t _ r e g s - > r14 = 0 * /
pushq $ 0 / * p t _ r e g s - > r15 = 0 * /
2005-04-17 02:20:36 +04:00
cld
2015-03-31 20:00:04 +03:00
x86_64, entry: Filter RFLAGS.NT on entry from userspace
The NT flag doesn't do anything in long mode other than causing IRET
to #GP. Oddly, CPL3 code can still set NT using popf.
Entry via hardware or software interrupt clears NT automatically, so
the only relevant entries are fast syscalls.
If user code causes kernel code to run with NT set, then there's at
least some (small) chance that it could cause trouble. For example,
user code could cause a call to EFI code with NT set, and who knows
what would happen? Apparently some games on Wine sometimes do
this (!), and, if an IRET return happens, they will segfault. That
segfault cannot be handled, because signal delivery fails, too.
This patch programs the CPU to clear NT on entry via SYSCALL (both
32-bit and 64-bit, by my reading of the AMD APM), and it clears NT
in software on entry via SYSENTER.
To save a few cycles, this borrows a trick from Jan Beulich in Xen:
it checks whether NT is set before trying to clear it. As a result,
it seems to have very little effect on SYSENTER performance on my
machine.
There's another minor bug fix in here: it looks like the CFI
annotations were wrong if CONFIG_AUDITSYSCALL=n.
Testers beware: on Xen, SYSENTER with NT set turns into a GPF.
I haven't touched anything on 32-bit kernels.
The syscall mask change comes from a variant of this patch by Anish
Bhatt.
Note to stable maintainers: there is no known security issue here.
A misguided program can set NT and cause the kernel to try and fail
to deliver SIGSEGV, crashing the program. This patch fixes Far Cry
on Wine: https://bugs.winehq.org/show_bug.cgi?id=33275
Cc: <stable@vger.kernel.org>
Reported-by: Anish Bhatt <anish@chelsio.com>
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/395749a5d39a29bd3e4b35899cf3a3c1340e5595.1412189265.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-10-01 22:49:04 +04:00
/ *
2016-03-10 06:00:25 +03:00
* SYSENTER d o e s n ' t f i l t e r f l a g s , s o w e n e e d t o c l e a r N T a n d A C
x86_64, entry: Filter RFLAGS.NT on entry from userspace
The NT flag doesn't do anything in long mode other than causing IRET
to #GP. Oddly, CPL3 code can still set NT using popf.
Entry via hardware or software interrupt clears NT automatically, so
the only relevant entries are fast syscalls.
If user code causes kernel code to run with NT set, then there's at
least some (small) chance that it could cause trouble. For example,
user code could cause a call to EFI code with NT set, and who knows
what would happen? Apparently some games on Wine sometimes do
this (!), and, if an IRET return happens, they will segfault. That
segfault cannot be handled, because signal delivery fails, too.
This patch programs the CPU to clear NT on entry via SYSCALL (both
32-bit and 64-bit, by my reading of the AMD APM), and it clears NT
in software on entry via SYSENTER.
To save a few cycles, this borrows a trick from Jan Beulich in Xen:
it checks whether NT is set before trying to clear it. As a result,
it seems to have very little effect on SYSENTER performance on my
machine.
There's another minor bug fix in here: it looks like the CFI
annotations were wrong if CONFIG_AUDITSYSCALL=n.
Testers beware: on Xen, SYSENTER with NT set turns into a GPF.
I haven't touched anything on 32-bit kernels.
The syscall mask change comes from a variant of this patch by Anish
Bhatt.
Note to stable maintainers: there is no known security issue here.
A misguided program can set NT and cause the kernel to try and fail
to deliver SIGSEGV, crashing the program. This patch fixes Far Cry
on Wine: https://bugs.winehq.org/show_bug.cgi?id=33275
Cc: <stable@vger.kernel.org>
Reported-by: Anish Bhatt <anish@chelsio.com>
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/395749a5d39a29bd3e4b35899cf3a3c1340e5595.1412189265.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-10-01 22:49:04 +04:00
* ourselves. T o s a v e a f e w c y c l e s , w e c a n c h e c k w h e t h e r
2016-03-10 06:00:25 +03:00
* either w a s s e t i n s t e a d o f d o i n g a n u n c o n d i t i o n a l p o p f q .
2015-10-06 03:47:55 +03:00
* This n e e d s t o h a p p e n b e f o r e e n a b l i n g i n t e r r u p t s s o t h a t
* we d o n ' t g e t p r e e m p t e d w i t h N T s e t .
2015-10-09 20:08:59 +03:00
*
2016-03-10 06:00:30 +03:00
* If T F i s s e t , w e w i l l s i n g l e - s t e p a l l t h e w a y t o h e r e - - d o _ d e b u g
* will i g n o r e a l l t h e t r a p s . ( Y e s , t h i s i s s l o w , b u t s o i s
* single- s t e p p i n g i n g e n e r a l . T h i s a l l o w s u s t o a v o i d h a v i n g
* a m o r e c o m p l i c a t e d c o d e t o h a n d l e t h e c a s e w h e r e a u s e r p r o g r a m
* forces u s t o s i n g l e - s t e p t h r o u g h t h e S Y S E N T E R e n t r y c o d e . )
*
2015-12-12 13:27:57 +03:00
* NB. : . L s y s e n t e r _ f i x _ f l a g s i s a l a b e l w i t h t h e c o d e u n d e r i t m o v e d
2015-10-09 20:08:59 +03:00
* out- o f - l i n e a s a n o p t i m i z a t i o n : N T i s u n l i k e l y t o b e s e t i n t h e
* majority o f t h e c a s e s a n d i n s t e a d o f p o l l u t i n g t h e I $ u n n e c e s s a r i l y ,
* we' r e k e e p i n g t h a t c o d e b e h i n d a b r a n c h w h i c h w i l l p r e d i c t a s
* not- t a k e n a n d t h e r e f o r e i t s i n s t r u c t i o n s w o n ' t b e f e t c h e d .
x86_64, entry: Filter RFLAGS.NT on entry from userspace
The NT flag doesn't do anything in long mode other than causing IRET
to #GP. Oddly, CPL3 code can still set NT using popf.
Entry via hardware or software interrupt clears NT automatically, so
the only relevant entries are fast syscalls.
If user code causes kernel code to run with NT set, then there's at
least some (small) chance that it could cause trouble. For example,
user code could cause a call to EFI code with NT set, and who knows
what would happen? Apparently some games on Wine sometimes do
this (!), and, if an IRET return happens, they will segfault. That
segfault cannot be handled, because signal delivery fails, too.
This patch programs the CPU to clear NT on entry via SYSCALL (both
32-bit and 64-bit, by my reading of the AMD APM), and it clears NT
in software on entry via SYSENTER.
To save a few cycles, this borrows a trick from Jan Beulich in Xen:
it checks whether NT is set before trying to clear it. As a result,
it seems to have very little effect on SYSENTER performance on my
machine.
There's another minor bug fix in here: it looks like the CFI
annotations were wrong if CONFIG_AUDITSYSCALL=n.
Testers beware: on Xen, SYSENTER with NT set turns into a GPF.
I haven't touched anything on 32-bit kernels.
The syscall mask change comes from a variant of this patch by Anish
Bhatt.
Note to stable maintainers: there is no known security issue here.
A misguided program can set NT and cause the kernel to try and fail
to deliver SIGSEGV, crashing the program. This patch fixes Far Cry
on Wine: https://bugs.winehq.org/show_bug.cgi?id=33275
Cc: <stable@vger.kernel.org>
Reported-by: Anish Bhatt <anish@chelsio.com>
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/395749a5d39a29bd3e4b35899cf3a3c1340e5595.1412189265.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-10-01 22:49:04 +04:00
* /
2016-03-10 06:00:30 +03:00
testl $ X 8 6 _ E F L A G S _ N T | X 8 6 _ E F L A G S _ A C | X 8 6 _ E F L A G S _ T F , E F L A G S ( % r s p )
2015-12-12 13:27:57 +03:00
jnz . L s y s e n t e r _ f i x _ f l a g s
.Lsysenter_flags_fixed :
x86_64, entry: Filter RFLAGS.NT on entry from userspace
The NT flag doesn't do anything in long mode other than causing IRET
to #GP. Oddly, CPL3 code can still set NT using popf.
Entry via hardware or software interrupt clears NT automatically, so
the only relevant entries are fast syscalls.
If user code causes kernel code to run with NT set, then there's at
least some (small) chance that it could cause trouble. For example,
user code could cause a call to EFI code with NT set, and who knows
what would happen? Apparently some games on Wine sometimes do
this (!), and, if an IRET return happens, they will segfault. That
segfault cannot be handled, because signal delivery fails, too.
This patch programs the CPU to clear NT on entry via SYSCALL (both
32-bit and 64-bit, by my reading of the AMD APM), and it clears NT
in software on entry via SYSENTER.
To save a few cycles, this borrows a trick from Jan Beulich in Xen:
it checks whether NT is set before trying to clear it. As a result,
it seems to have very little effect on SYSENTER performance on my
machine.
There's another minor bug fix in here: it looks like the CFI
annotations were wrong if CONFIG_AUDITSYSCALL=n.
Testers beware: on Xen, SYSENTER with NT set turns into a GPF.
I haven't touched anything on 32-bit kernels.
The syscall mask change comes from a variant of this patch by Anish
Bhatt.
Note to stable maintainers: there is no known security issue here.
A misguided program can set NT and cause the kernel to try and fail
to deliver SIGSEGV, crashing the program. This patch fixes Far Cry
on Wine: https://bugs.winehq.org/show_bug.cgi?id=33275
Cc: <stable@vger.kernel.org>
Reported-by: Anish Bhatt <anish@chelsio.com>
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/395749a5d39a29bd3e4b35899cf3a3c1340e5595.1412189265.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-10-01 22:49:04 +04:00
2015-10-06 03:48:11 +03:00
/ *
* User m o d e i s t r a c e d a s t h o u g h I R Q s a r e o n , a n d S Y S E N T E R
* turned t h e m o f f .
* /
TRACE_ I R Q S _ O F F
2015-10-06 03:48:02 +03:00
2015-10-06 03:48:11 +03:00
movq % r s p , % r d i
call d o _ f a s t _ s y s c a l l _ 3 2
2015-11-20 00:55:45 +03:00
/* XEN PV guests always use IRET path */
ALTERNATIVE " t e s t l % e a x , % e a x ; jz .Lsyscall_32_done", \
" jmp . L s y s c a l l _ 3 2 _ d o n e " , X 8 6 _ F E A T U R E _ X E N P V
2015-10-06 03:48:12 +03:00
jmp s y s r e t 3 2 _ f r o m _ s y s t e m _ c a l l
2005-04-17 02:20:36 +04:00
2015-12-12 13:27:57 +03:00
.Lsysenter_fix_flags :
2015-10-06 03:47:55 +03:00
pushq $ X 8 6 _ E F L A G S _ F I X E D
x86/debug: Remove perpetually broken, unmaintainable dwarf annotations
So the dwarf2 annotations in low level assembly code have
become an increasing hindrance: unreadable, messy macros
mixed into some of the most security sensitive code paths
of the Linux kernel.
These debug info annotations don't even buy the upstream
kernel anything: dwarf driven stack unwinding has caused
problems in the past so it's out of tree, and the upstream
kernel only uses the much more robust framepointers based
stack unwinding method.
In addition to that there's a steady, slow bitrot going
on with these annotations, requiring frequent fixups.
There's no tooling and no functionality upstream that
keeps it correct.
So burn down the sick forest, allowing new, healthier growth:
27 files changed, 350 insertions(+), 1101 deletions(-)
Someone who has the willingness and time to do this
properly can attempt to reintroduce dwarf debuginfo in x86
assembly code plus dwarf unwinding from first principles,
with the following conditions:
- it should be maximally readable, and maximally low-key to
'ordinary' code reading and maintenance.
- find a build time method to insert dwarf annotations
automatically in the most common cases, for pop/push
instructions that manipulate the stack pointer. This could
be done for example via a preprocessing step that just
looks for common patterns - plus special annotations for
the few cases where we want to depart from the default.
We have hundreds of CFI annotations, so automating most of
that makes sense.
- it should come with build tooling checks that ensure that
CFI annotations are sensible. We've seen such efforts from
the framepointer side, and there's no reason it couldn't be
done on the dwarf side.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-28 13:21:47 +03:00
popfq
2015-12-12 13:27:57 +03:00
jmp . L s y s e n t e r _ f l a g s _ f i x e d
2016-03-10 06:00:30 +03:00
GLOBAL( _ _ e n d _ e n t r y _ S Y S E N T E R _ c o m p a t )
2015-06-08 09:33:56 +03:00
ENDPROC( e n t r y _ S Y S E N T E R _ c o m p a t )
2005-04-17 02:20:36 +04:00
/ *
2016-03-10 06:00:35 +03:00
* 3 2 - bit S Y S C A L L e n t r y .
*
* 3 2 - bit s y s t e m c a l l s t h r o u g h t h e v D S O ' s _ _ k e r n e l _ v s y s c a l l e n t e r h e r e
* on 6 4 - b i t k e r n e l s r u n n i n g o n A M D C P U s .
*
* The S Y S C A L L i n s t r u c t i o n , i n p r i n c i p l e , s h o u l d * o n l y * o c c u r i n t h e
* vDSO. I n p r a c t i c e , i t a p p e a r s t h a t t h i s r e a l l y i s t h e c a s e .
* As e v i d e n c e :
*
* - The c a l l i n g c o n v e n t i o n f o r S Y S C A L L h a s c h a n g e d s e v e r a l t i m e s w i t h o u t
* anyone n o t i c i n g .
*
* - Prior t o t h e i n - k e r n e l X 8 6 _ B U G _ S Y S R E T _ S S _ A T T R S f i x u p , a n y t h i n g
* user t a s k t h a t d i d S Y S C A L L w i t h o u t i m m e d i a t e l y r e l o a d i n g S S
* would r a n d o m l y c r a s h .
2005-04-17 02:20:36 +04:00
*
2016-03-10 06:00:35 +03:00
* - Most p r o g r a m m e r s d o n o t d i r e c t l y t a r g e t A M D C P U s , a n d t h e 3 2 - b i t
* SYSCALL i n s t r u c t i o n d o e s n o t e x i s t o n I n t e l C P U s . E v e n o n A M D
* CPUs, L i n u x d i s a b l e s t h e S Y S C A L L i n s t r u c t i o n o n 3 2 - b i t k e r n e l s
* because t h e S Y S C A L L i n s t r u c t i o n i n l e g a c y / n a t i v e 3 2 - b i t m o d e ( a s
* opposed t o c o m p a t m o d e ) i s s u f f i c i e n t l y p o o r l y d e s i g n e d a s t o b e
* essentially u n u s a b l e .
2015-02-27 01:40:32 +03:00
*
2016-03-10 06:00:35 +03:00
* 3 2 - bit S Y S C A L L s a v e s R I P t o R C X , c l e a r s R F L A G S . R F , t h e n s a v e s
* RFLAGS t o R 1 1 , t h e n l o a d s n e w S S , C S , a n d R I P f r o m p r e v i o u s l y
* programmed M S R s . R F L A G S g e t s m a s k e d b y a v a l u e f r o m a n o t h e r M S R
* ( so C L D a n d C L A C a r e n o t n e e d e d ) . S Y S C A L L d o e s n o t s a v e a n y t h i n g o n
* the s t a c k a n d d o e s n o t c h a n g e R S P .
*
* Note : RFLAGS s a v i n g + m a s k i n g - w i t h - M S R h a p p e n s o n l y i n L o n g m o d e
2015-06-05 14:02:28 +03:00
* ( in l e g a c y 3 2 - b i t m o d e , I F , R F a n d V M b i t s a r e c l e a r e d a n d t h a t ' s i t ) .
2016-03-10 06:00:35 +03:00
* Don' t g e t c o n f u s e d : R F L A G S s a v i n g + m a s k i n g d e p e n d s o n L o n g M o d e A c t i v e b i t
2015-02-27 01:40:32 +03:00
* ( EFER. L M A =1 ) , N O T o n b i t n e s s o f u s e r s p a c e w h e r e S Y S C A L L e x e c u t e s
* or t a r g e t C S d e s c r i p t o r ' s L b i t ( S Y S C A L L d o e s n o t r e a d s e g m e n t d e s c r i p t o r s ) .
*
2005-04-17 02:20:36 +04:00
* Arguments :
2015-02-27 01:40:32 +03:00
* eax s y s t e m c a l l n u m b e r
* ecx r e t u r n a d d r e s s
* ebx a r g 1
* ebp a r g 2 ( n o t e : n o t s a v e d i n t h e s t a c k f r a m e , s h o u l d n o t b e t o u c h e d )
* edx a r g 3
* esi a r g 4
* edi a r g 5
* esp u s e r s t a c k
* 0 ( % esp) a r g 6
* /
2015-06-08 09:28:07 +03:00
ENTRY( e n t r y _ S Y S C A L L _ c o m p a t )
2015-10-06 03:48:11 +03:00
/* Interrupts are off on entry. */
2017-08-08 06:59:21 +03:00
swapgs
2015-10-06 03:48:02 +03:00
2015-10-06 03:48:11 +03:00
/* Stash user ESP and switch to the kernel stack. */
2015-06-05 14:02:28 +03:00
movl % e s p , % r8 d
movq P E R _ C P U _ V A R ( c p u _ c u r r e n t _ t o p _ o f _ s t a c k ) , % r s p
2015-03-27 13:36:20 +03:00
2015-03-31 20:00:04 +03:00
/* Construct struct pt_regs on stack */
x86/debug: Remove perpetually broken, unmaintainable dwarf annotations
So the dwarf2 annotations in low level assembly code have
become an increasing hindrance: unreadable, messy macros
mixed into some of the most security sensitive code paths
of the Linux kernel.
These debug info annotations don't even buy the upstream
kernel anything: dwarf driven stack unwinding has caused
problems in the past so it's out of tree, and the upstream
kernel only uses the much more robust framepointers based
stack unwinding method.
In addition to that there's a steady, slow bitrot going
on with these annotations, requiring frequent fixups.
There's no tooling and no functionality upstream that
keeps it correct.
So burn down the sick forest, allowing new, healthier growth:
27 files changed, 350 insertions(+), 1101 deletions(-)
Someone who has the willingness and time to do this
properly can attempt to reintroduce dwarf debuginfo in x86
assembly code plus dwarf unwinding from first principles,
with the following conditions:
- it should be maximally readable, and maximally low-key to
'ordinary' code reading and maintenance.
- find a build time method to insert dwarf annotations
automatically in the most common cases, for pop/push
instructions that manipulate the stack pointer. This could
be done for example via a preprocessing step that just
looks for common patterns - plus special annotations for
the few cases where we want to depart from the default.
We have hundreds of CFI annotations, so automating most of
that makes sense.
- it should come with build tooling checks that ensure that
CFI annotations are sensible. We've seen such efforts from
the framepointer side, and there's no reason it couldn't be
done on the dwarf side.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-28 13:21:47 +03:00
pushq $ _ _ U S E R 3 2 _ D S / * p t _ r e g s - > s s * /
pushq % r8 / * p t _ r e g s - > s p * /
pushq % r11 / * p t _ r e g s - > f l a g s * /
pushq $ _ _ U S E R 3 2 _ C S / * p t _ r e g s - > c s * /
pushq % r c x / * p t _ r e g s - > i p * /
2017-08-08 06:59:21 +03:00
GLOBAL( e n t r y _ S Y S C A L L _ c o m p a t _ a f t e r _ h w f r a m e )
movl % e a x , % e a x / * d i s c a r d o r i g _ a x h i g h b i t s * /
x86/debug: Remove perpetually broken, unmaintainable dwarf annotations
So the dwarf2 annotations in low level assembly code have
become an increasing hindrance: unreadable, messy macros
mixed into some of the most security sensitive code paths
of the Linux kernel.
These debug info annotations don't even buy the upstream
kernel anything: dwarf driven stack unwinding has caused
problems in the past so it's out of tree, and the upstream
kernel only uses the much more robust framepointers based
stack unwinding method.
In addition to that there's a steady, slow bitrot going
on with these annotations, requiring frequent fixups.
There's no tooling and no functionality upstream that
keeps it correct.
So burn down the sick forest, allowing new, healthier growth:
27 files changed, 350 insertions(+), 1101 deletions(-)
Someone who has the willingness and time to do this
properly can attempt to reintroduce dwarf debuginfo in x86
assembly code plus dwarf unwinding from first principles,
with the following conditions:
- it should be maximally readable, and maximally low-key to
'ordinary' code reading and maintenance.
- find a build time method to insert dwarf annotations
automatically in the most common cases, for pop/push
instructions that manipulate the stack pointer. This could
be done for example via a preprocessing step that just
looks for common patterns - plus special annotations for
the few cases where we want to depart from the default.
We have hundreds of CFI annotations, so automating most of
that makes sense.
- it should come with build tooling checks that ensure that
CFI annotations are sensible. We've seen such efforts from
the framepointer side, and there's no reason it couldn't be
done on the dwarf side.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-28 13:21:47 +03:00
pushq % r a x / * p t _ r e g s - > o r i g _ a x * /
pushq % r d i / * p t _ r e g s - > d i * /
pushq % r s i / * p t _ r e g s - > s i * /
pushq % r d x / * p t _ r e g s - > d x * /
2015-12-17 10:18:48 +03:00
pushq % r b p / * p t _ r e g s - > c x ( s t a s h e d i n b p ) * /
x86/debug: Remove perpetually broken, unmaintainable dwarf annotations
So the dwarf2 annotations in low level assembly code have
become an increasing hindrance: unreadable, messy macros
mixed into some of the most security sensitive code paths
of the Linux kernel.
These debug info annotations don't even buy the upstream
kernel anything: dwarf driven stack unwinding has caused
problems in the past so it's out of tree, and the upstream
kernel only uses the much more robust framepointers based
stack unwinding method.
In addition to that there's a steady, slow bitrot going
on with these annotations, requiring frequent fixups.
There's no tooling and no functionality upstream that
keeps it correct.
So burn down the sick forest, allowing new, healthier growth:
27 files changed, 350 insertions(+), 1101 deletions(-)
Someone who has the willingness and time to do this
properly can attempt to reintroduce dwarf debuginfo in x86
assembly code plus dwarf unwinding from first principles,
with the following conditions:
- it should be maximally readable, and maximally low-key to
'ordinary' code reading and maintenance.
- find a build time method to insert dwarf annotations
automatically in the most common cases, for pop/push
instructions that manipulate the stack pointer. This could
be done for example via a preprocessing step that just
looks for common patterns - plus special annotations for
the few cases where we want to depart from the default.
We have hundreds of CFI annotations, so automating most of
that makes sense.
- it should come with build tooling checks that ensure that
CFI annotations are sensible. We've seen such efforts from
the framepointer side, and there's no reason it couldn't be
done on the dwarf side.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-28 13:21:47 +03:00
pushq $ - E N O S Y S / * p t _ r e g s - > a x * /
2016-05-02 17:56:50 +03:00
pushq $ 0 / * p t _ r e g s - > r8 = 0 * /
pushq $ 0 / * p t _ r e g s - > r9 = 0 * /
pushq $ 0 / * p t _ r e g s - > r10 = 0 * /
pushq $ 0 / * p t _ r e g s - > r11 = 0 * /
2015-10-06 03:48:11 +03:00
pushq % r b x / * p t _ r e g s - > r b x * /
2015-12-17 10:18:48 +03:00
pushq % r b p / * p t _ r e g s - > r b p ( w i l l b e o v e r w r i t t e n ) * /
2016-05-02 17:56:50 +03:00
pushq $ 0 / * p t _ r e g s - > r12 = 0 * /
pushq $ 0 / * p t _ r e g s - > r13 = 0 * /
pushq $ 0 / * p t _ r e g s - > r14 = 0 * /
pushq $ 0 / * p t _ r e g s - > r15 = 0 * /
2015-03-31 20:00:04 +03:00
2015-10-06 03:48:11 +03:00
/ *
* User m o d e i s t r a c e d a s t h o u g h I R Q s a r e o n , a n d S Y S E N T E R
* turned t h e m o f f .
* /
TRACE_ I R Q S _ O F F
movq % r s p , % r d i
call d o _ f a s t _ s y s c a l l _ 3 2
2015-11-20 00:55:45 +03:00
/* XEN PV guests always use IRET path */
ALTERNATIVE " t e s t l % e a x , % e a x ; jz .Lsyscall_32_done", \
" jmp . L s y s c a l l _ 3 2 _ d o n e " , X 8 6 _ F E A T U R E _ X E N P V
2015-10-06 03:48:12 +03:00
/* Opportunistic SYSRET */
sysret32_from_system_call :
TRACE_ I R Q S _ O N / * U s e r m o d e t r a c e s a s I R Q s o n . * /
movq R B X ( % r s p ) , % r b x / * p t _ r e g s - > r b x * /
movq R B P ( % r s p ) , % r b p / * p t _ r e g s - > r b p * /
movq E F L A G S ( % r s p ) , % r11 / * p t _ r e g s - > f l a g s ( i n r11 ) * /
movq R I P ( % r s p ) , % r c x / * p t _ r e g s - > i p ( i n r c x ) * /
addq $ R A X , % r s p / * S k i p r8 - r15 * /
popq % r a x / * p t _ r e g s - > r a x * /
popq % r d x / * S k i p p t _ r e g s - > c x * /
popq % r d x / * p t _ r e g s - > d x * /
popq % r s i / * p t _ r e g s - > s i * /
popq % r d i / * p t _ r e g s - > d i * /
/ *
* USERGS_ S Y S R E T 3 2 d o e s :
* GSBASE = u s e r ' s G S b a s e
* EIP = E C X
* RFLAGS = R 1 1
* CS = _ _ U S E R 3 2 _ C S
* SS = _ _ U S E R _ D S
*
* ECX w i l l n o t m a t c h p t _ r e g s - > c x , b u t w e ' r e r e t u r n i n g t o a v D S O
* trampoline t h a t w i l l f i x u p R C X , s o t h i s i s o k a y .
*
* R1 2 - R 1 5 a r e c a l l e e - s a v e d , s o t h e y c o n t a i n w h a t e v e r w a s i n t h e m
* when t h e s y s t e m c a l l s t a r t e d , w h i c h i s a l r e a d y k n o w n t o u s e r
* code. W e z e r o R 8 - R 1 0 t o a v o i d i n f o l e a k s .
* /
xorq % r8 , % r8
xorq % r9 , % r9
xorq % r10 , % r10
movq R S P - O R I G _ R A X ( % r s p ) , % r s p
2015-11-20 00:55:47 +03:00
swapgs
sysretl
2015-06-08 09:28:07 +03:00
END( e n t r y _ S Y S C A L L _ c o m p a t )
2015-06-05 14:02:28 +03:00
2015-02-27 01:40:32 +03:00
/ *
2016-03-10 06:00:35 +03:00
* 3 2 - bit l e g a c y s y s t e m c a l l e n t r y .
*
* 3 2 - bit x86 L i n u x s y s t e m c a l l s t r a d i t i o n a l l y u s e d t h e I N T $ 0 x80
* instruction. I N T $ 0 x80 l a n d s h e r e .
*
* This e n t r y p o i n t c a n b e u s e d b y 3 2 - b i t a n d 6 4 - b i t p r o g r a m s t o p e r f o r m
* 3 2 - bit s y s t e m c a l l s . I n s t a n c e s o f I N T $ 0 x80 c a n b e f o u n d i n l i n e i n
* various p r o g r a m s a n d l i b r a r i e s . I t i s a l s o u s e d b y t h e v D S O ' s
* _ _ kernel_ v s y s c a l l f a l l b a c k f o r h a r d w a r e t h a t d o e s n ' t s u p p o r t a f a s t e r
* entry m e t h o d . R e s t a r t e d 3 2 - b i t s y s t e m c a l l s a l s o f a l l b a c k t o I N T
* $ 0 x8 0 r e g a r d l e s s o f w h a t i n s t r u c t i o n w a s o r i g i n a l l y u s e d t o d o t h e
* system c a l l .
*
* This i s c o n s i d e r e d a s l o w p a t h . I t i s n o t u s e d b y m o s t l i b c
* implementations o n m o d e r n h a r d w a r e e x c e p t d u r i n g p r o c e s s s t a r t u p .
2005-04-17 02:20:36 +04:00
*
2015-02-27 01:40:32 +03:00
* Arguments :
* eax s y s t e m c a l l n u m b e r
* ebx a r g 1
* ecx a r g 2
* edx a r g 3
* esi a r g 4
* edi a r g 5
2016-03-10 06:00:35 +03:00
* ebp a r g 6
2015-02-27 01:40:32 +03:00
* /
2015-06-08 09:28:07 +03:00
ENTRY( e n t r y _ I N T 8 0 _ c o m p a t )
2006-07-03 11:24:45 +04:00
/ *
2015-03-27 13:36:20 +03:00
* Interrupts a r e o f f o n e n t r y .
2006-07-03 11:24:45 +04:00
* /
2016-02-24 23:18:49 +03:00
ASM_ C L A C / * D o t h i s e a r l y t o m i n i m i z e e x p o s u r e * /
2015-03-27 13:36:20 +03:00
SWAPGS
2015-10-06 03:48:09 +03:00
/ *
* User t r a c i n g c o d e ( p t r a c e o r s i g n a l h a n d l e r s ) m i g h t a s s u m e t h a t
* the s a v e d R A X c o n t a i n s a 3 2 - b i t n u m b e r w h e n w e ' r e i n v o k i n g a 3 2 - b i t
* syscall. J u s t i n c a s e t h e h i g h b i t s a r e n o n z e r o , z e r o - e x t e n d
* the s y s c a l l n u m b e r . ( T h i s c o u l d a l m o s t c e r t a i n l y b e d e l e t e d
* with n o i l l e f f e c t s . )
* /
2015-06-05 14:02:28 +03:00
movl % e a x , % e a x
2015-03-27 13:36:21 +03:00
2015-03-31 20:00:04 +03:00
/* Construct struct pt_regs on stack (iret frame is already on stack) */
x86/debug: Remove perpetually broken, unmaintainable dwarf annotations
So the dwarf2 annotations in low level assembly code have
become an increasing hindrance: unreadable, messy macros
mixed into some of the most security sensitive code paths
of the Linux kernel.
These debug info annotations don't even buy the upstream
kernel anything: dwarf driven stack unwinding has caused
problems in the past so it's out of tree, and the upstream
kernel only uses the much more robust framepointers based
stack unwinding method.
In addition to that there's a steady, slow bitrot going
on with these annotations, requiring frequent fixups.
There's no tooling and no functionality upstream that
keeps it correct.
So burn down the sick forest, allowing new, healthier growth:
27 files changed, 350 insertions(+), 1101 deletions(-)
Someone who has the willingness and time to do this
properly can attempt to reintroduce dwarf debuginfo in x86
assembly code plus dwarf unwinding from first principles,
with the following conditions:
- it should be maximally readable, and maximally low-key to
'ordinary' code reading and maintenance.
- find a build time method to insert dwarf annotations
automatically in the most common cases, for pop/push
instructions that manipulate the stack pointer. This could
be done for example via a preprocessing step that just
looks for common patterns - plus special annotations for
the few cases where we want to depart from the default.
We have hundreds of CFI annotations, so automating most of
that makes sense.
- it should come with build tooling checks that ensure that
CFI annotations are sensible. We've seen such efforts from
the framepointer side, and there's no reason it couldn't be
done on the dwarf side.
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jan Beulich <JBeulich@suse.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-05-28 13:21:47 +03:00
pushq % r a x / * p t _ r e g s - > o r i g _ a x * /
pushq % r d i / * p t _ r e g s - > d i * /
pushq % r s i / * p t _ r e g s - > s i * /
pushq % r d x / * p t _ r e g s - > d x * /
pushq % r c x / * p t _ r e g s - > c x * /
pushq $ - E N O S Y S / * p t _ r e g s - > a x * /
2016-05-02 17:56:50 +03:00
pushq $ 0 / * p t _ r e g s - > r8 = 0 * /
pushq $ 0 / * p t _ r e g s - > r9 = 0 * /
pushq $ 0 / * p t _ r e g s - > r10 = 0 * /
pushq $ 0 / * p t _ r e g s - > r11 = 0 * /
2015-10-06 03:48:05 +03:00
pushq % r b x / * p t _ r e g s - > r b x * /
pushq % r b p / * p t _ r e g s - > r b p * /
pushq % r12 / * p t _ r e g s - > r12 * /
pushq % r13 / * p t _ r e g s - > r13 * /
pushq % r14 / * p t _ r e g s - > r14 * /
pushq % r15 / * p t _ r e g s - > r15 * /
2005-04-17 02:20:36 +04:00
cld
2015-06-05 14:02:28 +03:00
2015-06-02 22:04:02 +03:00
/ *
2015-10-06 03:48:09 +03:00
* User m o d e i s t r a c e d a s t h o u g h I R Q s a r e o n , a n d t h e i n t e r r u p t
* gate t u r n e d t h e m o f f .
2015-06-02 22:04:02 +03:00
* /
2015-10-06 03:48:09 +03:00
TRACE_ I R Q S _ O F F
movq % r s p , % r d i
2016-03-10 00:24:32 +03:00
call d o _ i n t 8 0 _ s y s c a l l _ 3 2
2015-10-06 03:48:11 +03:00
.Lsyscall_32_done :
2015-10-06 03:48:09 +03:00
/* Go back to user mode. */
TRACE_ I R Q S _ O N
SWAPGS
jmp r e s t o r e _ r e g s _ a n d _ i r e t
2015-06-08 09:28:07 +03:00
END( e n t r y _ I N T 8 0 _ c o m p a t )
2005-04-17 02:20:36 +04:00
2017-08-24 11:06:24 +03:00
ENTRY( s t u b32 _ c l o n e )
2015-06-03 16:58:49 +03:00
/ *
2015-06-03 16:58:50 +03:00
* The 3 2 - b i t c l o n e A B I i s : c l o n e ( . . . , i n t t l s _ v a l , i n t * c h i l d _ t i d p t r ) .
* The 6 4 - b i t c l o n e A B I i s : c l o n e ( . . . , i n t * c h i l d _ t i d p t r , i n t t l s _ v a l ) .
*
* The n a t i v e 6 4 - b i t k e r n e l ' s s y s _ c l o n e ( ) i m p l e m e n t s t h e l a t t e r ,
* so w e n e e d t o s w a p a r g u m e n t s h e r e b e f o r e c a l l i n g i t :
2015-06-03 16:58:49 +03:00
* /
2015-06-03 16:58:50 +03:00
xchg % r8 , % r c x
2015-10-06 03:48:05 +03:00
jmp s y s _ c l o n e
2017-08-24 11:06:24 +03:00
ENDPROC( s t u b32 _ c l o n e )