Skip to content

Commit 8169aff

Browse files
amlutoIngo Molnar
authored andcommitted
x86/entry/64/compat: Set up full pt_regs for all compat syscalls
This is conceptually simpler. More importantly, it eliminates the PTREGSCALL and execve stubs, which were not compatible with the C ABI. This means that C code can call through the compat syscall table. The execve stubs are a bit subtle. They did two things: they cleared some registers and they forced slow-path return. Neither is necessary any more: elf_common_init clears the extra registers and start_thread calls force_iret(). Signed-off-by: Andy Lutomirski <luto@kernel.org> 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: H. Peter Anvin <hpa@zytor.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 Link: http://lkml.kernel.org/r/f95b7f7dfaacf88a8cae85bb06226cae53769287.1444091584.git.luto@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 2ec6797 commit 8169aff

File tree

3 files changed

+20
-40
lines changed

3 files changed

+20
-40
lines changed

arch/x86/entry/entry_64.S

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,20 +391,16 @@ GLOBAL(stub_execveat)
391391
jmp return_from_execve
392392
END(stub_execveat)
393393

394-
#if defined(CONFIG_X86_X32_ABI) || defined(CONFIG_IA32_EMULATION)
394+
#if defined(CONFIG_X86_X32_ABI)
395395
.align 8
396396
GLOBAL(stub_x32_execve)
397-
GLOBAL(stub32_execve)
398397
call compat_sys_execve
399398
jmp return_from_execve
400-
END(stub32_execve)
401399
END(stub_x32_execve)
402400
.align 8
403401
GLOBAL(stub_x32_execveat)
404-
GLOBAL(stub32_execveat)
405402
call compat_sys_execveat
406403
jmp return_from_execve
407-
END(stub32_execveat)
408404
END(stub_x32_execveat)
409405
#endif
410406

arch/x86/entry/entry_64_compat.S

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,18 @@ ENTRY(entry_INT80_compat)
219219
pushq %rdx /* pt_regs->dx */
220220
pushq %rcx /* pt_regs->cx */
221221
pushq $-ENOSYS /* pt_regs->ax */
222-
pushq $0 /* pt_regs->r8 */
223-
pushq $0 /* pt_regs->r9 */
224-
pushq $0 /* pt_regs->r10 */
225-
pushq $0 /* pt_regs->r11 */
222+
xorq %r8,%r8
223+
pushq %r8 /* pt_regs->r8 = 0 */
224+
pushq %r8 /* pt_regs->r9 = 0 */
225+
pushq %r8 /* pt_regs->r10 = 0 */
226+
pushq %r8 /* pt_regs->r11 = 0 */
227+
pushq %rbx /* pt_regs->rbx */
228+
pushq %rbp /* pt_regs->rbp */
229+
pushq %r12 /* pt_regs->r12 */
230+
pushq %r13 /* pt_regs->r13 */
231+
pushq %r14 /* pt_regs->r14 */
232+
pushq %r15 /* pt_regs->r15 */
226233
cld
227-
sub $(6*8), %rsp /* pt_regs->bp, bx, r12-15 not saved */
228234

229235
orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS)
230236
testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS)
@@ -243,10 +249,10 @@ ia32_do_call:
243249
call *ia32_sys_call_table(, %rax, 8)
244250
movq %rax, RAX(%rsp)
245251
1:
252+
RESTORE_EXTRA_REGS
246253
jmp int_ret_from_sys_call
247254

248255
ia32_tracesys:
249-
SAVE_EXTRA_REGS
250256
movq %rsp, %rdi /* &pt_regs -> arg1 */
251257
call syscall_trace_enter
252258
/*
@@ -261,25 +267,11 @@ ia32_tracesys:
261267
movl RSI(%rsp), %esi
262268
movl RDI(%rsp), %edi
263269
movl %eax, %eax /* zero extension */
264-
RESTORE_EXTRA_REGS
265270
jmp ia32_do_call
266271
END(entry_INT80_compat)
267272

268-
.macro PTREGSCALL label, func
269-
ALIGN
270-
GLOBAL(\label)
271-
leaq \func(%rip), %rax
272-
jmp ia32_ptregs_common
273-
.endm
274-
275-
PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn
276-
PTREGSCALL stub32_sigreturn, sys32_sigreturn
277-
PTREGSCALL stub32_fork, sys_fork
278-
PTREGSCALL stub32_vfork, sys_vfork
279-
280273
ALIGN
281274
GLOBAL(stub32_clone)
282-
leaq sys_clone(%rip), %rax
283275
/*
284276
* The 32-bit clone ABI is: clone(..., int tls_val, int *child_tidptr).
285277
* The 64-bit clone ABI is: clone(..., int *child_tidptr, int tls_val).
@@ -288,12 +280,4 @@ GLOBAL(stub32_clone)
288280
* so we need to swap arguments here before calling it:
289281
*/
290282
xchg %r8, %rcx
291-
jmp ia32_ptregs_common
292-
293-
ALIGN
294-
ia32_ptregs_common:
295-
SAVE_EXTRA_REGS 8
296-
call *%rax
297-
RESTORE_EXTRA_REGS 8
298-
ret
299-
END(ia32_ptregs_common)
283+
jmp sys_clone

arch/x86/entry/syscalls/syscall_32.tbl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#
99
0 i386 restart_syscall sys_restart_syscall
1010
1 i386 exit sys_exit
11-
2 i386 fork sys_fork stub32_fork
11+
2 i386 fork sys_fork sys_fork
1212
3 i386 read sys_read
1313
4 i386 write sys_write
1414
5 i386 open sys_open compat_sys_open
@@ -17,7 +17,7 @@
1717
8 i386 creat sys_creat
1818
9 i386 link sys_link
1919
10 i386 unlink sys_unlink
20-
11 i386 execve sys_execve stub32_execve
20+
11 i386 execve sys_execve compat_sys_execve
2121
12 i386 chdir sys_chdir
2222
13 i386 time sys_time compat_sys_time
2323
14 i386 mknod sys_mknod
@@ -125,7 +125,7 @@
125125
116 i386 sysinfo sys_sysinfo compat_sys_sysinfo
126126
117 i386 ipc sys_ipc compat_sys_ipc
127127
118 i386 fsync sys_fsync
128-
119 i386 sigreturn sys_sigreturn stub32_sigreturn
128+
119 i386 sigreturn sys_sigreturn sys32_sigreturn
129129
120 i386 clone sys_clone stub32_clone
130130
121 i386 setdomainname sys_setdomainname
131131
122 i386 uname sys_newuname
@@ -179,7 +179,7 @@
179179
170 i386 setresgid sys_setresgid16
180180
171 i386 getresgid sys_getresgid16
181181
172 i386 prctl sys_prctl
182-
173 i386 rt_sigreturn sys_rt_sigreturn stub32_rt_sigreturn
182+
173 i386 rt_sigreturn sys_rt_sigreturn sys32_rt_sigreturn
183183
174 i386 rt_sigaction sys_rt_sigaction compat_sys_rt_sigaction
184184
175 i386 rt_sigprocmask sys_rt_sigprocmask
185185
176 i386 rt_sigpending sys_rt_sigpending compat_sys_rt_sigpending
@@ -196,7 +196,7 @@
196196
187 i386 sendfile sys_sendfile compat_sys_sendfile
197197
188 i386 getpmsg
198198
189 i386 putpmsg
199-
190 i386 vfork sys_vfork stub32_vfork
199+
190 i386 vfork sys_vfork sys_vfork
200200
191 i386 ugetrlimit sys_getrlimit compat_sys_getrlimit
201201
192 i386 mmap2 sys_mmap_pgoff
202202
193 i386 truncate64 sys_truncate64 sys32_truncate64
@@ -364,7 +364,7 @@
364364
355 i386 getrandom sys_getrandom
365365
356 i386 memfd_create sys_memfd_create
366366
357 i386 bpf sys_bpf
367-
358 i386 execveat sys_execveat stub32_execveat
367+
358 i386 execveat sys_execveat compat_sys_execveat
368368
359 i386 socket sys_socket
369369
360 i386 socketpair sys_socketpair
370370
361 i386 bind sys_bind

0 commit comments

Comments
 (0)