summaryrefslogtreecommitdiffstats
path: root/scripts/leaking_addresses.pl
diff options
context:
space:
mode:
authorTobin C. Harding <me@tobin.cc>2017-11-08 23:19:40 -0500
committerTobin C. Harding <me@tobin.cc>2017-11-13 17:29:27 -0500
commit62139c1242b573cb647776e3abc503a69fbd2c08 (patch)
tree508dd1c0f9e2a13df4abe703f33d221feba45286 /scripts/leaking_addresses.pl
parentd09bd8da8812a4df69ea3303e6df846a729ec623 (diff)
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: Tobin C. Harding <me@tobin.cc>
Diffstat (limited to 'scripts/leaking_addresses.pl')
-rwxr-xr-xscripts/leaking_addresses.pl66
1 files changed, 60 insertions, 6 deletions
diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl
index 4610ad3c80c2..1d6ab7f1b10c 100755
--- a/scripts/leaking_addresses.pl
+++ b/scripts/leaking_addresses.pl
@@ -21,6 +21,7 @@ use File::Spec;
21use Cwd 'abs_path'; 21use Cwd 'abs_path';
22use Term::ANSIColor qw(:constants); 22use Term::ANSIColor qw(:constants);
23use Getopt::Long qw(:config no_auto_abbrev); 23use Getopt::Long qw(:config no_auto_abbrev);
24use Config;
24 25
25my $P = $0; 26my $P = $0;
26my $V = '0.01'; 27my $V = '0.01';
@@ -28,6 +29,11 @@ my $V = '0.01';
28# Directories to scan. 29# Directories to scan.
29my @DIRS = ('/proc', '/sys'); 30my @DIRS = ('/proc', '/sys');
30 31
32# Script can only grep for kernel addresses on the following architectures. If
33# your architecture is not listed here and has a grep'able kernel address please
34# consider submitting a patch.
35my @SUPPORTED_ARCHITECTURES = ('x86_64', 'ppc64');
36
31# Command line options. 37# Command line options.
32my $help = 0; 38my $help = 0;
33my $debug = 0; 39my $debug = 0;
@@ -137,6 +143,20 @@ if (!$input_raw and ($squash_by_path or $squash_by_filename)) {
137 exit(128); 143 exit(128);
138} 144}
139 145
146if (!is_supported_architecture()) {
147 printf "\nScript does not support your architecture, sorry.\n";
148 printf "\nCurrently we support: \n\n";
149 foreach(@SUPPORTED_ARCHITECTURES) {
150 printf "\t%s\n", $_;
151 }
152
153 my $archname = $Config{archname};
154 printf "\n\$ perl -MConfig -e \'print \"\$Config{archname}\\n\"\'\n";
155 printf "%s\n", $archname;
156
157 exit(129);
158}
159
140if ($output_raw) { 160if ($output_raw) {
141 open my $fh, '>', $output_raw or die "$0: $output_raw: $!\n"; 161 open my $fh, '>', $output_raw or die "$0: $output_raw: $!\n";
142 select $fh; 162 select $fh;
@@ -152,6 +172,31 @@ sub dprint
152 printf(STDERR @_) if $debug; 172 printf(STDERR @_) if $debug;
153} 173}
154 174
175sub is_supported_architecture
176{
177 return (is_x86_64() or is_ppc64());
178}
179
180sub is_x86_64
181{
182 my $archname = $Config{archname};
183
184 if ($archname =~ m/x86_64/) {
185 return 1;
186 }
187 return 0;
188}
189
190sub is_ppc64
191{
192 my $archname = $Config{archname};
193
194 if ($archname =~ m/powerpc/ and $archname =~ m/64/) {
195 return 1;
196 }
197 return 0;
198}
199
155sub is_false_positive 200sub is_false_positive
156{ 201{
157 my ($match) = @_; 202 my ($match) = @_;
@@ -161,10 +206,12 @@ sub is_false_positive
161 return 1; 206 return 1;
162 } 207 }
163 208
164 209 if (is_x86_64) {
165 if ($match =~ '\bf{10}600000\b' or# vsyscall memory region, we should probably check against a range here. 210 # vsyscall memory region, we should probably check against a range here.
166 $match =~ '\bf{10}601000\b') { 211 if ($match =~ '\bf{10}600000\b' or
167 return 1; 212 $match =~ '\bf{10}601000\b') {
213 return 1;
214 }
168 } 215 }
169 216
170 return 0; 217 return 0;
@@ -174,7 +221,7 @@ sub is_false_positive
174sub may_leak_address 221sub may_leak_address
175{ 222{
176 my ($line) = @_; 223 my ($line) = @_;
177 my $address = '\b(0x)?ffff[[:xdigit:]]{12}\b'; 224 my $address_re;
178 225
179 # Signal masks. 226 # Signal masks.
180 if ($line =~ '^SigBlk:' or 227 if ($line =~ '^SigBlk:' or
@@ -187,7 +234,14 @@ sub may_leak_address
187 return 0; 234 return 0;
188 } 235 }
189 236
190 while (/($address)/g) { 237 # One of these is guaranteed to be true.
238 if (is_x86_64()) {
239 $address_re = '\b(0x)?ffff[[:xdigit:]]{12}\b';
240 } elsif (is_ppc64()) {
241 $address_re = '\b(0x)?[89abcdef]00[[:xdigit:]]{13}\b';
242 }
243
244 while (/($address_re)/g) {
191 if (!is_false_positive($1)) { 245 if (!is_false_positive($1)) {
192 return 1; 246 return 1;
193 } 247 }