aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2017-08-18 06:30:30 -0400
committerIngo Molnar <mingo@kernel.org>2017-08-29 05:55:15 -0400
commiteaa2f87c6b840b83827c40db6eb8481689570259 (patch)
tree93449daec7e592149122d621150d06cb79ef6baf
parent9c3a815f471a84811cf8021cf64aae3b8081dfde (diff)
x86/ldt: Fix off by one in get_segment_base()
ldt->entries[] is allocated in alloc_ldt_struct(). It has ldt->nr_entries elements and ldt->nr_entries is capped at LDT_ENTRIES. So if "idx" is == ldt->nr_entries then we're reading beyond the end of the buffer. It seems duplicative to have two limit checks when one would work just as well so I removed the check against LDT_ENTRIES. The gdt_page.gdt[] array has GDT_ENTRIES entries. Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Acked-by: Andy Lutomirski <luto@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: kernel-janitors@vger.kernel.org Fixes: d07bdfd322d3 ("perf/x86: Fix USER/KERNEL tagging of samples properly") Link: http://lkml.kernel.org/r/20170818102516.gqwm4xdvvuvjw5ho@mwanda Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/x86/events/core.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index af12e294caed..939050169d12 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -2335,12 +2335,9 @@ static unsigned long get_segment_base(unsigned int segment)
2335#ifdef CONFIG_MODIFY_LDT_SYSCALL 2335#ifdef CONFIG_MODIFY_LDT_SYSCALL
2336 struct ldt_struct *ldt; 2336 struct ldt_struct *ldt;
2337 2337
2338 if (idx > LDT_ENTRIES)
2339 return 0;
2340
2341 /* IRQs are off, so this synchronizes with smp_store_release */ 2338 /* IRQs are off, so this synchronizes with smp_store_release */
2342 ldt = lockless_dereference(current->active_mm->context.ldt); 2339 ldt = lockless_dereference(current->active_mm->context.ldt);
2343 if (!ldt || idx > ldt->nr_entries) 2340 if (!ldt || idx >= ldt->nr_entries)
2344 return 0; 2341 return 0;
2345 2342
2346 desc = &ldt->entries[idx]; 2343 desc = &ldt->entries[idx];
@@ -2348,7 +2345,7 @@ static unsigned long get_segment_base(unsigned int segment)
2348 return 0; 2345 return 0;
2349#endif 2346#endif
2350 } else { 2347 } else {
2351 if (idx > GDT_ENTRIES) 2348 if (idx >= GDT_ENTRIES)
2352 return 0; 2349 return 0;
2353 2350
2354 desc = raw_cpu_ptr(gdt_page.gdt) + idx; 2351 desc = raw_cpu_ptr(gdt_page.gdt) + idx;