提交 62139c12 编写于 作者: T Tobin C. Harding

leaking_addresses: add support for ppc64

Currently script is targeted at x86_64. We can support other
architectures by using the correct regular expressions for each
architecture.

Add the infrastructure to support multiple architectures. Add support
for ppc64.
Signed-off-by: NTobin C. Harding <me@tobin.cc>
上级 d09bd8da
...@@ -21,6 +21,7 @@ use File::Spec; ...@@ -21,6 +21,7 @@ use File::Spec;
use Cwd 'abs_path'; use Cwd 'abs_path';
use Term::ANSIColor qw(:constants); use Term::ANSIColor qw(:constants);
use Getopt::Long qw(:config no_auto_abbrev); use Getopt::Long qw(:config no_auto_abbrev);
use Config;
my $P = $0; my $P = $0;
my $V = '0.01'; my $V = '0.01';
...@@ -28,6 +29,11 @@ my $V = '0.01'; ...@@ -28,6 +29,11 @@ my $V = '0.01';
# Directories to scan. # Directories to scan.
my @DIRS = ('/proc', '/sys'); my @DIRS = ('/proc', '/sys');
# Script can only grep for kernel addresses on the following architectures. If
# your architecture is not listed here and has a grep'able kernel address please
# consider submitting a patch.
my @SUPPORTED_ARCHITECTURES = ('x86_64', 'ppc64');
# Command line options. # Command line options.
my $help = 0; my $help = 0;
my $debug = 0; my $debug = 0;
...@@ -137,6 +143,20 @@ if (!$input_raw and ($squash_by_path or $squash_by_filename)) { ...@@ -137,6 +143,20 @@ if (!$input_raw and ($squash_by_path or $squash_by_filename)) {
exit(128); exit(128);
} }
if (!is_supported_architecture()) {
printf "\nScript does not support your architecture, sorry.\n";
printf "\nCurrently we support: \n\n";
foreach(@SUPPORTED_ARCHITECTURES) {
printf "\t%s\n", $_;
}
my $archname = $Config{archname};
printf "\n\$ perl -MConfig -e \'print \"\$Config{archname}\\n\"\'\n";
printf "%s\n", $archname;
exit(129);
}
if ($output_raw) { if ($output_raw) {
open my $fh, '>', $output_raw or die "$0: $output_raw: $!\n"; open my $fh, '>', $output_raw or die "$0: $output_raw: $!\n";
select $fh; select $fh;
...@@ -152,6 +172,31 @@ sub dprint ...@@ -152,6 +172,31 @@ sub dprint
printf(STDERR @_) if $debug; printf(STDERR @_) if $debug;
} }
sub is_supported_architecture
{
return (is_x86_64() or is_ppc64());
}
sub is_x86_64
{
my $archname = $Config{archname};
if ($archname =~ m/x86_64/) {
return 1;
}
return 0;
}
sub is_ppc64
{
my $archname = $Config{archname};
if ($archname =~ m/powerpc/ and $archname =~ m/64/) {
return 1;
}
return 0;
}
sub is_false_positive sub is_false_positive
{ {
my ($match) = @_; my ($match) = @_;
...@@ -161,11 +206,13 @@ sub is_false_positive ...@@ -161,11 +206,13 @@ sub is_false_positive
return 1; return 1;
} }
if (is_x86_64) {
if ($match =~ '\bf{10}600000\b' or# vsyscall memory region, we should probably check against a range here. # vsyscall memory region, we should probably check against a range here.
if ($match =~ '\bf{10}600000\b' or
$match =~ '\bf{10}601000\b') { $match =~ '\bf{10}601000\b') {
return 1; return 1;
} }
}
return 0; return 0;
} }
...@@ -174,7 +221,7 @@ sub is_false_positive ...@@ -174,7 +221,7 @@ sub is_false_positive
sub may_leak_address sub may_leak_address
{ {
my ($line) = @_; my ($line) = @_;
my $address = '\b(0x)?ffff[[:xdigit:]]{12}\b'; my $address_re;
# Signal masks. # Signal masks.
if ($line =~ '^SigBlk:' or if ($line =~ '^SigBlk:' or
...@@ -187,7 +234,14 @@ sub may_leak_address ...@@ -187,7 +234,14 @@ sub may_leak_address
return 0; return 0;
} }
while (/($address)/g) { # One of these is guaranteed to be true.
if (is_x86_64()) {
$address_re = '\b(0x)?ffff[[:xdigit:]]{12}\b';
} elsif (is_ppc64()) {
$address_re = '\b(0x)?[89abcdef]00[[:xdigit:]]{13}\b';
}
while (/($address_re)/g) {
if (!is_false_positive($1)) { if (!is_false_positive($1)) {
return 1; return 1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册