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"
2008-06-25 08:19:28 +04:00
# ifdef C O N F I G _ P A R A V I R T
ENTRY( n a t i v e _ u s e r g s _ s y s r e t 3 2 )
swapgs
sysretl
ENDPROC( n a t i v e _ u s e r g s _ s y s r e t 3 2 )
# endif
2005-04-17 02:20:36 +04:00
/ *
2015-06-05 14:02:28 +03:00
* 3 2 - bit S Y S E N T E R i n s t r u c t i o n e n t r y .
2005-04-17 02:20:36 +04:00
*
2015-02-27 01:40:32 +03:00
* 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 ) .
* 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 ,
* and d o e s n o t s a v e o l d r i p ( ! ! ! ) a n d r f l a g 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
* 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
*
2005-04-17 02:20:36 +04:00
* This i s p u r e l y a f a s t p a t h . F o r a n y t h i n g c o m p l i c a t e d w e u s e t h e i n t 0 x80
2015-02-27 01:40:32 +03:00
* path b e l o w . W e s e t u p a c o m p l e t e h a r d w a r e s t a c k f r a m e t o s h a r e c o d e
2005-04-17 02:20:36 +04:00
* with t h e i n t 0 x80 p a t h .
2015-02-27 01:40:32 +03:00
* /
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-03-27 13:36:21 +03:00
/* Zero-extending 32-bit regs, do not remove */
movl % e b p , % e b p
movl % e a x , % e a x
2015-03-31 20:00:04 +03:00
movl A S M _ T H R E A D _ I N F O ( T I _ s y s e n t e r _ r e t u r n , % r s p , 0 ) , % r10 d
/* 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 % r b p / * p t _ r e g s - > s 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 * /
2015-06-05 14:02:28 +03:00
pushq % r10 / * p t _ r e g s - > i p = t h r e a d _ i n f o - > s y s e n t e r _ r e t u r n * /
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 * /
2005-04-17 02:20:36 +04:00
cld
2015-06-05 14:02:28 +03:00
sub $ ( 1 0 * 8 ) , % r s p / * p t _ r e g s - > r8 - 1 1 , b p , b x , r12 - 1 5 n o t s a v e d * /
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
/ *
* 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
* 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
* NT 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 .
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-06-05 14:02:28 +03:00
testl $ X 8 6 _ E F L A G S _ N T , E F L A G S ( % r s p )
jnz s y s e n t e r _ f i x _ f l a g s
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
sysenter_flags_fixed :
2015-10-06 03:48:02 +03:00
/* Temporary: SYSENTER is disabled. */
# ifdef C O N F I G _ C O N T E X T _ T R A C K I N G
call e n t e r _ f r o m _ u s e r _ m o d e
# endif
ENABLE_ I N T E R R U P T S ( C L B R _ N O N E )
movl $ 1 1 , % e d i
call d o _ e x i t
2015-10-06 03:48:04 +03:00
/* Unreachable. */
ud2
2005-04-17 02:20:36 +04: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
sysenter_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-06-05 14:02:28 +03:00
jmp s y s e n t e r _ f l a g s _ f i x e d
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
/ *
2015-06-05 14:02:28 +03:00
* 3 2 - bit S Y S C A L L i n s t r u c t i o n e n t r y .
2005-04-17 02:20:36 +04:00
*
2015-06-05 14:02:28 +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 r f l a g s t o r11 ,
2015-02-27 01:40:32 +03:00
* then 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 p r o g r a m m e d M S R s .
* rflags 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 ( s o C L D a n d C L A C
* are 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 t h e s t a c k
* and 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 ) .
2015-02-27 01:40:32 +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
* ( 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
*
2005-04-17 02:20:36 +04:00
* This i s p u r e l y a f a s t p a t h . F o r a n y t h i n g c o m p l i c a t e d w e u s e t h e i n t 0 x80
2015-02-27 01:40:32 +03:00
* path b e l o w . W e s e t u p a c o m p l e t e h a r d w a r e s t a c k f r a m e t o s h a r e c o d e
* with t h e i n t 0 x80 p a t h .
* /
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-03-27 13:36:20 +03:00
/ *
* Interrupts a r e o f f o n e n t r y .
* We d o n o t f r a m e t h i s t i n y i r q - o f f b l o c k w i t h T R A C E _ I R Q S _ O F F / O N ,
* it i s t o o s m a l l t o e v e r c a u s e n o t i c e a b l e i r q l a t e n c y .
* /
2008-06-26 18:28:51 +04:00
SWAPGS_ U N S A F E _ S T A C K
2015-10-06 03:48:02 +03:00
/* Temporary: SYSCALL32 is disabled. */
movl $ - E N O S Y S , % e a x
USERGS_ S Y S R E T 3 2
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
2008-06-25 08:19:29 +04:00
ENABLE_ I N T E R R U P T S ( C L B R _ N O N E )
2015-03-27 13:36:20 +03:00
2015-03-27 13:36:21 +03:00
/* Zero-extending 32-bit regs, do not remove */
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 */
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 * /
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 b p / * p t _ r e g s - > c x * /
2015-06-05 14:02:28 +03:00
movl % e b p , % e 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 * /
2015-06-05 14:02:28 +03:00
sub $ ( 1 0 * 8 ) , % r s p / * p t _ r e g s - > r8 - 1 1 , b p , b x , r12 - 1 5 n o t s a v e d * /
2015-03-31 20:00:04 +03:00
2015-10-06 03:48:04 +03:00
/* Unreachable. */
ud2
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
/ *
* Emulated I A 3 2 s y s t e m c a l l s v i a i n t 0 x80 .
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
* ebp a r g 6 ( 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 )
2005-04-17 02:20:36 +04:00
*
* Notes :
2015-02-27 01:40:32 +03:00
* Uses t h e s a m e s t a c k f r a m e a s t h e x86 - 6 4 v e r s i o n .
* All r e g i s t e r s e x c e p t e a x m u s t b e s a v e d ( b u t p t r a c e m a y v i o l a t e t h a t ) .
2005-04-17 02:20:36 +04:00
* Arguments a r e z e r o e x t e n d e d . F o r s y s t e m c a l l s t h a t w a n t s i g n e x t e n s i o n a n d
* take l o n g a r g u m e n t s a w r a p p e r i s n e e d e d . M o s t c a l l s c a n j u s t b e c a l l e d
* directly.
2015-02-27 01:40:32 +03:00
* Assumes i t i s o n l y c a l l e d f r o m u s e r s p a c e a n d e n t e r e d w i t h i n t e r r u p t s o f f .
* /
2005-04-17 02:20:36 +04: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 .
* We d o n o t f r a m e t h i s t i n y i r q - o f f b l o c k w i t h T R A C E _ I R Q S _ O F F / O N ,
* it i s t o o s m a l l t o e v e r c a u s e n o t i c e a b l e i r q l a t e n c y .
2006-07-03 11:24:45 +04:00
* /
2015-03-27 13:36:20 +03:00
PARAVIRT_ A D J U S T _ E X C E P T I O N _ F R A M E
SWAPGS
2008-06-25 08:19:29 +04:00
ENABLE_ I N T E R R U P T S ( C L B R _ N O N E )
2015-03-27 13:36:20 +03:00
2015-03-27 13:36:21 +03:00
/* Zero-extending 32-bit regs, do not remove */
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 * /
2015-06-02 20:35:10 +03:00
pushq $ 0 / * p t _ r e g s - > r8 * /
pushq $ 0 / * p t _ r e g s - > r9 * /
pushq $ 0 / * p t _ r e g s - > r10 * /
pushq $ 0 / * p t _ r e g s - > r11 * /
2005-04-17 02:20:36 +04:00
cld
2015-06-05 14:02:28 +03:00
sub $ ( 6 * 8 ) , % r s p / * p t _ r e g s - > b p , b x , r12 - 1 5 n o t s a v e d * /
orl $ T S _ C O M P A T , A S M _ T H R E A D _ I N F O ( T I _ s t a t u s , % r s p , S I Z E O F _ P T R E G S )
testl $ _ T I F _ W O R K _ S Y S C A L L _ E N T R Y , A S M _ T H R E A D _ I N F O ( T I _ f l a g s , % r s p , S I Z E O F _ P T R E G S )
jnz i a32 _ t r a c e s y s
2015-03-31 20:00:04 +03:00
2009-02-07 05:15:18 +03:00
ia32_do_call :
2015-06-05 14:02:28 +03:00
/* 32-bit syscall -> 64-bit C ABI argument conversion */
movl % e d i , % r8 d / * a r g 5 * /
movl % e b p , % r9 d / * a r g 6 * /
xchg % e c x , % e s i / * r s i : a r g 2 , r c x : a r g 4 * /
movl % e b x , % e d i / * a r g 1 * /
movl % e d x , % e d x / * a r g 3 ( z e r o e x t e n s i o n ) * /
cmpq $ ( I A 3 2 _ N R _ s y s c a l l s - 1 ) , % r a x
2015-04-21 19:03:14 +03:00
ja 1 f
2015-06-05 14:02:28 +03:00
2015-06-07 21:24:30 +03:00
call * i a32 _ s y s _ c a l l _ t a b l e ( , % r a x , 8 )
2015-06-05 14:02:28 +03:00
movq % r a x , R A X ( % r s p )
2015-04-21 19:03:14 +03:00
1 :
2015-06-05 14:02:28 +03:00
jmp i n t _ r e t _ f r o m _ s y s _ c a l l
2005-04-17 02:20:36 +04:00
x86/asm/entry/64: Always allocate a complete "struct pt_regs" on the kernel stack
The 64-bit entry code was using six stack slots less by not
saving/restoring registers which are callee-preserved according
to the C ABI, and was not allocating space for them.
Only when syscalls needed a complete "struct pt_regs" was
the complete area allocated and filled in.
As an additional twist, on interrupt entry a "slightly less
truncated pt_regs" trick is used, to make nested interrupt
stacks easier to unwind.
This proved to be a source of significant obfuscation and subtle
bugs. For example, 'stub_fork' had to pop the return address,
extend the struct, save registers, and push return address back.
Ugly. 'ia32_ptregs_common' pops return address and "returns" via
jmp insn, throwing a wrench into CPU return stack cache.
This patch changes the code to always allocate a complete
"struct pt_regs" on the kernel stack. The saving of registers
is still done lazily.
"Partial pt_regs" trick on interrupt stack is retained.
Macros which manipulate "struct pt_regs" on stack are reworked:
- ALLOC_PT_GPREGS_ON_STACK allocates the structure.
- SAVE_C_REGS saves to it those registers which are clobbered
by C code.
- SAVE_EXTRA_REGS saves to it all other registers.
- Corresponding RESTORE_* and REMOVE_PT_GPREGS_FROM_STACK macros
reverse it.
'ia32_ptregs_common', 'stub_fork' and friends lost their ugly dance
with the return pointer.
LOAD_ARGS32 in ia32entry.S now uses symbolic stack offsets
instead of magic numbers.
'error_entry' and 'save_paranoid' now use SAVE_C_REGS +
SAVE_EXTRA_REGS instead of having it open-coded yet again.
Patch was run-tested: 64-bit executables, 32-bit executables,
strace works.
Timing tests did not show measurable difference in 32-bit
and 64-bit syscalls.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Cc: Alexei Starovoitov <ast@plumgrid.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Will Drewry <wad@chromium.org>
Link: http://lkml.kernel.org/r/1423778052-21038-2-git-send-email-dvlasenk@redhat.com
Link: http://lkml.kernel.org/r/b89763d354aa23e670b9bdf3a40ae320320a7c2e.1424989793.git.luto@amacapital.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-02-27 01:40:27 +03:00
ia32_tracesys :
SAVE_ E X T R A _ R E G S
2015-06-05 14:02:28 +03:00
movq % r s p , % r d i / * & p t _ r e g s - > a r g 1 * /
call s y s c a l l _ t r a c e _ e n t e r
2015-06-02 22:04:02 +03:00
/ *
* Reload a r g r e g i s t e r s f r o m s t a c k i n c a s e p t r a c e c h a n g e d t h e m .
* Don' t r e l o a d % e a x b e c a u s e s y s c a l l _ t r a c e _ e n t e r ( ) r e t u r n e d
* the % r a x v a l u e w e s h o u l d s e e . B u t d o t r u n c a t e i t t o 3 2 b i t s .
* If i t ' s - 1 t o m a k e u s p u n t t h e s y s c a l l , t h e n ( u 3 2 ) - 1 i s s t i l l
* an a p p r o p r i a t e l y i n v a l i d v a l u e .
* /
movl R C X ( % r s p ) , % e c x
movl R D X ( % r s p ) , % e d x
movl R S I ( % r s p ) , % e s i
movl R D I ( % r s p ) , % e d i
2015-06-05 14:02:28 +03:00
movl % e a x , % e a x / * z e r o e x t e n s i o n * /
x86/asm/entry/64: Always allocate a complete "struct pt_regs" on the kernel stack
The 64-bit entry code was using six stack slots less by not
saving/restoring registers which are callee-preserved according
to the C ABI, and was not allocating space for them.
Only when syscalls needed a complete "struct pt_regs" was
the complete area allocated and filled in.
As an additional twist, on interrupt entry a "slightly less
truncated pt_regs" trick is used, to make nested interrupt
stacks easier to unwind.
This proved to be a source of significant obfuscation and subtle
bugs. For example, 'stub_fork' had to pop the return address,
extend the struct, save registers, and push return address back.
Ugly. 'ia32_ptregs_common' pops return address and "returns" via
jmp insn, throwing a wrench into CPU return stack cache.
This patch changes the code to always allocate a complete
"struct pt_regs" on the kernel stack. The saving of registers
is still done lazily.
"Partial pt_regs" trick on interrupt stack is retained.
Macros which manipulate "struct pt_regs" on stack are reworked:
- ALLOC_PT_GPREGS_ON_STACK allocates the structure.
- SAVE_C_REGS saves to it those registers which are clobbered
by C code.
- SAVE_EXTRA_REGS saves to it all other registers.
- Corresponding RESTORE_* and REMOVE_PT_GPREGS_FROM_STACK macros
reverse it.
'ia32_ptregs_common', 'stub_fork' and friends lost their ugly dance
with the return pointer.
LOAD_ARGS32 in ia32entry.S now uses symbolic stack offsets
instead of magic numbers.
'error_entry' and 'save_paranoid' now use SAVE_C_REGS +
SAVE_EXTRA_REGS instead of having it open-coded yet again.
Patch was run-tested: 64-bit executables, 32-bit executables,
strace works.
Timing tests did not show measurable difference in 32-bit
and 64-bit syscalls.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Cc: Alexei Starovoitov <ast@plumgrid.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Will Drewry <wad@chromium.org>
Link: http://lkml.kernel.org/r/1423778052-21038-2-git-send-email-dvlasenk@redhat.com
Link: http://lkml.kernel.org/r/b89763d354aa23e670b9bdf3a40ae320320a7c2e.1424989793.git.luto@amacapital.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-02-27 01:40:27 +03:00
RESTORE_ E X T R A _ R E G S
2015-06-05 14:02:28 +03:00
jmp i a32 _ d o _ c a l l
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
2013-07-10 22:04:28 +04:00
.macro PTREGSCALL label, f u n c
2011-11-29 15:24:10 +04:00
ALIGN
GLOBAL( \ l a b e l )
2015-06-05 14:02:28 +03:00
leaq \ f u n c ( % r i p ) , % r a x
jmp i a32 _ p t r e g s _ c o m m o n
2005-04-17 02:20:36 +04:00
.endm
2015-06-05 14:02:28 +03:00
PTREGSCALL s t u b32 _ r t _ s i g r e t u r n , s y s32 _ r t _ s i g r e t u r n
PTREGSCALL s t u b32 _ s i g r e t u r n , s y s32 _ s i g r e t u r n
PTREGSCALL s t u b32 _ f o r k , s y s _ f o r k
PTREGSCALL s t u b32 _ v f o r k , s y s _ v f o r k
2005-04-17 02:20:36 +04:00
2012-10-23 06:34:11 +04:00
ALIGN
GLOBAL( s t u b32 _ c l o n e )
2015-06-05 14:02:28 +03:00
leaq s y s _ c l o n e ( % r i p ) , % r a x
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-06-05 14:02:28 +03:00
jmp i a32 _ p t r e g s _ c o m m o n
2012-10-23 06:34:11 +04:00
2011-11-29 15:24:10 +04:00
ALIGN
ia32_ptregs_common :
x86/asm/entry/64: Always allocate a complete "struct pt_regs" on the kernel stack
The 64-bit entry code was using six stack slots less by not
saving/restoring registers which are callee-preserved according
to the C ABI, and was not allocating space for them.
Only when syscalls needed a complete "struct pt_regs" was
the complete area allocated and filled in.
As an additional twist, on interrupt entry a "slightly less
truncated pt_regs" trick is used, to make nested interrupt
stacks easier to unwind.
This proved to be a source of significant obfuscation and subtle
bugs. For example, 'stub_fork' had to pop the return address,
extend the struct, save registers, and push return address back.
Ugly. 'ia32_ptregs_common' pops return address and "returns" via
jmp insn, throwing a wrench into CPU return stack cache.
This patch changes the code to always allocate a complete
"struct pt_regs" on the kernel stack. The saving of registers
is still done lazily.
"Partial pt_regs" trick on interrupt stack is retained.
Macros which manipulate "struct pt_regs" on stack are reworked:
- ALLOC_PT_GPREGS_ON_STACK allocates the structure.
- SAVE_C_REGS saves to it those registers which are clobbered
by C code.
- SAVE_EXTRA_REGS saves to it all other registers.
- Corresponding RESTORE_* and REMOVE_PT_GPREGS_FROM_STACK macros
reverse it.
'ia32_ptregs_common', 'stub_fork' and friends lost their ugly dance
with the return pointer.
LOAD_ARGS32 in ia32entry.S now uses symbolic stack offsets
instead of magic numbers.
'error_entry' and 'save_paranoid' now use SAVE_C_REGS +
SAVE_EXTRA_REGS instead of having it open-coded yet again.
Patch was run-tested: 64-bit executables, 32-bit executables,
strace works.
Timing tests did not show measurable difference in 32-bit
and 64-bit syscalls.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Cc: Alexei Starovoitov <ast@plumgrid.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Will Drewry <wad@chromium.org>
Link: http://lkml.kernel.org/r/1423778052-21038-2-git-send-email-dvlasenk@redhat.com
Link: http://lkml.kernel.org/r/b89763d354aa23e670b9bdf3a40ae320320a7c2e.1424989793.git.luto@amacapital.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-02-27 01:40:27 +03:00
SAVE_ E X T R A _ R E G S 8
2015-06-05 14:02:28 +03:00
call * % r a x
x86/asm/entry/64: Always allocate a complete "struct pt_regs" on the kernel stack
The 64-bit entry code was using six stack slots less by not
saving/restoring registers which are callee-preserved according
to the C ABI, and was not allocating space for them.
Only when syscalls needed a complete "struct pt_regs" was
the complete area allocated and filled in.
As an additional twist, on interrupt entry a "slightly less
truncated pt_regs" trick is used, to make nested interrupt
stacks easier to unwind.
This proved to be a source of significant obfuscation and subtle
bugs. For example, 'stub_fork' had to pop the return address,
extend the struct, save registers, and push return address back.
Ugly. 'ia32_ptregs_common' pops return address and "returns" via
jmp insn, throwing a wrench into CPU return stack cache.
This patch changes the code to always allocate a complete
"struct pt_regs" on the kernel stack. The saving of registers
is still done lazily.
"Partial pt_regs" trick on interrupt stack is retained.
Macros which manipulate "struct pt_regs" on stack are reworked:
- ALLOC_PT_GPREGS_ON_STACK allocates the structure.
- SAVE_C_REGS saves to it those registers which are clobbered
by C code.
- SAVE_EXTRA_REGS saves to it all other registers.
- Corresponding RESTORE_* and REMOVE_PT_GPREGS_FROM_STACK macros
reverse it.
'ia32_ptregs_common', 'stub_fork' and friends lost their ugly dance
with the return pointer.
LOAD_ARGS32 in ia32entry.S now uses symbolic stack offsets
instead of magic numbers.
'error_entry' and 'save_paranoid' now use SAVE_C_REGS +
SAVE_EXTRA_REGS instead of having it open-coded yet again.
Patch was run-tested: 64-bit executables, 32-bit executables,
strace works.
Timing tests did not show measurable difference in 32-bit
and 64-bit syscalls.
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Cc: Alexei Starovoitov <ast@plumgrid.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Will Drewry <wad@chromium.org>
Link: http://lkml.kernel.org/r/1423778052-21038-2-git-send-email-dvlasenk@redhat.com
Link: http://lkml.kernel.org/r/b89763d354aa23e670b9bdf3a40ae320320a7c2e.1424989793.git.luto@amacapital.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2015-02-27 01:40:27 +03:00
RESTORE_ E X T R A _ R E G S 8
ret
2006-06-26 15:56:55 +04:00
END( i a32 _ p t r e g s _ c o m m o n )