Skip to contentSkip to conversation

x86: do not leak kernel page mapping locations

PATCH In review Kees Cook 2 participants 3 messages Feb 7, 2013 – Feb 8, 2013

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 x86: do not leak kernel page mapping locations

Without this patch, it is trivial to determine kernel page mappings by examining the error code reported to dmesg[1]. Instead, declare the entire kernel memory space as a violation of a present page.

Additionally, since show_unhandled_signals is enabled by default, switch branch hinting to the more realistic expectation, and unobfuscate the setting of the PF_PROT bit to improve readability.

[1] http://vulnfactory.org/blog/2013/02/06/a-linux-memory-trick/

---
 arch/x86/mm/fault.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/x86/mm/fault.c +5 -3
index 027088f..fb674fd 100644
@@ -748,13 +748,15 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
 				return;
 		}
 #endif
+		/* Kernel addresses are always protection faults: */
+		if (address >= TASK_SIZE)
+			error_code |= PF_PROT;
 
-		if (unlikely(show_unhandled_signals))
+		if (likely(show_unhandled_signals))
 			show_signal_msg(regs, error_code, address, tsk);
 
-		/* Kernel addresses are always protection faults: */
 		tsk->thread.cr2		= address;
-		tsk->thread.error_code	= error_code | (address >= TASK_SIZE);
+		tsk->thread.error_code	= error_code;
 		tsk->thread.trap_nr	= X86_TRAP_PF;
 
 		force_sig_info_fault(SIGSEGV, si_code, address, tsk, 0);
Signature · 6 lines
1.7.9.5


-- 
Kees Cook
Chrome OS Security
#1 lore raw
Quoted 8 lines · Kees Cook

Without this patch, it is trivial to determine kernel page mappings by examining the error code reported to dmesg[1]. Instead, declare the entire kernel memory space as a violation of a present page.

Additionally, since show_unhandled_signals is enabled by default, switch branch hinting to the more realistic expectation, and unobfuscate the setting of the PF_PROT bit to improve readability.

Quoted 6 lines

[1] http://vulnfactory.org/blog/2013/02/06/a-linux-memory-trick/

There is, of course, tons of information in dmesg which can be used for nefarious purposes, and it is hard to avoid that without neutering dmesg to uselessness.

So the question is to some degree how much this adds in isolation from locking down dmesg (and if dmesg_restrict isn't enough, what more do we need...)?

That being said, the patch doesn't seem to do any harm so I acked it and Ingo is going to apply it.

-hpa

#2 lore raw

[tip:x86/urgent] x86: Do not leak kernel page mapping locations

In reply to Kees Cook
Commit-ID:  e575a86fdc50d013bf3ad3aa81d9100e8e6cc60d
Gitweb:     http://git.kernel.org/tip/e575a86fdc50d013bf3ad3aa81d9100e8e6cc60d
Author:     Kees Cook <[email protected]>
AuthorDate: Thu, 7 Feb 2013 09:44:13 -0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 7 Feb 2013 19:57:44 +0100

x86: Do not leak kernel page mapping locations

Without this patch, it is trivial to determine kernel page mappings by examining the error code reported to dmesg[1]. Instead, declare the entire kernel memory space as a violation of a present page.

Additionally, since show_unhandled_signals is enabled by default, switch branch hinting to the more realistic expectation, and unobfuscate the setting of the PF_PROT bit to improve readability.

[1] http://vulnfactory.org/blog/2013/02/06/a-linux-memory-trick/

---
 arch/x86/mm/fault.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
arch/x86/mm/fault.c +5 -3
index 027088f..fb674fd 100644
@@ -748,13 +748,15 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
 				return;
 		}
 #endif
+		/* Kernel addresses are always protection faults: */
+		if (address >= TASK_SIZE)
+			error_code |= PF_PROT;
 
-		if (unlikely(show_unhandled_signals))
+		if (likely(show_unhandled_signals))
 			show_signal_msg(regs, error_code, address, tsk);
 
-		/* Kernel addresses are always protection faults: */
 		tsk->thread.cr2		= address;
-		tsk->thread.error_code	= error_code | (address >= TASK_SIZE);
+		tsk->thread.error_code	= error_code;
 		tsk->thread.trap_nr	= X86_TRAP_PF;
 
 		force_sig_info_fault(SIGSEGV, si_code, address, tsk, 0);