summaryrefslogtreecommitdiffstats
path: root/scripts/leaking_addresses.pl
diff options
context:
space:
mode:
authorTobin C. Harding <me@tobin.cc>2018-02-18 19:03:37 -0500
committerTobin C. Harding <me@tobin.cc>2018-04-06 18:50:34 -0400
commitb401f56f33bf551304cc4ca4f503863ee6ac7787 (patch)
tree810a69ac53bb627f7d90309af2656be976d593fa /scripts/leaking_addresses.pl
parente2858caddc71f61521254a5359d17d058d6dda08 (diff)
leaking_addresses: simplify path skipping
Currently script has multiple configuration arrays. This is confusing, evident by the fact that a bunch of the entries are in the wrong place. We can simplify the code by just having a single array for absolute paths to skip and a single array for file names to skip wherever they appear in the scanned directory tree. There are also currently multiple subroutines to handle the different arrays, we can reduce these to a single subroutine also. Simplify the path skipping code. Signed-off-by: Tobin C. Harding <me@tobin.cc>
Diffstat (limited to 'scripts/leaking_addresses.pl')
-rwxr-xr-xscripts/leaking_addresses.pl90
1 files changed, 29 insertions, 61 deletions
diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl
index 3d5c3096aac8..2ad6e7fb6698 100755
--- a/scripts/leaking_addresses.pl
+++ b/scripts/leaking_addresses.pl
@@ -48,41 +48,26 @@ my $kernel_config_file = ""; # Kernel configuration file.
48my $opt_32bit = 0; # Scan 32-bit kernel. 48my $opt_32bit = 0; # Scan 32-bit kernel.
49my $page_offset_32bit = 0; # Page offset for 32-bit kernel. 49my $page_offset_32bit = 0; # Page offset for 32-bit kernel.
50 50
51# Do not parse these files (absolute path). 51# Skip these absolute paths.
52my @skip_parse_files_abs = ('/proc/kmsg', 52my @skip_abs = (
53 '/proc/kcore', 53 '/proc/kmsg',
54 '/proc/fs/ext4/sdb1/mb_groups', 54 '/proc/device-tree',
55 '/proc/1/fd/3', 55 '/sys/firmware/devicetree',
56 '/sys/firmware/devicetree', 56 '/sys/kernel/debug/tracing/trace_pipe',
57 '/proc/device-tree', 57 '/sys/kernel/security/apparmor/revision');
58 '/sys/kernel/debug/tracing/trace_pipe', 58
59 '/sys/kernel/security/apparmor/revision'); 59# Skip these under any subdirectory.
60 60my @skip_any = (
61# Do not parse these files under any subdirectory. 61 'pagemap',
62my @skip_parse_files_any = ('0', 62 'events',
63 '1', 63 'access',
64 '2', 64 'registers',
65 'pagemap', 65 'snapshot_raw',
66 'events', 66 'trace_pipe_raw',
67 'access', 67 'ptmx',
68 'registers', 68 'trace_pipe',
69 'snapshot_raw', 69 'fd',
70 'trace_pipe_raw', 70 'usbmon');
71 'ptmx',
72 'trace_pipe');
73
74# Do not walk these directories (absolute path).
75my @skip_walk_dirs_abs = ();
76
77# Do not walk these directories under any subdirectory.
78my @skip_walk_dirs_any = ('self',
79 'thread-self',
80 'cwd',
81 'fd',
82 'usbmon',
83 'stderr',
84 'stdin',
85 'stdout');
86 71
87sub help 72sub help
88{ 73{
@@ -417,26 +402,20 @@ sub parse_dmesg
417# True if we should skip this path. 402# True if we should skip this path.
418sub skip 403sub skip
419{ 404{
420 my ($path, $paths_abs, $paths_any) = @_; 405 my ($path) = @_;
421 406
422 foreach (@$paths_abs) { 407 foreach (@skip_abs) {
423 return 1 if (/^$path$/); 408 return 1 if (/^$path$/);
424 } 409 }
425 410
426 my($filename, $dirs, $suffix) = fileparse($path); 411 my($filename, $dirs, $suffix) = fileparse($path);
427 foreach (@$paths_any) { 412 foreach (@skip_any) {
428 return 1 if (/^$filename$/); 413 return 1 if (/^$filename$/);
429 } 414 }
430 415
431 return 0; 416 return 0;
432} 417}
433 418
434sub skip_parse
435{
436 my ($path) = @_;
437 return skip($path, \@skip_parse_files_abs, \@skip_parse_files_any);
438}
439
440sub timed_parse_file 419sub timed_parse_file
441{ 420{
442 my ($file) = @_; 421 my ($file) = @_;
@@ -466,12 +445,6 @@ sub parse_file
466 return; 445 return;
467 } 446 }
468 447
469 if (skip_parse($file)) {
470 dprint "skipping file: $file\n";
471 return;
472 }
473 dprint "parsing: $file\n";
474
475 open my $fh, "<", $file or return; 448 open my $fh, "<", $file or return;
476 while ( <$fh> ) { 449 while ( <$fh> ) {
477 if (may_leak_address($_)) { 450 if (may_leak_address($_)) {
@@ -481,21 +454,12 @@ sub parse_file
481 close $fh; 454 close $fh;
482} 455}
483 456
484
485# True if we should skip walking this directory.
486sub skip_walk
487{
488 my ($path) = @_;
489 return skip($path, \@skip_walk_dirs_abs, \@skip_walk_dirs_any)
490}
491
492# Recursively walk directory tree. 457# Recursively walk directory tree.
493sub walk 458sub walk
494{ 459{
495 my @dirs = @_; 460 my @dirs = @_;
496 461
497 while (my $pwd = shift @dirs) { 462 while (my $pwd = shift @dirs) {
498 next if (skip_walk($pwd));
499 next if (!opendir(DIR, $pwd)); 463 next if (!opendir(DIR, $pwd));
500 my @files = readdir(DIR); 464 my @files = readdir(DIR);
501 closedir(DIR); 465 closedir(DIR);
@@ -506,11 +470,15 @@ sub walk
506 my $path = "$pwd/$file"; 470 my $path = "$pwd/$file";
507 next if (-l $path); 471 next if (-l $path);
508 472
473 next if (skip($path));
474
509 if (-d $path) { 475 if (-d $path) {
510 push @dirs, $path; 476 push @dirs, $path;
511 } else { 477 next;
512 timed_parse_file($path);
513 } 478 }
479
480 dprint "parsing: $path\n";
481 timed_parse_file($path);
514 } 482 }
515 } 483 }
516} 484}