Commit a5d2cfe7 authored by Benjamin Berg's avatar Benjamin Berg Committed by Johannes Berg
Browse files

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: default avatarBenjamin Berg <benjamin.berg@intel.com>
Link: https://patch.msgid.link/20240703134536.1161108-8-benjamin@sipsolutions.net


Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 7911b650
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -285,7 +285,6 @@ void protect(struct mm_id *mm_idp, unsigned long addr,
/* skas/process.c */
extern int is_skas_winch(int pid, int fd, void *data);
extern int start_userspace(unsigned long stub_stack);
extern int copy_context_skas0(unsigned long stack, int pid);
extern void userspace(struct uml_pt_regs *regs, unsigned long *aux_fp_regs);
extern void new_thread(void *stack, jmp_buf *buf, void (*handler)(void));
extern void switch_threads(jmp_buf *me, jmp_buf *you);
+0 −1
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ struct stub_syscall {

struct stub_data {
	unsigned long offset;
	int fd;
	long err, child_err;

	int syscall_data_len;
+3 −5
Original line number Diff line number Diff line
@@ -3,16 +3,14 @@
# Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
#

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

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

CFLAGS_clone.o := $(CFLAGS_NO_HARDENING)
CFLAGS_stub.o := $(CFLAGS_NO_HARDENING)
UNPROFILE_OBJS := clone.o stub.o

UNPROFILE_OBJS := stub.o
KCOV_INSTRUMENT := n

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

arch/um/kernel/skas/clone.c

deleted100644 → 0
+0 −50
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) 2015 Thomas Meyer (thomas@m3y3r.de)
 * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
 */

#include <signal.h>
#include <sched.h>
#include <asm/unistd.h>
#include <sys/time.h>
#include <as-layout.h>
#include <ptrace_user.h>
#include <stub-data.h>
#include <sysdep/stub.h>

/*
 * This is in a separate file because it needs to be compiled with any
 * extraneous gcc flags (-pg, -fprofile-arcs, -ftest-coverage) disabled
 *
 * Use UM_KERN_PAGE_SIZE instead of PAGE_SIZE because that calls getpagesize
 * on some systems.
 */

void __attribute__ ((__section__ (".__syscall_stub")))
stub_clone_handler(void)
{
	struct stub_data *data = get_stub_data();
	long err;

	/* syscall data as a temporary stack area (bottom half). */
	err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD,
			    (unsigned long) data->syscall_data +
					    sizeof(data->syscall_data) / 2 -
					    sizeof(void *));
	if (err) {
		data->err = err;
		goto done;
	}

	err = stub_syscall4(__NR_ptrace, PTRACE_TRACEME, 0, 0, 0);
	if (err) {
		data->child_err = err;
		goto done;
	}

	remap_stack_and_trap();

 done:
	trap_myself();
}
+7 −13
Original line number Diff line number Diff line
@@ -21,8 +21,7 @@ static_assert(sizeof(struct stub_data) == STUB_DATA_PAGES * UM_KERN_PAGE_SIZE);

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

@@ -30,27 +29,22 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm)
	if (stack == 0)
		goto out;

	to_mm->id.stack = stack;
	if (current->mm != NULL && current->mm != &init_mm)
		from_mm = &current->mm->context;
	new_id->stack = stack;

	block_signals_trace();
	if (from_mm)
		to_mm->id.u.pid = copy_context_skas0(stack,
						     from_mm->id.u.pid);
	else to_mm->id.u.pid = start_userspace(stack);
	new_id->u.pid = start_userspace(stack);
	unblock_signals_trace();

	if (to_mm->id.u.pid < 0) {
		ret = to_mm->id.u.pid;
	if (new_id->u.pid < 0) {
		ret = new_id->u.pid;
		goto out_free;
	}

	return 0;

 out_free:
	if (to_mm->id.stack != 0)
		free_pages(to_mm->id.stack, ilog2(STUB_DATA_PAGES));
	if (new_id->stack != 0)
		free_pages(new_id->stack, ilog2(STUB_DATA_PAGES));
 out:
	return ret;
}
Loading