]> git.baikalelectronics.ru Git - kernel.git/commitdiff
x86/process/64: Use FSGSBASE instructions on thread copy and ptrace
authorChang S. Bae <chang.seok.bae@intel.com>
Thu, 28 May 2020 20:13:53 +0000 (16:13 -0400)
committerThomas Gleixner <tglx@linutronix.de>
Thu, 18 Jun 2020 13:47:02 +0000 (15:47 +0200)
When FSGSBASE is enabled, copying threads and reading fsbase and gsbase
using ptrace must read the actual values.

When copying a thread, use save_fsgs() and copy the saved values.  For
ptrace, the bases must be read from memory regardless of the selector if
FSGSBASE is enabled.

[ tglx: Invoke __rdgsbase_inactive() with interrupts disabled ]
[ luto: Massage changelog ]

Suggested-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/1557309753-24073-9-git-send-email-chang.seok.bae@intel.com
Link: https://lkml.kernel.org/r/20200528201402.1708239-8-sashal@kernel.org
arch/x86/kernel/process.c
arch/x86/kernel/process_64.c

index f362ce0d5ac0f621b901c6d728445efe7f66c107..216c88df191978e7a418bea167ad24d2334cc48f 100644 (file)
@@ -140,10 +140,12 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long sp,
        memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
 
 #ifdef CONFIG_X86_64
-       savesegment(gs, p->thread.gsindex);
-       p->thread.gsbase = p->thread.gsindex ? 0 : current->thread.gsbase;
-       savesegment(fs, p->thread.fsindex);
-       p->thread.fsbase = p->thread.fsindex ? 0 : current->thread.fsbase;
+       current_save_fsgs();
+       p->thread.fsindex = current->thread.fsindex;
+       p->thread.fsbase = current->thread.fsbase;
+       p->thread.gsindex = current->thread.gsindex;
+       p->thread.gsbase = current->thread.gsbase;
+
        savesegment(es, p->thread.es);
        savesegment(ds, p->thread.ds);
 #else
index 8ccc587c311b2984a82bcde7035fdfb5d3a482a5..d618969cea6637df0c48030bb8c43c7ae62d1db1 100644 (file)
@@ -426,7 +426,8 @@ unsigned long x86_fsbase_read_task(struct task_struct *task)
 
        if (task == current)
                fsbase = x86_fsbase_read_cpu();
-       else if (task->thread.fsindex == 0)
+       else if (static_cpu_has(X86_FEATURE_FSGSBASE) ||
+                (task->thread.fsindex == 0))
                fsbase = task->thread.fsbase;
        else
                fsbase = x86_fsgsbase_read_task(task, task->thread.fsindex);
@@ -440,7 +441,8 @@ unsigned long x86_gsbase_read_task(struct task_struct *task)
 
        if (task == current)
                gsbase = x86_gsbase_read_cpu_inactive();
-       else if (task->thread.gsindex == 0)
+       else if (static_cpu_has(X86_FEATURE_FSGSBASE) ||
+                (task->thread.gsindex == 0))
                gsbase = task->thread.gsbase;
        else
                gsbase = x86_fsgsbase_read_task(task, task->thread.gsindex);