From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753327AbdKHVQQ (ORCPT ); Wed, 8 Nov 2017 16:16:16 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:41141 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752716AbdKHVQM (ORCPT ); Wed, 8 Nov 2017 16:16:12 -0500 X-ME-Sender: Date: Thu, 9 Nov 2017 08:16:08 +1100 From: "Tobin C. Harding" To: Michael Ellerman Cc: kernel-hardening@lists.openwall.com, "Jason A. Donenfeld" , "Theodore Ts'o" , Linus Torvalds , Kees Cook , Paolo Bonzini , Tycho Andersen , "Roberts, William C" , Tejun Heo , Jordan Glover , Greg KH , Petr Mladek , Joe Perches , Ian Campbell , Sergey Senozhatsky , Catalin Marinas , Will Deacon , Steven Rostedt , Chris Fries , Dave Weinstein , Daniel Micay , Djalal Harouni , linux-kernel@vger.kernel.org, Network Development , David Miller Subject: Re: [kernel-hardening] [PATCH v4] scripts: add leaking_addresses.pl Message-ID: <20171108211608.GC27823@eros> References: <1510050731-32446-1-git-send-email-me@tobin.cc> <87k1z12cof.fsf@concordia.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87k1z12cof.fsf@concordia.ellerman.id.au> X-Mailer: Mutt 1.5.24 (2015-08-30) User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 08, 2017 at 11:10:56PM +1100, Michael Ellerman wrote: > "Tobin C. Harding" writes: > > Currently we are leaking addresses from the kernel to user space. This > > script is an attempt to find some of those leakages. Script parses > > `dmesg` output and /proc and /sys files for hex strings that look like > > kernel addresses. > > > > Only works for 64 bit kernels, the reason being that kernel addresses > > on 64 bit kernels have 'ffff' as the leading bit pattern making greping > > possible. > > That doesn't work super well on other architectures :D > > I don't speak perl but presumably you can check the arch somehow and > customise the regex? I'm on it. > ... > > +# Return _all_ non false positive addresses from $line. > > +sub extract_addresses > > +{ > > + my ($line) = @_; > > + my $address = '\b(0x)?ffff[[:xdigit:]]{12}\b'; > > On 64-bit powerpc (ppc64/ppc64le) we'd want: > > + my $address = '\b(0x)?[89abcdef]00[[:xdigit:]]{13}\b'; This is great! Thanks a million. This gives me the idea of getting in contact with people who have access to other [64 bit] architectures and getting the address format. I guess a dump of kallsyms from each architecture would do the job nicely. > > +# Do not parse these files (absolute path). > > +my @skip_parse_files_abs = ('/proc/kmsg', > > + '/proc/kcore', > > + '/proc/fs/ext4/sdb1/mb_groups', > > + '/proc/1/fd/3', > > + '/sys/kernel/debug/tracing/trace_pipe', > > + '/sys/kernel/security/apparmor/revision'); > > Can you add: > > /sys/firmware/devicetree > > and/or /proc/device-tree (which is a symlink to the above). Can do, thanks. > We should also start restricting access to that because it may have > potentially interesting physical addresses in it, but that will break > existing tools, so it will need to be opt-in and done over time. Seems like this is going to be a recurring theme if we try to stop leaks using file permissions. I'm interested in how we would do this, assuming it has to be a case by case fix but done many times. thanks, Tobin.