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>
This commit is contained in:
Tobin C. Harding 2017-12-07 14:40:29 +11:00
parent f9d2a42dac
commit 2f042c93a1

View File

@ -20,6 +20,7 @@ use Term::ANSIColor qw(:constants);
use Getopt::Long qw(:config no_auto_abbrev);
use Config;
use bigint qw/hex/;
use feature 'state';
my $P = $0;
my $V = '0.01';
@ -296,13 +297,7 @@ sub may_leak_address
return 0;
}
# 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';
}
$address_re = get_address_re();
while (/($address_re)/g) {
if (!is_false_positive($1)) {
return 1;
@ -312,6 +307,29 @@ sub may_leak_address
return 0;
}
sub get_address_re
{
if (is_x86_64()) {
return get_x86_64_re();
} elsif (is_ppc64()) {
return '\b(0x)?[89abcdef]00[[:xdigit:]]{13}\b';
}
}
sub get_x86_64_re
{
# We handle page table levels but only if explicitly configured using
# CONFIG_PGTABLE_LEVELS. If config file parsing fails or config option
# is not found we default to using address regular expression suitable
# for 4 page table levels.
state $ptl = get_kernel_config_option('CONFIG_PGTABLE_LEVELS');
if ($ptl == 5) {
return '\b(0x)?ff[[:xdigit:]]{14}\b';
}
return '\b(0x)?ffff[[:xdigit:]]{12}\b';
}
sub parse_dmesg
{
open my $cmd, '-|', 'dmesg';