Skip to content

Commit eb35bdd

Browse files
committed
arm64: flush TLS registers during exec
Nathan reports that we leak TLS information from the parent context during an exec, as we don't clear the TLS registers when flushing the thread state. This patch updates the flushing code so that we: (1) Unconditionally zero the tpidr_el0 register (since this is fully context switched for native tasks and zeroed for compat tasks) (2) Zero the tp_value state in thread_info before clearing the tpidrr0_el0 register for compat tasks (since this is only writable by the set_tls compat syscall and therefore not fully switched). A missing compiler barrier is also added to the compat set_tls syscall. Cc: <stable@vger.kernel.org> Acked-by: Nathan Lynch <Nathan_Lynch@mentor.com> Reported-by: Nathan Lynch <Nathan_Lynch@mentor.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent 3d8afe3 commit eb35bdd

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎arch/arm64/kernel/process.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,27 @@ void exit_thread(void)
230230
{
231231
}
232232

233+
static void tls_thread_flush(void)
234+
{
235+
asm ("msr tpidr_el0, xzr");
236+
237+
if (is_compat_task()) {
238+
current->thread.tp_value = 0;
239+
240+
/*
241+
* We need to ensure ordering between the shadow state and the
242+
* hardware state, so that we don't corrupt the hardware state
243+
* with a stale shadow state during context switch.
244+
*/
245+
barrier();
246+
asm ("msr tpidrro_el0, xzr");
247+
}
248+
}
249+
233250
void flush_thread(void)
234251
{
235252
fpsimd_flush_thread();
253+
tls_thread_flush();
236254
flush_ptrace_hw_breakpoint(current);
237255
}
238256

‎arch/arm64/kernel/sys_compat.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ long compat_arm_syscall(struct pt_regs *regs)
7979

8080
case __ARM_NR_compat_set_tls:
8181
current->thread.tp_value = regs->regs[0];
82+
83+
/*
84+
* Protect against register corruption from context switch.
85+
* See comment in tls_thread_flush.
86+
*/
87+
barrier();
8288
asm ("msr tpidrro_el0, %0" : : "r" (regs->regs[0]));
8389
return 0;
8490

0 commit comments

Comments
 (0)