From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756912AbdJKEG5 (ORCPT ); Wed, 11 Oct 2017 00:06:57 -0400 Received: from smtprelay0036.hostedemail.com ([216.40.44.36]:57576 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751465AbdJKEGz (ORCPT ); Wed, 11 Oct 2017 00:06:55 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::::::::::::::::::::::::,RULES_HIT:41:355:379:541:599:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1540:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2828:2892:3138:3139:3140:3141:3142:3352:3622:3865:3870:4321:5007:6742:10004:10400:10848:11026:11232:11658:11914:12048:12296:12740:12760:12895:13069:13311:13357:13439:14659:14721:21080:21627:30054:30075:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:3,LUA_SUMMARY:none X-HE-Tag: shop00_7616abb91c919 X-Filterd-Recvd-Size: 2331 Message-ID: <1507694810.3552.45.camel@perches.com> Subject: Re: [PATCH] printk: hash addresses printed with %p From: Joe Perches To: "Tobin C. Harding" , kernel-hardening@lists.openwall.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org 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 Date: Tue, 10 Oct 2017 21:06:50 -0700 In-Reply-To: <1507693696-3777-1-git-send-email-me@tobin.cc> References: <1507693696-3777-1-git-send-email-me@tobin.cc> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.6-1ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@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; }