summaryrefslogtreecommitdiffstats
path: root/scripts/leaking_addresses.pl
diff options
context:
space:
mode:
authorTobin C. Harding <me@tobin.cc>2017-12-07 04:40:29 +0100
committerTobin C. Harding <me@tobin.cc>2018-04-07 00:50:34 +0200
commit2f042c93a138f87a2f85e80daa5dbab6bf138045 (patch)
tree7d050a4e680ac3370e197d66b80b6709c65ba685 /scripts/leaking_addresses.pl
parentleaking_addresses: add support for kernel config file (diff)
downloadlinux-2f042c93a138f87a2f85e80daa5dbab6bf138045.tar.xz
linux-2f042c93a138f87a2f85e80daa5dbab6bf138045.zip
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>
Diffstat (limited to '')
-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);
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';