Skip to content

Commit 993773d

Browse files
Dianzhang ChenKAGA-KOKO
authored andcommitted
x86/tls: Fix possible spectre-v1 in do_get_thread_area()
The index to access the threads tls array is controlled by userspace via syscall: sys_ptrace(), hence leading to a potential exploitation of the Spectre variant 1 vulnerability. The index can be controlled from: ptrace -> arch_ptrace -> do_get_thread_area. Fix this by sanitizing the user supplied index before using it to access the p->thread.tls_array. Signed-off-by: Dianzhang Chen <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 31a2fbb commit 993773d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

arch/x86/kernel/tls.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/user.h>
66
#include <linux/regset.h>
77
#include <linux/syscalls.h>
8+
#include <linux/nospec.h>
89

910
#include <linux/uaccess.h>
1011
#include <asm/desc.h>
@@ -220,15 +221,19 @@ int do_get_thread_area(struct task_struct *p, int idx,
220221
struct user_desc __user *u_info)
221222
{
222223
struct user_desc info;
224+
int index;
223225

224226
if (idx == -1 && get_user(idx, &u_info->entry_number))
225227
return -EFAULT;
226228

227229
if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
228230
return -EINVAL;
229231

230-
fill_user_desc(&info, idx,
231-
&p->thread.tls_array[idx - GDT_ENTRY_TLS_MIN]);
232+
index = idx - GDT_ENTRY_TLS_MIN;
233+
index = array_index_nospec(index,
234+
GDT_ENTRY_TLS_MAX - GDT_ENTRY_TLS_MIN + 1);
235+
236+
fill_user_desc(&info, idx, &p->thread.tls_array[index]);
232237

233238
if (copy_to_user(u_info, &info, sizeof(info)))
234239
return -EFAULT;

0 commit comments

Comments
 (0)