Commit f60a83df authored by Chang S. Bae's avatar Chang S. Bae Committed by Thomas Gleixner

x86/process/64: Use FSGSBASE instructions on thread copy and ptrace

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: default avatarAndy Lutomirski <luto@kernel.org>
Signed-off-by: default avatarChang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: "H . Peter Anvin" <hpa@zytor.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ravi Shankar <ravi.v.shankar@intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Link: https://lkml.kernel.org/r/1557309753-24073-9-git-send-email-chang.seok.bae@intel.com
parent 1ab5f3f7
...@@ -245,13 +245,17 @@ static __always_inline void save_fsgs(struct task_struct *task) ...@@ -245,13 +245,17 @@ static __always_inline void save_fsgs(struct task_struct *task)
savesegment(fs, task->thread.fsindex); savesegment(fs, task->thread.fsindex);
savesegment(gs, task->thread.gsindex); savesegment(gs, task->thread.gsindex);
if (static_cpu_has(X86_FEATURE_FSGSBASE)) { if (static_cpu_has(X86_FEATURE_FSGSBASE)) {
unsigned long flags;
/* /*
* If FSGSBASE is enabled, we can't make any useful guesses * If FSGSBASE is enabled, we can't make any useful guesses
* about the base, and user code expects us to save the current * about the base, and user code expects us to save the current
* value. Fortunately, reading the base directly is efficient. * value. Fortunately, reading the base directly is efficient.
*/ */
task->thread.fsbase = rdfsbase(); task->thread.fsbase = rdfsbase();
local_irq_save(flags);
task->thread.gsbase = __rdgsbase_inactive(); task->thread.gsbase = __rdgsbase_inactive();
local_irq_restore(flags);
} else { } else {
save_base_legacy(task, task->thread.fsindex, FS); save_base_legacy(task, task->thread.fsindex, FS);
save_base_legacy(task, task->thread.gsindex, GS); save_base_legacy(task, task->thread.gsindex, GS);
...@@ -433,7 +437,8 @@ unsigned long x86_fsbase_read_task(struct task_struct *task) ...@@ -433,7 +437,8 @@ unsigned long x86_fsbase_read_task(struct task_struct *task)
if (task == current) if (task == current)
fsbase = x86_fsbase_read_cpu(); 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; fsbase = task->thread.fsbase;
else else
fsbase = x86_fsgsbase_read_task(task, task->thread.fsindex); fsbase = x86_fsgsbase_read_task(task, task->thread.fsindex);
...@@ -447,7 +452,8 @@ unsigned long x86_gsbase_read_task(struct task_struct *task) ...@@ -447,7 +452,8 @@ unsigned long x86_gsbase_read_task(struct task_struct *task)
if (task == current) if (task == current)
gsbase = x86_gsbase_read_cpu_inactive(); 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; gsbase = task->thread.gsbase;
else else
gsbase = x86_fsgsbase_read_task(task, task->thread.gsindex); gsbase = x86_fsgsbase_read_task(task, task->thread.gsindex);
...@@ -487,10 +493,11 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long sp, ...@@ -487,10 +493,11 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long sp,
p->thread.sp = (unsigned long) fork_frame; p->thread.sp = (unsigned long) fork_frame;
p->thread.io_bitmap_ptr = NULL; p->thread.io_bitmap_ptr = NULL;
savesegment(gs, p->thread.gsindex); save_fsgs(me);
p->thread.gsbase = p->thread.gsindex ? 0 : me->thread.gsbase; p->thread.fsindex = me->thread.fsindex;
savesegment(fs, p->thread.fsindex); p->thread.fsbase = me->thread.fsbase;
p->thread.fsbase = p->thread.fsindex ? 0 : me->thread.fsbase; p->thread.gsindex = me->thread.gsindex;
p->thread.gsbase = me->thread.gsbase;
savesegment(es, p->thread.es); savesegment(es, p->thread.es);
savesegment(ds, p->thread.ds); savesegment(ds, p->thread.ds);
memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps)); memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment