Skip to content

Commit 16dd46b

Browse files
committed
arm64: No need to set the x0-x2 registers in start_thread()
For historical reasons, ARM used to set r0-r2 in start_thread() to the first values on the user stack when starting a new user application. The same logic has been inherited in AArch64. The x0 register is overridden by the sys_execve() return value so it's always zero on success. The x1 and x2 registers are ignored by AArch64 and EABI AArch32 applications, so we can safely remove the register setting for both native and compat user space. This also fixes a potential fault with the kernel accessing user space stack directly. Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> Reported-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent f71a1a4 commit 16dd46b

File tree

1 file changed

+0
-10
lines changed

1 file changed

+0
-10
lines changed

arch/arm64/include/asm/processor.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,30 +92,20 @@ static inline void start_thread_common(struct pt_regs *regs, unsigned long pc)
9292
static inline void start_thread(struct pt_regs *regs, unsigned long pc,
9393
unsigned long sp)
9494
{
95-
unsigned long *stack = (unsigned long *)sp;
96-
9795
start_thread_common(regs, pc);
9896
regs->pstate = PSR_MODE_EL0t;
9997
regs->sp = sp;
100-
regs->regs[2] = stack[2]; /* x2 (envp) */
101-
regs->regs[1] = stack[1]; /* x1 (argv) */
102-
regs->regs[0] = stack[0]; /* x0 (argc) */
10398
}
10499

105100
#ifdef CONFIG_COMPAT
106101
static inline void compat_start_thread(struct pt_regs *regs, unsigned long pc,
107102
unsigned long sp)
108103
{
109-
unsigned int *stack = (unsigned int *)sp;
110-
111104
start_thread_common(regs, pc);
112105
regs->pstate = COMPAT_PSR_MODE_USR;
113106
if (pc & 1)
114107
regs->pstate |= COMPAT_PSR_T_BIT;
115108
regs->compat_sp = sp;
116-
regs->regs[2] = stack[2]; /* x2 (envp) */
117-
regs->regs[1] = stack[1]; /* x1 (argv) */
118-
regs->regs[0] = stack[0]; /* x0 (argc) */
119109
}
120110
#endif
121111

0 commit comments

Comments
 (0)