aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobin C. Harding <me@tobin.cc>2017-12-06 22:40:29 -0500
committerTobin C. Harding <me@tobin.cc>2018-04-06 18:50:34 -0400
commit2f042c93a138f87a2f85e80daa5dbab6bf138045 (patch)
tree7d050a4e680ac3370e197d66b80b6709c65ba685
parentf9d2a42dacf96eb8a10259edafec0f66c9921d52 (diff)
leaking_addresses: add support for 5 page table levels
Currently script only supports 4 page table levels because of the way the kernel address regular expression is crafted. We can do better than this. Using previously added support for kernel configuration options we can get the number of page table levels defined by CONFIG_PGTABLE_LEVELS. Using this value a correct regular expression can be crafted. This only supports 5 page tables on x86_64. Add support for 5 page table levels on x86_64. Signed-off-by: Tobin C. Harding <me@tobin.cc>
-rwxr-xr-xscripts/leaking_addresses.pl32
1 files changed, 25 insertions, 7 deletions
diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl
index b3ffbf8022ce..35d6dd9fdced 100755
--- a/scripts/leaking_addresses.pl
+++ b/scripts/leaking_addresses.pl
@@ -20,6 +20,7 @@ use Term::ANSIColor qw(:constants);
20use Getopt::Long qw(:config no_auto_abbrev); 20use Getopt::Long qw(:config no_auto_abbrev);
21use Config; 21use Config;
22use bigint qw/hex/; 22use bigint qw/hex/;
23use feature 'state';
23 24
24my $P = $0; 25my $P = $0;
25my $V = '0.01'; 26my $V = '0.01';
@@ -296,13 +297,7 @@ sub may_leak_address
296 return 0; 297 return 0;
297 } 298 }
298 299
299 # One of these is guaranteed to be true. 300 $address_re = get_address_re();
300 if (is_x86_64()) {
301 $address_re = '\b(0x)?ffff[[:xdigit:]]{12}\b';
302 } elsif (is_ppc64()) {
303 $address_re = '\b(0x)?[89abcdef]00[[:xdigit:]]{13}\b';
304 }
305
306 while (/($address_re)/g) { 301 while (/($address_re)/g) {
307 if (!is_false_positive($1)) { 302 if (!is_false_positive($1)) {
308 return 1; 303 return 1;
@@ -312,6 +307,29 @@ sub may_leak_address
312 return 0; 307 return 0;
313} 308}
314 309
310sub get_address_re
311{
312 if (is_x86_64()) {
313 return get_x86_64_re();
314 } elsif (is_ppc64()) {
315 return '\b(0x)?[89abcdef]00[[:xdigit:]]{13}\b';
316 }
317}
318
319sub get_x86_64_re
320{
321 # We handle page table levels but only if explicitly configured using
322 # CONFIG_PGTABLE_LEVELS. If config file parsing fails or config option
323 # is not found we default to using address regular expression suitable
324 # for 4 page table levels.
325 state $ptl = get_kernel_config_option('CONFIG_PGTABLE_LEVELS');
326
327 if ($ptl == 5) {
328 return '\b(0x)?ff[[:xdigit:]]{14}\b';
329 }
330 return '\b(0x)?ffff[[:xdigit:]]{12}\b';
331}
332
315sub parse_dmesg 333sub parse_dmesg
316{ 334{
317 open my $cmd, '-|', 'dmesg'; 335 open my $cmd, '-|', 'dmesg';