History

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.

Tobin C. Harding committed 8 years ago

Commit 2f042c91 parent f9d2a421 file · +25 −7Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/leaking_addresses.pl+25−7
@@ -20,6 +20,7 @@ use Term::ANSIColor qw(:constants); · 19 unmodified lines
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 · 270 unmodified lines
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 · 3 unmodified lines
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_dmesg333sub parse_dmesg
316{334{
317 open my $cmd, '-|', 'dmesg';335 open my $cmd, '-|', 'dmesg';