Skip to content

Commit 20ecc91

Browse files
author
Al Viro
committed
m68k: sanitize copy_thread(), fork/vfork/clone wrappers, switch to generic fork/vfork
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent dfe09ae commit 20ecc91

4 files changed

Lines changed: 46 additions & 71 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#define __ARCH_WANT_SYS_RT_SIGACTION
3333
#define __ARCH_WANT_SYS_RT_SIGSUSPEND
3434
#define __ARCH_WANT_SYS_EXECVE
35+
#define __ARCH_WANT_SYS_FORK
36+
#define __ARCH_WANT_SYS_VFORK
3537

3638
/*
3739
* "Conditional" syscalls

‎arch/m68k/kernel/entry.S‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,29 @@
4444

4545
.globl system_call, buserr, trap, resume
4646
.globl sys_call_table
47-
.globl sys_fork, sys_clone, sys_vfork
47+
.globl __sys_fork, __sys_clone, __sys_vfork
4848
.globl ret_from_interrupt, bad_interrupt
4949
.globl auto_irqhandler_fixup
5050
.globl user_irqvec_fixup
5151

5252
.text
53-
ENTRY(sys_fork)
53+
ENTRY(__sys_fork)
5454
SAVE_SWITCH_STACK
55-
pea %sp@(SWITCH_STACK_SIZE)
56-
jbsr m68k_fork
57-
addql #4,%sp
58-
RESTORE_SWITCH_STACK
55+
jbsr sys_fork
56+
lea %sp@(24),%sp
5957
rts
6058

61-
ENTRY(sys_clone)
59+
ENTRY(__sys_clone)
6260
SAVE_SWITCH_STACK
6361
pea %sp@(SWITCH_STACK_SIZE)
6462
jbsr m68k_clone
65-
addql #4,%sp
66-
RESTORE_SWITCH_STACK
63+
lea %sp@(28),%sp
6764
rts
6865

69-
ENTRY(sys_vfork)
66+
ENTRY(__sys_vfork)
7067
SAVE_SWITCH_STACK
71-
pea %sp@(SWITCH_STACK_SIZE)
72-
jbsr m68k_vfork
73-
addql #4,%sp
74-
RESTORE_SWITCH_STACK
68+
jbsr sys_vfork
69+
lea %sp@(24),%sp
7570
rts
7671

7772
ENTRY(sys_sigreturn)

‎arch/m68k/kernel/process.c‎

Lines changed: 32 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -136,83 +136,61 @@ void flush_thread(void)
136136
}
137137

138138
/*
139-
* "m68k_fork()".. By the time we get here, the
140-
* non-volatile registers have also been saved on the
141-
* stack. We do some ugly pointer stuff here.. (see
142-
* also copy_thread)
139+
* Why not generic sys_clone, you ask? m68k passes all arguments on stack.
140+
* And we need all registers saved, which means a bunch of stuff pushed
141+
* on top of pt_regs, which means that sys_clone() arguments would be
142+
* buried. We could, of course, copy them, but it's too costly for no
143+
* good reason - generic clone() would have to copy them *again* for
144+
* do_fork() anyway. So in this case it's actually better to pass pt_regs *
145+
* and extract arguments for do_fork() from there. Eventually we might
146+
* go for calling do_fork() directly from the wrapper, but only after we
147+
* are finished with do_fork() prototype conversion.
143148
*/
144-
145-
asmlinkage int m68k_fork(struct pt_regs *regs)
146-
{
147-
#ifdef CONFIG_MMU
148-
return do_fork(SIGCHLD, rdusp(), regs, 0, NULL, NULL);
149-
#else
150-
return -EINVAL;
151-
#endif
152-
}
153-
154-
asmlinkage int m68k_vfork(struct pt_regs *regs)
155-
{
156-
return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, rdusp(), regs, 0,
157-
NULL, NULL);
158-
}
159-
160149
asmlinkage int m68k_clone(struct pt_regs *regs)
161150
{
162-
unsigned long clone_flags;
163-
unsigned long newsp;
164-
int __user *parent_tidptr, *child_tidptr;
165-
166-
/* syscall2 puts clone_flags in d1 and usp in d2 */
167-
clone_flags = regs->d1;
168-
newsp = regs->d2;
169-
parent_tidptr = (int __user *)regs->d3;
170-
child_tidptr = (int __user *)regs->d4;
171-
if (!newsp)
172-
newsp = rdusp();
173-
return do_fork(clone_flags, newsp, regs, 0,
174-
parent_tidptr, child_tidptr);
151+
/* regs will be equal to current_pt_regs() */
152+
return do_fork(regs->d1, regs->d2, regs, 0,
153+
(int __user *)regs->d3, (int __user *)regs->d4);
175154
}
176155

177156
int copy_thread(unsigned long clone_flags, unsigned long usp,
178157
unsigned long arg,
179-
struct task_struct * p, struct pt_regs * regs)
158+
struct task_struct * p, struct pt_regs * unused)
180159
{
181-
struct pt_regs * childregs;
182-
struct switch_stack *childstack;
160+
struct fork_frame {
161+
struct switch_stack sw;
162+
struct pt_regs regs;
163+
} *frame;
183164

184-
childregs = (struct pt_regs *) (task_stack_page(p) + THREAD_SIZE) - 1;
185-
childstack = ((struct switch_stack *) childregs) - 1;
165+
frame = (struct fork_frame *) (task_stack_page(p) + THREAD_SIZE) - 1;
186166

187-
p->thread.usp = usp;
188-
p->thread.ksp = (unsigned long)childstack;
189-
p->thread.esp0 = (unsigned long)childregs;
167+
p->thread.ksp = (unsigned long)frame;
168+
p->thread.esp0 = (unsigned long)&frame->regs;
190169

191170
/*
192171
* Must save the current SFC/DFC value, NOT the value when
193172
* the parent was last descheduled - RGH 10-08-96
194173
*/
195174
p->thread.fs = get_fs().seg;
196175

197-
if (unlikely(!regs)) {
176+
if (unlikely(p->flags & PF_KTHREAD)) {
198177
/* kernel thread */
199-
memset(childstack, 0,
200-
sizeof(struct switch_stack) + sizeof(struct pt_regs));
201-
childregs->sr = PS_S;
202-
childstack->a3 = usp; /* function */
203-
childstack->d7 = arg;
204-
childstack->retpc = (unsigned long)ret_from_kernel_thread;
178+
memset(frame, 0, sizeof(struct fork_frame));
179+
frame->regs.sr = PS_S;
180+
frame->sw.a3 = usp; /* function */
181+
frame->sw.d7 = arg;
182+
frame->sw.retpc = (unsigned long)ret_from_kernel_thread;
205183
p->thread.usp = 0;
206184
return 0;
207185
}
208-
*childregs = *regs;
209-
childregs->d0 = 0;
210-
211-
*childstack = ((struct switch_stack *) regs)[-1];
212-
childstack->retpc = (unsigned long)ret_from_fork;
186+
memcpy(frame, container_of(current_pt_regs(), struct fork_frame, regs),
187+
sizeof(struct fork_frame));
188+
frame->regs.d0 = 0;
189+
frame->sw.retpc = (unsigned long)ret_from_fork;
190+
p->thread.usp = usp ?: rdusp();
213191

214192
if (clone_flags & CLONE_SETTLS)
215-
task_thread_info(p)->tp_value = regs->d5;
193+
task_thread_info(p)->tp_value = frame->regs.d5;
216194

217195
#ifdef CONFIG_FPU
218196
if (!FPU_IS_EMU) {

‎arch/m68k/kernel/syscalltable.S‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ALIGN
2222
ENTRY(sys_call_table)
2323
.long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
2424
.long sys_exit
25-
.long sys_fork
25+
.long __sys_fork
2626
.long sys_read
2727
.long sys_write
2828
.long sys_open /* 5 */
@@ -140,7 +140,7 @@ ENTRY(sys_call_table)
140140
.long sys_ipc
141141
.long sys_fsync
142142
.long sys_sigreturn
143-
.long sys_clone /* 120 */
143+
.long __sys_clone /* 120 */
144144
.long sys_setdomainname
145145
.long sys_newuname
146146
.long sys_cacheflush /* modify_ldt for i386 */
@@ -210,7 +210,7 @@ ENTRY(sys_call_table)
210210
.long sys_sendfile
211211
.long sys_ni_syscall /* streams1 */
212212
.long sys_ni_syscall /* streams2 */
213-
.long sys_vfork /* 190 */
213+
.long __sys_vfork /* 190 */
214214
.long sys_getrlimit
215215
.long sys_mmap2
216216
.long sys_truncate64

0 commit comments

Comments
 (0)