Commit eaa2f87c authored by Dan Carpenter's avatar Dan Carpenter Committed by Ingo Molnar

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: default avatarDan Carpenter <>
Acked-by: default avatarAndy Lutomirski <>
Cc: Alexander Shishkin <>
Cc: Arnaldo Carvalho de Melo <>
Cc: Linus Torvalds <>
Cc: Peter Zijlstra <>
Cc: Thomas Gleixner <>
Fixes: d07bdfd3 ("perf/x86: Fix USER/KERNEL tagging of samples properly")
Link: Ingo Molnar's avatarIngo Molnar <>
parent 9c3a815f
......@@ -2335,12 +2335,9 @@ static unsigned long get_segment_base(unsigned int segment)
struct ldt_struct *ldt;
if (idx > LDT_ENTRIES)
return 0;
/* IRQs are off, so this synchronizes with smp_store_release */
ldt = lockless_dereference(current->active_mm->context.ldt);
if (!ldt || idx > ldt->nr_entries)
if (!ldt || idx >= ldt->nr_entries)
return 0;
desc = &ldt->entries[idx];
......@@ -2348,7 +2345,7 @@ static unsigned long get_segment_base(unsigned int segment)
return 0;
} else {
if (idx > GDT_ENTRIES)
if (idx >= GDT_ENTRIES)
return 0;
desc = raw_cpu_ptr(gdt_page.gdt) + idx;
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