Skip to content

Commit 22e2430

Browse files
author
Al Viro
committed
x86, um: convert to saner kernel_execve() semantics
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent a74fb73 commit 22e2430

10 files changed

Lines changed: 21 additions & 68 deletions

File tree

‎arch/um/include/asm/processor-generic.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ struct thread_struct {
2626
jmp_buf *fault_catcher;
2727
struct task_struct *prev_sched;
2828
unsigned long temp_stack;
29-
jmp_buf *exec_buf;
3029
struct arch_thread arch;
3130
jmp_buf switch_buf;
3231
int mm_count;
@@ -54,7 +53,6 @@ struct thread_struct {
5453
.fault_addr = NULL, \
5554
.prev_sched = NULL, \
5655
.temp_stack = 0, \
57-
.exec_buf = NULL, \
5856
.arch = INIT_ARCH_THREAD, \
5957
.request = { 0 } \
6058
}

‎arch/um/include/shared/os.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ extern int os_getpid(void);
191191
extern int os_getpgrp(void);
192192

193193
extern void init_new_thread_signals(void);
194-
extern int run_kernel_thread(int (*fn)(void *), void *arg, jmp_buf **jmp_ptr);
195194

196195
extern int os_map_memory(void *virt, int fd, unsigned long long off,
197196
unsigned long len, int r, int w, int x);

‎arch/um/kernel/exec.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,3 @@ void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp)
4747
#endif
4848
}
4949
EXPORT_SYMBOL(start_thread);
50-
51-
void __noreturn ret_from_kernel_execve(struct pt_regs *unused)
52-
{
53-
UML_LONGJMP(current->thread.exec_buf, 1);
54-
}

‎arch/um/kernel/process.c‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,10 @@ void new_thread_handler(void)
135135
arg = current->thread.request.u.thread.arg;
136136

137137
/*
138-
* The return value is 1 if the kernel thread execs a process,
139-
* 0 if it just exits
138+
* callback returns only if the kernel thread execs a process
140139
*/
141-
n = run_kernel_thread(fn, arg, &current->thread.exec_buf);
142-
if (n == 1)
143-
userspace(&current->thread.regs.regs);
144-
else
145-
do_exit(0);
140+
n = fn(arg);
141+
userspace(&current->thread.regs.regs);
146142
}
147143

148144
/* Called magically, see new_thread_handler above */

‎arch/um/os-Linux/process.c‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,3 @@ void init_new_thread_signals(void)
244244
signal(SIGWINCH, SIG_IGN);
245245
signal(SIGTERM, SIG_DFL);
246246
}
247-
248-
int run_kernel_thread(int (*fn)(void *), void *arg, jmp_buf **jmp_ptr)
249-
{
250-
jmp_buf buf;
251-
int n;
252-
253-
*jmp_ptr = &buf;
254-
n = UML_SETJMP(&buf);
255-
if (n != 0)
256-
return n;
257-
(*fn)(arg);
258-
return 0;
259-
}

‎arch/x86/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ config X86
9898
select GENERIC_STRNCPY_FROM_USER
9999
select GENERIC_STRNLEN_USER
100100
select GENERIC_KERNEL_THREAD
101+
select GENERIC_KERNEL_EXECVE
101102

102103
config INSTRUCTION_DECODER
103104
def_bool (KPROBES || PERF_EVENTS || UPROBES)

‎arch/x86/include/asm/unistd.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
# define __ARCH_WANT_SYS_UTIME
5252
# define __ARCH_WANT_SYS_WAITPID
5353
# define __ARCH_WANT_SYS_EXECVE
54-
# define __ARCH_WANT_KERNEL_EXECVE
5554

5655
/*
5756
* "Conditional" syscalls

‎arch/x86/kernel/entry_32.S‎

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,20 @@ ENTRY(ret_from_fork)
298298
CFI_ENDPROC
299299
END(ret_from_fork)
300300

301-
ENTRY(ret_from_kernel_execve)
302-
movl %eax, %esp
303-
movl $0,PT_EAX(%esp)
301+
ENTRY(ret_from_kernel_thread)
302+
CFI_STARTPROC
303+
pushl_cfi %eax
304+
call schedule_tail
304305
GET_THREAD_INFO(%ebp)
306+
popl_cfi %eax
307+
pushl_cfi $0x0202 # Reset kernel eflags
308+
popfl_cfi
309+
movl PT_EBP(%esp),%eax
310+
call *PT_EBX(%esp)
311+
movl $0,PT_EAX(%esp)
305312
jmp syscall_exit
306-
END(ret_from_kernel_execve)
313+
CFI_ENDPROC
314+
ENDPROC(ret_from_kernel_thread)
307315

308316
/*
309317
* Interrupt exit functions should be protected against kprobes
@@ -994,21 +1002,6 @@ END(spurious_interrupt_bug)
9941002
*/
9951003
.popsection
9961004

997-
ENTRY(ret_from_kernel_thread)
998-
CFI_STARTPROC
999-
pushl_cfi %eax
1000-
call schedule_tail
1001-
GET_THREAD_INFO(%ebp)
1002-
popl_cfi %eax
1003-
pushl_cfi $0x0202 # Reset kernel eflags
1004-
popfl_cfi
1005-
movl PT_EBP(%esp),%eax
1006-
call *PT_EBX(%esp)
1007-
call do_exit
1008-
ud2 # padding for call trace
1009-
CFI_ENDPROC
1010-
ENDPROC(ret_from_kernel_thread)
1011-
10121005
#ifdef CONFIG_XEN
10131006
/* Xen doesn't set %esp to be precisely what the normal sysenter
10141007
entrypoint expects, so fix it up before using the normal path. */

‎arch/x86/kernel/entry_64.S‎

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -459,15 +459,13 @@ ENTRY(ret_from_fork)
459459
jmp ret_from_sys_call # go to the SYSRET fastpath
460460

461461
1:
462-
subq $REST_SKIP, %rsp # move the stack pointer back
462+
subq $REST_SKIP, %rsp # leave space for volatiles
463463
CFI_ADJUST_CFA_OFFSET REST_SKIP
464464
movq %rbp, %rdi
465465
call *%rbx
466-
# exit
467-
mov %eax, %edi
468-
call do_exit
469-
ud2 # padding for call trace
470-
466+
movl $0, RAX(%rsp)
467+
RESTORE_REST
468+
jmp int_ret_from_sys_call
471469
CFI_ENDPROC
472470
END(ret_from_fork)
473471

@@ -1214,20 +1212,6 @@ bad_gs:
12141212
jmp 2b
12151213
.previous
12161214

1217-
ENTRY(ret_from_kernel_execve)
1218-
movq %rdi, %rsp
1219-
movl $0, RAX(%rsp)
1220-
// RESTORE_REST
1221-
movq 0*8(%rsp), %r15
1222-
movq 1*8(%rsp), %r14
1223-
movq 2*8(%rsp), %r13
1224-
movq 3*8(%rsp), %r12
1225-
movq 4*8(%rsp), %rbp
1226-
movq 5*8(%rsp), %rbx
1227-
addq $(6*8), %rsp
1228-
jmp int_ret_from_sys_call
1229-
END(ret_from_kernel_execve)
1230-
12311215
/* Call softirq on interrupt stack. Interrupts are off. */
12321216
ENTRY(call_softirq)
12331217
CFI_STARTPROC

‎arch/x86/um/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ config UML_X86
1414
def_bool y
1515
select GENERIC_FIND_FIRST_BIT
1616
select GENERIC_KERNEL_THREAD
17+
select GENERIC_KERNEL_EXECVE
1718

1819
config 64BIT
1920
bool "64-bit kernel" if SUBARCH = "x86"

0 commit comments

Comments
 (0)