From 1929d0811ef4060b64829286474756d9f32e6c6a Mon Sep 17 00:00:00 2001 From: Patrick Daly Date: Fri, 7 Jun 2019 17:00:54 -0700 Subject: [PATCH] lib/vsprintf: Less restrictive hashed pointer printing Commit ad67b74d2469 ("printk: hash addresses printed with %p") and Commit ef0010a30935 ("vsprintf: don't use 'restricted_pointer()' when not restricting") effectively removed the ability to display kernel addresses in the kernel log. While this may be a useful feature in production builds, it is undesirable when trying to debug. %px is not a possible alternative, because it is unable to differentiate between a debug and production build. Change-Id: I139fae7b8488936d214efdd2b5b807fa1c005467 Signed-off-by: Patrick Daly [isaacm@codeaurora.org: resolve trivial merge conflicts] Signed-off-by: Isaac J. Manjarres --- lib/Kconfig.debug | 9 +++++++++ lib/vsprintf.c | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 646b6bf69df7..0ca35af22945 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -164,6 +164,15 @@ config DYNAMIC_DEBUG See Documentation/admin-guide/dynamic-debug-howto.rst for additional information. +config DEBUG_CONSOLE_UNHASHED_POINTERS + bool "Display unhashed kernel pointers" + depends on DEBUG_KERNEL + help + Pointers %p and %pK are normally hashed prior to being displayed to + prevent leaking kernel addresses. On debug builds, always print + actual pointer values, ignoring the kptr_restrict setting. + Not to be enabled on production builds. + endmenu # "printk and dmesg options" menu "Compile-time checks and compiler options" diff --git a/lib/vsprintf.c b/lib/vsprintf.c index e78017a3e1bd..3196954ad8eb 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -2163,6 +2163,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, case 'V': return va_format(buf, end, ptr, spec, fmt); case 'K': + if (IS_ENABLED(CONFIG_DEBUG_CONSOLE_UNHASHED_POINTERS)) + break; return restricted_pointer(buf, end, ptr, spec); case 'N': return netdev_bits(buf, end, ptr, spec, fmt); @@ -2189,6 +2191,9 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, return pointer_string(buf, end, ptr, spec); } + if (IS_ENABLED(CONFIG_DEBUG_CONSOLE_UNHASHED_POINTERS)) + return pointer_string(buf, end, ptr, spec); + /* default is to _not_ leak addresses, hash before printing */ return ptr_to_id(buf, end, ptr, spec); }