[RFC PATCH 5/5] x86/hw_breakpoint: Prevent data breakpoints on debug_idt_table

Lai Jiangshan
2020-05-25T14:51:28Z

A data breakpoint on the IDT is terrifying and should be avoided.
The IDT on CPU entry area is already protected. The debug IDT
should be also protected, although it is seldom used and only
used for short time.

Cc: Andy Lutomirski <luto@kernel.org>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: x86@kernel.org
Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com>
---
Please drop this patch when Peter's work to remove debug_idt_table
is merged.

arch/x86/kernel/hw_breakpoint.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c
index 9579bd6fb589..83d8b1fcbc76 100644
--- a/arch/x86/kernel/hw_breakpoint.c
+++ b/arch/x86/kernel/hw_breakpoint.c
@@ -284,6 +284,11 @@ static inline bool within_cpu_entry(unsigned long addr, unsigned long end)
return true;
}

+ /* debug_idt_table is used when load_debug_idt() */
+ if (within_area(addr, end, (unsigned long)debug_idt_table,
+ sizeof(debug_idt_table[0]) * IDT_ENTRIES))
+ return true;
+
return false;
}

--
2.20.1