public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vfsprintf: only hash addresses in security environment
@ 2020-03-04 12:47 Jason Yan
  2020-03-04 15:12 ` Andy Shevchenko
  2020-03-04 18:34 ` Kees Cook
  0 siblings, 2 replies; 7+ messages in thread
From: Jason Yan @ 2020-03-04 12:47 UTC (permalink / raw)
  To: pmladek, rostedt, sergey.senozhatsky, andriy.shevchenko, linux
  Cc: linux-kernel, Jason Yan, Scott Wood, Kees Cook, Tobin C . Harding,
	Linus Torvalds, Daniel Axtens

When I am implementing KASLR for powerpc, Scott Wood argued that format
specifier "%p" always hashes the addresses that people do not have a
choice to shut it down: https://patchwork.kernel.org/cover/11367547/

It's true that if in a debug environment or security is not concerned,
such as KASLR is absent or kptr_restrict = 0,  there is no way to shut
the hashing down except changing the code and build the kernel again
to use a different format specifier like "%px". And when we want to
turn to security environment, the format specifier has to be changed
back and rebuild the kernel.

As KASLR is available on most popular platforms and enabled by default,
print the raw value of address while KASLR is absent and kptr_restrict
is zero. Those who concerns about security must have KASLR enabled or
kptr_restrict set properly.

Cc: Scott Wood <oss@buserror.net>
Cc: Kees Cook <keescook@chromium.org>
Cc: "Tobin C . Harding" <tobin@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Daniel Axtens <dja@axtens.net>
Signed-off-by: Jason Yan <yanaijie@huawei.com>
---
 lib/vsprintf.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 7c488a1ce318..f74131b152a1 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -2253,8 +2253,15 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 		return err_ptr(buf, end, ptr, spec);
 	}
 
-	/* default is to _not_ leak addresses, hash before printing */
-	return ptr_to_id(buf, end, ptr, spec);
+	/*
+	 * In security environment, while kaslr is enabled or kptr_restrict is
+	 * not zero, hash before printing so that addresses will not be
+	 * leaked. And if not in a security environment, print the raw value
+	 */
+	if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) || kptr_restrict)
+		return ptr_to_id(buf, end, ptr, spec);
+	else
+		return pointer_string(buf, end, ptr, spec);
 }
 
 /*
-- 
2.17.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-03-06 18:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-04 12:47 [PATCH] vfsprintf: only hash addresses in security environment Jason Yan
2020-03-04 15:12 ` Andy Shevchenko
2020-03-04 18:34 ` Kees Cook
2020-03-04 21:11   ` [PATCH v3 0/6] implement KASLR for powerpc/fsl_booke/64 Scott Wood
2020-03-04 22:36     ` Kees Cook
2020-03-05 18:51     ` Linus Torvalds
2020-03-06 18:33       ` Scott Wood

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox