Skip to content

Commit a5d2cfe

Browse files
benzeajmberg-intel
authored andcommitted
um: remove copy_context_skas0
The kernel flushes the memory ranges anyway for CoW and does not assume that the userspace process has anything set up already. So, start with a fresh process for the new mm context. Signed-off-by: Benjamin Berg <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Johannes Berg <[email protected]>
1 parent 7911b65 commit a5d2cfe

File tree

9 files changed

+10
-229
lines changed

9 files changed

+10
-229
lines changed

arch/um/include/shared/os.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ void protect(struct mm_id *mm_idp, unsigned long addr,
285285
/* skas/process.c */
286286
extern int is_skas_winch(int pid, int fd, void *data);
287287
extern int start_userspace(unsigned long stub_stack);
288-
extern int copy_context_skas0(unsigned long stack, int pid);
289288
extern void userspace(struct uml_pt_regs *regs, unsigned long *aux_fp_regs);
290289
extern void new_thread(void *stack, jmp_buf *buf, void (*handler)(void));
291290
extern void switch_threads(jmp_buf *me, jmp_buf *you);

arch/um/include/shared/skas/stub-data.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ struct stub_syscall {
3636

3737
struct stub_data {
3838
unsigned long offset;
39-
int fd;
4039
long err, child_err;
4140

4241
int syscall_data_len;

arch/um/kernel/skas/Makefile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
# Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
44
#
55

6-
obj-y := clone.o stub.o mmu.o process.o syscall.o uaccess.o
6+
obj-y := stub.o mmu.o process.o syscall.o uaccess.o
77

8-
# clone.o and stub.o are in the stub, so it can't be built with profiling
8+
# stub.o is in the stub, so it can't be built with profiling
99
# GCC hardened also auto-enables -fpic, but we need %ebx so it can't work ->
1010
# disable it
1111

12-
CFLAGS_clone.o := $(CFLAGS_NO_HARDENING)
1312
CFLAGS_stub.o := $(CFLAGS_NO_HARDENING)
14-
UNPROFILE_OBJS := clone.o stub.o
15-
13+
UNPROFILE_OBJS := stub.o
1614
KCOV_INSTRUMENT := n
1715

1816
include $(srctree)/arch/um/scripts/Makefile.rules

arch/um/kernel/skas/clone.c

Lines changed: 0 additions & 50 deletions
This file was deleted.

arch/um/kernel/skas/mmu.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,30 @@ static_assert(sizeof(struct stub_data) == STUB_DATA_PAGES * UM_KERN_PAGE_SIZE);
2121

2222
int init_new_context(struct task_struct *task, struct mm_struct *mm)
2323
{
24-
struct mm_context *from_mm = NULL;
25-
struct mm_context *to_mm = &mm->context;
24+
struct mm_id *new_id = &mm->context.id;
2625
unsigned long stack = 0;
2726
int ret = -ENOMEM;
2827

2928
stack = __get_free_pages(GFP_KERNEL | __GFP_ZERO, ilog2(STUB_DATA_PAGES));
3029
if (stack == 0)
3130
goto out;
3231

33-
to_mm->id.stack = stack;
34-
if (current->mm != NULL && current->mm != &init_mm)
35-
from_mm = &current->mm->context;
32+
new_id->stack = stack;
3633

3734
block_signals_trace();
38-
if (from_mm)
39-
to_mm->id.u.pid = copy_context_skas0(stack,
40-
from_mm->id.u.pid);
41-
else to_mm->id.u.pid = start_userspace(stack);
35+
new_id->u.pid = start_userspace(stack);
4236
unblock_signals_trace();
4337

44-
if (to_mm->id.u.pid < 0) {
45-
ret = to_mm->id.u.pid;
38+
if (new_id->u.pid < 0) {
39+
ret = new_id->u.pid;
4640
goto out_free;
4741
}
4842

4943
return 0;
5044

5145
out_free:
52-
if (to_mm->id.stack != 0)
53-
free_pages(to_mm->id.stack, ilog2(STUB_DATA_PAGES));
46+
if (new_id->stack != 0)
47+
free_pages(new_id->stack, ilog2(STUB_DATA_PAGES));
5448
out:
5549
return ret;
5650
}

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

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -464,114 +464,6 @@ void userspace(struct uml_pt_regs *regs, unsigned long *aux_fp_regs)
464464
}
465465
}
466466

467-
static unsigned long thread_regs[MAX_REG_NR];
468-
static unsigned long thread_fp_regs[FP_SIZE];
469-
470-
static int __init init_thread_regs(void)
471-
{
472-
get_safe_registers(thread_regs, thread_fp_regs);
473-
/* Set parent's instruction pointer to start of clone-stub */
474-
thread_regs[REGS_IP_INDEX] = STUB_CODE +
475-
(unsigned long) stub_clone_handler -
476-
(unsigned long) __syscall_stub_start;
477-
478-
/* syscall data as a temporary stack area (top half). */
479-
thread_regs[REGS_SP_INDEX] = STUB_DATA +
480-
offsetof(struct stub_data, syscall_data) +
481-
sizeof(((struct stub_data *) 0)->syscall_data) -
482-
sizeof(void *);
483-
return 0;
484-
}
485-
486-
__initcall(init_thread_regs);
487-
488-
int copy_context_skas0(unsigned long new_stack, int pid)
489-
{
490-
int err;
491-
unsigned long current_stack = current_stub_stack();
492-
struct stub_data *data = (struct stub_data *) current_stack;
493-
struct stub_data *child_data = (struct stub_data *) new_stack;
494-
unsigned long long new_offset;
495-
int new_fd = phys_mapping(uml_to_phys((void *)new_stack), &new_offset);
496-
497-
/*
498-
* prepare offset and fd of child's stack as argument for parent's
499-
* and child's mmap2 calls
500-
*/
501-
*data = ((struct stub_data) {
502-
.offset = MMAP_OFFSET(new_offset),
503-
.fd = new_fd,
504-
.err = -ESRCH,
505-
.child_err = 0,
506-
});
507-
508-
*child_data = ((struct stub_data) {
509-
.child_err = -ESRCH,
510-
});
511-
512-
err = ptrace_setregs(pid, thread_regs);
513-
if (err < 0) {
514-
err = -errno;
515-
printk(UM_KERN_ERR "%s : PTRACE_SETREGS failed, pid = %d, errno = %d\n",
516-
__func__, pid, -err);
517-
return err;
518-
}
519-
520-
err = put_fp_registers(pid, thread_fp_regs);
521-
if (err < 0) {
522-
printk(UM_KERN_ERR "%s : put_fp_registers failed, pid = %d, err = %d\n",
523-
__func__, pid, err);
524-
return err;
525-
}
526-
527-
/*
528-
* Wait, until parent has finished its work: read child's pid from
529-
* parent's stack, and check, if bad result.
530-
*/
531-
err = ptrace(PTRACE_CONT, pid, 0, 0);
532-
if (err) {
533-
err = -errno;
534-
printk(UM_KERN_ERR "Failed to continue new process, pid = %d, errno = %d\n",
535-
pid, errno);
536-
return err;
537-
}
538-
539-
wait_stub_done(pid);
540-
541-
pid = data->err;
542-
if (pid < 0) {
543-
printk(UM_KERN_ERR "%s - stub-parent reports error %d\n",
544-
__func__, -pid);
545-
return pid;
546-
}
547-
548-
/*
549-
* Wait, until child has finished too: read child's result from
550-
* child's stack and check it.
551-
*/
552-
wait_stub_done(pid);
553-
if (child_data->child_err != STUB_DATA) {
554-
printk(UM_KERN_ERR "%s - stub-child %d reports error %ld\n",
555-
__func__, pid, data->child_err);
556-
err = data->child_err;
557-
goto out_kill;
558-
}
559-
560-
if (ptrace(PTRACE_SETOPTIONS, pid, NULL,
561-
(void *)PTRACE_O_TRACESYSGOOD) < 0) {
562-
err = -errno;
563-
printk(UM_KERN_ERR "%s : PTRACE_SETOPTIONS failed, errno = %d\n",
564-
__func__, errno);
565-
goto out_kill;
566-
}
567-
568-
return pid;
569-
570-
out_kill:
571-
os_kill_ptraced_process(pid, 1);
572-
return err;
573-
}
574-
575467
void new_thread(void *stack, jmp_buf *buf, void (*handler)(void))
576468
{
577469
(*buf)[0].JB_IP = (unsigned long) handler;

arch/x86/um/shared/sysdep/stub.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@
1313

1414
extern void stub_segv_handler(int, siginfo_t *, void *);
1515
extern void stub_syscall_handler(void);
16-
extern void stub_clone_handler(void);

arch/x86/um/shared/sysdep/stub_32.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -107,30 +107,6 @@ static __always_inline void trap_myself(void)
107107
__asm("int3");
108108
}
109109

110-
static __always_inline void remap_stack_and_trap(void)
111-
{
112-
__asm__ volatile (
113-
"movl %%esp,%%ebx ;"
114-
"andl %0,%%ebx ;"
115-
"movl %1,%%eax ;"
116-
"movl %%ebx,%%edi ; addl %2,%%edi ; movl (%%edi),%%edi ;"
117-
"movl %%ebx,%%ebp ; addl %3,%%ebp ; movl (%%ebp),%%ebp ;"
118-
"int $0x80 ;"
119-
"addl %4,%%ebx ; movl %%eax, (%%ebx) ;"
120-
"int $3"
121-
: :
122-
"g" (~(STUB_DATA_PAGES * UM_KERN_PAGE_SIZE - 1)),
123-
"g" (STUB_MMAP_NR),
124-
"g" (offsetof(struct stub_data, fd)),
125-
"g" (offsetof(struct stub_data, offset)),
126-
"g" (offsetof(struct stub_data, child_err)),
127-
"c" (STUB_DATA_PAGES * UM_KERN_PAGE_SIZE),
128-
"d" (PROT_READ | PROT_WRITE),
129-
"S" (MAP_FIXED | MAP_SHARED)
130-
:
131-
"memory");
132-
}
133-
134110
static __always_inline void *get_stub_data(void)
135111
{
136112
unsigned long ret;

arch/x86/um/shared/sysdep/stub_64.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -101,32 +101,6 @@ static __always_inline void trap_myself(void)
101101
__asm("int3");
102102
}
103103

104-
static __always_inline void remap_stack_and_trap(void)
105-
{
106-
__asm__ volatile (
107-
"movq %0,%%rax ;"
108-
"movq %%rsp,%%rdi ;"
109-
"andq %1,%%rdi ;"
110-
"movq %2,%%r10 ;"
111-
"movq %%rdi,%%r8 ; addq %3,%%r8 ; movq (%%r8),%%r8 ;"
112-
"movq %%rdi,%%r9 ; addq %4,%%r9 ; movq (%%r9),%%r9 ;"
113-
__syscall ";"
114-
"movq %%rsp,%%rdi ; andq %1,%%rdi ;"
115-
"addq %5,%%rdi ; movq %%rax, (%%rdi) ;"
116-
"int3"
117-
: :
118-
"g" (STUB_MMAP_NR),
119-
"g" (~(STUB_DATA_PAGES * UM_KERN_PAGE_SIZE - 1)),
120-
"g" (MAP_FIXED | MAP_SHARED),
121-
"g" (offsetof(struct stub_data, fd)),
122-
"g" (offsetof(struct stub_data, offset)),
123-
"g" (offsetof(struct stub_data, child_err)),
124-
"S" (STUB_DATA_PAGES * UM_KERN_PAGE_SIZE),
125-
"d" (PROT_READ | PROT_WRITE)
126-
:
127-
__syscall_clobber, "r10", "r8", "r9");
128-
}
129-
130104
static __always_inline void *get_stub_data(void)
131105
{
132106
unsigned long ret;

0 commit comments

Comments
 (0)