Skip to content

Commit 9ac0800

Browse files
author
Al Viro
committed
arm64: sanitize copy_thread(), switch to generic fork/vfork/clone
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent b9763ce commit 9ac0800

7 files changed

Lines changed: 12 additions & 28 deletions

File tree

‎arch/arm64/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ config ARM64
3333
select RTC_LIB
3434
select SPARSE_IRQ
3535
select SYSCTL_EXCEPTION_TRACE
36+
select CLONE_BACKWARDS
3637
help
3738
ARM 64-bit (AArch64) Linux support.
3839

‎arch/arm64/include/asm/syscalls.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ asmlinkage long sys_sigaltstack_wrapper(const stack_t __user *uss,
3131
* AArch64 sys_clone implementation has a different prototype than the generic
3232
* one (additional TLS value argument).
3333
*/
34+
asmlinkage long sys_clone(unsigned long, unsigned long, void __user *, int,
35+
void __user *);
3436
#define sys_clone sys_clone
3537

3638
#include <asm-generic/syscalls.h>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#define __ARCH_WANT_SYS_SIGPROCMASK
2525
#define __ARCH_WANT_COMPAT_SYS_RT_SIGSUSPEND
2626
#define __ARCH_WANT_COMPAT_SYS_SENDFILE
27+
#define __ARCH_WANT_SYS_FORK
28+
#define __ARCH_WANT_SYS_VFORK
2729
#endif
2830
#define __ARCH_WANT_SYS_EXECVE
31+
#define __ARCH_WANT_SYS_CLONE
2932
#include <uapi/asm/unistd.h>

‎arch/arm64/include/asm/unistd32.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
__SYSCALL(0, sys_restart_syscall)
2525
__SYSCALL(1, sys_exit)
26-
__SYSCALL(2, compat_sys_fork)
26+
__SYSCALL(2, sys_fork)
2727
__SYSCALL(3, sys_read)
2828
__SYSCALL(4, sys_write)
2929
__SYSCALL(5, compat_sys_open)
@@ -211,7 +211,7 @@ __SYSCALL(186, compat_sys_sigaltstack_wrapper)
211211
__SYSCALL(187, compat_sys_sendfile)
212212
__SYSCALL(188, sys_ni_syscall) /* 188 reserved */
213213
__SYSCALL(189, sys_ni_syscall) /* 189 reserved */
214-
__SYSCALL(190, compat_sys_vfork)
214+
__SYSCALL(190, sys_vfork)
215215
__SYSCALL(191, compat_sys_getrlimit) /* SuS compliant getrlimit */
216216
__SYSCALL(192, sys_mmap_pgoff)
217217
__SYSCALL(193, compat_sys_truncate64_wrapper)

‎arch/arm64/kernel/process.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,15 @@ asmlinkage void ret_from_fork(void) asm("ret_from_fork");
235235

236236
int copy_thread(unsigned long clone_flags, unsigned long stack_start,
237237
unsigned long stk_sz, struct task_struct *p,
238-
struct pt_regs *regs)
238+
struct pt_regs *unused)
239239
{
240240
struct pt_regs *childregs = task_pt_regs(p);
241241
unsigned long tls = p->thread.tp_value;
242242

243243
memset(&p->thread.cpu_context, 0, sizeof(struct cpu_context));
244244

245-
if (likely(regs)) {
246-
*childregs = *regs;
245+
if (likely(!(p->flags & PF_KTHREAD))) {
246+
*childregs = *current_pt_regs();
247247
childregs->regs[0] = 0;
248248
if (is_compat_thread(task_thread_info(p))) {
249249
if (stack_start)
@@ -266,7 +266,7 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start,
266266
* for the new thread.
267267
*/
268268
if (clone_flags & CLONE_SETTLS)
269-
tls = regs->regs[3];
269+
tls = childregs->regs[3];
270270
} else {
271271
memset(childregs, 0, sizeof(struct pt_regs));
272272
childregs->pstate = PSR_MODE_EL1h;

‎arch/arm64/kernel/sys.c‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,6 @@
2626
#include <linux/slab.h>
2727
#include <linux/syscalls.h>
2828

29-
/*
30-
* Clone a task - this clones the calling program thread.
31-
*/
32-
asmlinkage long sys_clone(unsigned long clone_flags, unsigned long newsp,
33-
int __user *parent_tidptr, unsigned long tls_val,
34-
int __user *child_tidptr)
35-
{
36-
return do_fork(clone_flags, newsp, current_pt_regs(), 0,
37-
parent_tidptr, child_tidptr);
38-
}
39-
4029
asmlinkage long sys_mmap(unsigned long addr, unsigned long len,
4130
unsigned long prot, unsigned long flags,
4231
unsigned long fd, off_t off)

‎arch/arm64/kernel/sys_compat.c‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,6 @@
2828
#include <asm/cacheflush.h>
2929
#include <asm/unistd32.h>
3030

31-
asmlinkage int compat_sys_fork(void)
32-
{
33-
return do_fork(SIGCHLD, 0, current_pt_regs(), 0, NULL, NULL);
34-
}
35-
36-
asmlinkage int compat_sys_vfork(void)
37-
{
38-
return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, 0,
39-
current_pt_regs(), 0, NULL, NULL);
40-
}
41-
4231
asmlinkage int compat_sys_sched_rr_get_interval(compat_pid_t pid,
4332
struct compat_timespec __user *interval)
4433
{

0 commit comments

Comments
 (0)