Skip to content

Commit 41bdc78

Browse files
amlutoingomolnar
authored andcommitted
x86/tls: Validate TLS entries to protect espfix
Installing a 16-bit RW data segment into the GDT defeats espfix. AFAICT this will not affect glibc, Wine, or dosemu at all. Signed-off-by: Andy Lutomirski <luto@amacapital.net> Acked-by: H. Peter Anvin <hpa@zytor.com> Cc: stable@vger.kernel.org Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: security@kernel.org <security@kernel.org> Cc: Willy Tarreau <w@1wt.eu> Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent f0905c5 commit 41bdc78

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎arch/x86/kernel/tls.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ static int get_free_idx(void)
2727
return -ESRCH;
2828
}
2929

30+
static bool tls_desc_okay(const struct user_desc *info)
31+
{
32+
if (LDT_empty(info))
33+
return true;
34+
35+
/*
36+
* espfix is required for 16-bit data segments, but espfix
37+
* only works for LDT segments.
38+
*/
39+
if (!info->seg_32bit)
40+
return false;
41+
42+
return true;
43+
}
44+
3045
static void set_tls_desc(struct task_struct *p, int idx,
3146
const struct user_desc *info, int n)
3247
{
@@ -66,6 +81,9 @@ int do_set_thread_area(struct task_struct *p, int idx,
6681
if (copy_from_user(&info, u_info, sizeof(info)))
6782
return -EFAULT;
6883

84+
if (!tls_desc_okay(&info))
85+
return -EINVAL;
86+
6987
if (idx == -1)
7088
idx = info.entry_number;
7189

@@ -192,6 +210,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
192210
{
193211
struct user_desc infobuf[GDT_ENTRY_TLS_ENTRIES];
194212
const struct user_desc *info;
213+
int i;
195214

196215
if (pos >= GDT_ENTRY_TLS_ENTRIES * sizeof(struct user_desc) ||
197216
(pos % sizeof(struct user_desc)) != 0 ||
@@ -205,6 +224,10 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
205224
else
206225
info = infobuf;
207226

227+
for (i = 0; i < count / sizeof(struct user_desc); i++)
228+
if (!tls_desc_okay(info + i))
229+
return -EINVAL;
230+
208231
set_tls_desc(target,
209232
GDT_ENTRY_TLS_MIN + (pos / sizeof(struct user_desc)),
210233
info, count / sizeof(struct user_desc));

0 commit comments

Comments
 (0)