From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Perches Subject: Re: [PATCH] printk: hash addresses printed with %p Date: Tue, 10 Oct 2017 21:06:50 -0700 Message-ID: <1507694810.3552.45.camel@perches.com> References: <1507693696-3777-1-git-send-email-me@tobin.cc> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit Cc: Linus Torvalds , Kees Cook , Paolo Bonzini , Tycho Andersen , "Roberts, William C" , Tejun Heo , Jordan Glover , Greg KH , Petr Mladek , Ian Campbell , Sergey Senozhatsky , Catalin Marinas , Will Deacon , Steven Rostedt , Chris Fries , Dave Weinstein , Daniel Micay , Djalal Harouni To: "Tobin C. Harding" , kernel-hardening@lists.openwall.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Return-path: In-Reply-To: <1507693696-3777-1-git-send-email-me@tobin.cc> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On Wed, 2017-10-11 at 14:48 +1100, Tobin C. Harding wrote: > Currently there are many places in the kernel where addresses are being > printed using an unadorned %p. Kernel pointers should be printed using > %pK allowing some control via the kptr_restrict sysctl. Exposing addresses > gives attackers sensitive information about the kernel layout in memory. [] > diff --git a/lib/vsprintf.c b/lib/vsprintf.c [] > @@ -1591,6 +1591,35 @@ char *device_node_string(char *buf, char *end, struct device_node *dn, > return widen_string(buf, buf - buf_start, end, spec); > } > > +static long get_random_odd_long(void) > +{ > + long val = 0; > + > + while((val & 1) == 0) { > + val = get_random_long(); > + } > + > + return val; > +} Perhaps static long get_random_odd_long(void) { return get_random_long() | 1L; }