Skip to content

Commit dc26184

Browse files
benzeajmberg-intel
authored andcommitted
um: Create signal stack memory assignment in stub_data
When we switch to use seccomp, we need both the signal stack and other data (i.e. syscall information) to co-exist in the stub data. To facilitate this, start by defining separate memory areas for the stack and syscall data. This moves the signal stack onto a new page as the memory area is not sufficient to hold both signal stack and syscall information. Only change the signal stack setup for now, as the syscall code will be reworked later. Signed-off-by: Benjamin Berg <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Johannes Berg <[email protected]>
1 parent d1d3a2e commit dc26184

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

arch/um/include/shared/as-layout.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define STUB_START stub_start
2424
#define STUB_CODE STUB_START
2525
#define STUB_DATA (STUB_CODE + UM_KERN_PAGE_SIZE)
26-
#define STUB_DATA_PAGES 1 /* must be a power of two */
26+
#define STUB_DATA_PAGES 2 /* must be a power of two */
2727
#define STUB_END (STUB_DATA + STUB_DATA_PAGES * UM_KERN_PAGE_SIZE)
2828

2929
#ifndef __ASSEMBLY__

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,19 @@
88
#ifndef __STUB_DATA_H
99
#define __STUB_DATA_H
1010

11+
#include <linux/compiler_types.h>
12+
#include <as-layout.h>
13+
1114
struct stub_data {
1215
unsigned long offset;
1316
int fd;
1417
long parent_err, child_err;
18+
19+
/* 128 leaves enough room for additional fields in the struct */
20+
unsigned char syscall_data[UM_KERN_PAGE_SIZE - 128] __aligned(16);
21+
22+
/* Stack for our signal handlers and for calling into . */
23+
unsigned char sigstack[UM_KERN_PAGE_SIZE] __aligned(UM_KERN_PAGE_SIZE);
1524
};
1625

1726
#endif

arch/um/kernel/skas/clone.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ stub_clone_handler(void)
2727
struct stub_data *data = get_stub_data();
2828
long err;
2929

30+
/* syscall data as a temporary stack area (bottom half). */
3031
err = stub_syscall2(__NR_clone, CLONE_PARENT | CLONE_FILES | SIGCHLD,
31-
(unsigned long)data +
32-
STUB_DATA_PAGES * UM_KERN_PAGE_SIZE / 2);
32+
(unsigned long) data->syscall_data +
33+
sizeof(data->syscall_data) / 2 -
34+
sizeof(void *));
3335
if (err) {
3436
data->parent_err = err;
3537
goto done;

arch/um/kernel/skas/mmu.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#include <as-layout.h>
1515
#include <os.h>
1616
#include <skas.h>
17+
#include <stub-data.h>
18+
19+
/* Ensure the stub_data struct covers the allocated area */
20+
static_assert(sizeof(struct stub_data) == STUB_DATA_PAGES * UM_KERN_PAGE_SIZE);
1721

1822
int init_new_context(struct task_struct *task, struct mm_struct *mm)
1923
{

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,12 @@ static int __init init_thread_regs(void)
474474
thread_regs[REGS_IP_INDEX] = STUB_CODE +
475475
(unsigned long) stub_clone_handler -
476476
(unsigned long) __syscall_stub_start;
477-
thread_regs[REGS_SP_INDEX] = STUB_DATA + STUB_DATA_PAGES * UM_KERN_PAGE_SIZE -
478-
sizeof(void *);
479-
#ifdef __SIGNAL_FRAMESIZE
480-
thread_regs[REGS_SP_INDEX] -= __SIGNAL_FRAMESIZE;
481-
#endif
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 *);
482483
return 0;
483484
}
484485

0 commit comments

Comments
 (0)