lkml.org 
[lkml]   [2018]   [Apr]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH AUTOSEL for 4.9 120/293] arm64: ptrace: Flush user-RW TLS reg to thread_struct before reading
    Date
    From: Dave Martin <Dave.Martin@arm.com>

    [ Upstream commit 936eb65ca22ad856cb3a995e8cd742e982dc2dd0 ]

    When reading current's user-writable TLS register (which occurs
    when dumping core for native tasks), it is possible that userspace
    has modified it since the time the task was last scheduled out.
    The new TLS register value is not guaranteed to have been written
    immediately back to thread_struct in this case.

    As a result, a coredump can capture stale data for this register.
    Reading the register for a stopped task via ptrace is unaffected.

    For native tasks, this patch explicitly flushes the TPIDR_EL0
    register back to thread_struct before dumping when operating on
    current, thus ensuring that coredump contents are up to date. For
    compat tasks, the TLS register is not user-writable and so cannot
    be out of sync, so no flush is required in compat_tls_get().

    Signed-off-by: Dave Martin <Dave.Martin@arm.com>
    Signed-off-by: Will Deacon <will.deacon@arm.com>
    Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
    ---
    arch/arm64/include/asm/processor.h | 3 +++
    arch/arm64/kernel/process.c | 8 ++++++--
    arch/arm64/kernel/ptrace.c | 4 ++++
    3 files changed, 13 insertions(+), 2 deletions(-)

    diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h
    index 60e34824e18c..b3ac6e5a70b9 100644
    --- a/arch/arm64/include/asm/processor.h
    +++ b/arch/arm64/include/asm/processor.h
    @@ -102,6 +102,9 @@ struct thread_struct {
    #define task_user_tls(t) (&(t)->thread.tp_value)
    #endif

    +/* Sync TPIDR_EL0 back to thread_struct for current */
    +void tls_preserve_current_state(void);
    +
    #define INIT_THREAD { }

    static inline void start_thread_common(struct pt_regs *regs, unsigned long pc)
    diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c
    index 0e7394915c70..90e2823e5081 100644
    --- a/arch/arm64/kernel/process.c
    +++ b/arch/arm64/kernel/process.c
    @@ -304,12 +304,16 @@ int copy_thread(unsigned long clone_flags, unsigned long stack_start,
    return 0;
    }

    +void tls_preserve_current_state(void)
    +{
    + *task_user_tls(current) = read_sysreg(tpidr_el0);
    +}
    +
    static void tls_thread_switch(struct task_struct *next)
    {
    unsigned long tpidr, tpidrro;

    - tpidr = read_sysreg(tpidr_el0);
    - *task_user_tls(current) = tpidr;
    + tls_preserve_current_state();

    tpidr = *task_user_tls(next);
    tpidrro = is_compat_thread(task_thread_info(next)) ?
    diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
    index 8eedeef375d6..d1fd560b3a2a 100644
    --- a/arch/arm64/kernel/ptrace.c
    +++ b/arch/arm64/kernel/ptrace.c
    @@ -646,6 +646,10 @@ static int tls_get(struct task_struct *target, const struct user_regset *regset,
    void *kbuf, void __user *ubuf)
    {
    unsigned long *tls = &target->thread.tp_value;
    +
    + if (target == current)
    + tls_preserve_current_state();
    +
    return user_regset_copyout(&pos, &count, &kbuf, &ubuf, tls, 0, -1);
    }

    --
    2.15.1
    \
     
     \ /
      Last update: 2018-04-09 04:21    [W:2.230 / U:0.040 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site