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

From: Lai Jiangshan
Date: Mon May 25 2020 - 10:51:29 EST

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@xxxxxxxxxx>
Cc: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: x86@xxxxxxxxxx
Signed-off-by: Lai Jiangshan <laijs@xxxxxxxxxxxxxxxxx>
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;