Skip to content

Commit 3943abf

Browse files
Lai JiangshanKAGA-KOKO
authored andcommitted
x86/debug: Prevent data breakpoints on cpu_dr7
local_db_save() is called at the start of exc_debug_kernel(), reads DR7 and disables breakpoints to prevent recursion. When running in a guest (X86_FEATURE_HYPERVISOR), local_db_save() reads the per-cpu variable cpu_dr7 to check whether a breakpoint is active or not before it accesses DR7. A data breakpoint on cpu_dr7 therefore results in infinite #DB recursion. Disallow data breakpoints on cpu_dr7 to prevent that. Fixes: 84b6a34("x86/entry: Optimize local_db_save() for virt") Signed-off-by: Lai Jiangshan <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent c4bed4b commit 3943abf

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

arch/x86/kernel/hw_breakpoint.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,14 @@ static inline bool within_cpu_entry(unsigned long addr, unsigned long end)
307307
(unsigned long)&per_cpu(cpu_tlbstate, cpu),
308308
sizeof(struct tlb_state)))
309309
return true;
310+
311+
/*
312+
* When in guest (X86_FEATURE_HYPERVISOR), local_db_save()
313+
* will read per-cpu cpu_dr7 before clear dr7 register.
314+
*/
315+
if (within_area(addr, end, (unsigned long)&per_cpu(cpu_dr7, cpu),
316+
sizeof(cpu_dr7)))
317+
return true;
310318
}
311319

312320
return false;

0 commit comments

Comments
 (0)