From mboxrd@z Thu Jan 1 00:00:00 1970 From: Petr Mladek Subject: Re: [PATCH v4] scripts: add leaking_addresses.pl Date: Tue, 7 Nov 2017 16:51:29 +0100 Message-ID: <20171107155129.GE2652@pathway.suse.cz> References: <1510050731-32446-1-git-send-email-me@tobin.cc> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 , Joe Perches , Ian Campbell , Sergey Senozhatsky , Catalin Marinas , Will Deacon , Steven Rostedt , Chris Fries , Dave Weinstein , Daniel Micay < To: "Tobin C. Harding" Return-path: Content-Disposition: inline In-Reply-To: <1510050731-32446-1-git-send-email-me@tobin.cc> Sender: linux-kernel-owner@vger.kernel.org List-Id: netdev.vger.kernel.org On Tue 2017-11-07 21:32:11, Tobin C. Harding wrote: > 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. On 32 kernels we don't have this luxury. > > Scripts is _slightly_ smarter than a straight grep, we check for false > positives (all 0's or all 1's, and vsyscall start/finish addresses). > > Output is saved to file to expedite repeated formatting/viewing of > output. > > diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl > new file mode 100755 > index 000000000000..282c0cc2bdea > --- /dev/null > +++ b/scripts/leaking_addresses.pl > +sub help > +{ > + my ($exitcode) = @_; > + > + print << "EOM"; > +Usage: $P COMMAND [OPTIONS] > +Version: $V > + > +Commands: > + > + scan Scan the kernel (savesg raw results to file and runs `format`). > + format Parse results file and format output. > + > +Options: > + -o, --output= Accepts absolute or relative filename or directory name. IMHO, this is pretty non-standard. I would support only -o file. Then you do not need to solve problems with replacing an existing file. The user would know exactly what file will be generated. > + --suppress-dmesg Don't show dmesg results. The apostrophe breaks highlighting of the rest of the code ;-) > + --squash-by-path Show one result per unique path. > + --raw Show raw results. > + --send-report Submit raw results for someone else to worry about. > + -d, --debug Display debugging output. > + -h, --help, --version Display this help and exit. > + > +Scans the running (64 bit) kernel for potential leaking addresses. > +} This bracket should not be here. The help text is limited by "EOM" below. > + > +EOM > + exit($exitcode); > +} [...] > +sub cache_path > +{ > + my ($paths, $line) = @_; > + > + my $index = index($line, ':'); There are paths with the double dot, for example: /sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.6/2-1.6:1.0/input/input4/uevent Then the file name is wrongly detected, in my example as "pci0000" It seems that searching for ": " sub-string works rather well. I mean using: my $index = index($line, ': '); > + my $path = substr($line, 0, $index); > + > + if (!$paths->{$path}) { > + $paths->{$path} = (); > + } > + push @{$paths->{$path}}, $line; It would make sense to use the same trick from cache_filename and remove path from the cached text. I mean: $index += 2; # skip ': ' push @{$paths->{$path}}, substr($line, $index); > +} > + > +sub cache_filename > +{ > + my ($files, $line) = @_; > + > + my $index = index($line, ':'); Same problem with the double dot in the path name. The following helped me: my $index = index($line, ': '); > + my $path = substr($line, 0, $index); > + my $filename = basename($path); > + if (!$files->{$filename}) { > + $files->{$filename} = (); > + } > + $index += 2; # skip ': ' > + push @{$files->{$filename}}, substr($line, $index); > +} This is what caught my eye when trying the script. Best Regards, Petr