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
2020 use Getopt::Long qw(:config no_auto_abbrev);
2121 use Config;
2222 use bigint qw/hex/;
23+use feature 'state';
2324
2425 my $P = $0;
2526 my $V = '0.01';
@@ -296,13 +297,7 @@ sub may_leak_address · 270 unmodified lines
296297 return 0;
297298 }
298299
299− # One of these is guaranteed to be true.
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−
300+ $address_re = get_address_re();
306301 while (/($address_re)/g) {
307302 if (!is_false_positive($1)) {
308303 return 1;
@@ -312,6 +307,29 @@ sub may_leak_address · 3 unmodified lines
312307 return 0;
313308 }
314309
310+sub 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+
319+sub 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+
315333 sub parse_dmesg
316334 {
317335 open my $cmd, '-|', 'dmesg';