summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorTobin C. Harding <me@tobin.cc>2017-11-09 15:37:06 +1100
committerTobin C. Harding <me@tobin.cc>2017-11-14 09:29:27 +1100
commitdd98c252aea2a3dcd4014cb71bcdf9588519b800 (patch)
tree3e093f8ab931482bbc2b29130021e53604e61e68 /scripts
parent62139c1242b573cb647776e3abc503a69fbd2c08 (diff)
leaking_addresses: add timeout on file read
Currently script can stall if we read certain files (like /proc/kmsg). While we have a mechanism to skip these files once they are discovered it would be nice to not stall on as yet undiscovered files of this kind. Set a timer before each file is parsed, warn user if timer expires. Suggested-by: Kees Cook <keescook@chromium.org> Signed-off-by: Tobin C. Harding <me@tobin.cc>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/leaking_addresses.pl22
1 files changed, 21 insertions, 1 deletions
diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl
index 1d6ab7f1b10c..6efd1fdb7d25 100755
--- a/scripts/leaking_addresses.pl
+++ b/scripts/leaking_addresses.pl
@@ -29,6 +29,9 @@ my $V = '0.01';
# Directories to scan.
my @DIRS = ('/proc', '/sys');
+# Timer for parsing each file, in seconds.
+my $TIMEOUT = 10;
+
# Script can only grep for kernel addresses on the following architectures. If
# your architecture is not listed here and has a grep'able kernel address please
# consider submitting a patch.
@@ -284,6 +287,23 @@ sub skip_parse
return skip($path, \@skip_parse_files_abs, \@skip_parse_files_any);
}
+sub timed_parse_file
+{
+ my ($file) = @_;
+
+ eval {
+ local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required.
+ alarm $TIMEOUT;
+ parse_file($file);
+ alarm 0;
+ };
+
+ if ($@) {
+ die unless $@ eq "alarm\n"; # Propagate unexpected errors.
+ printf STDERR "timed out parsing: %s\n", $file;
+ }
+}
+
sub parse_file
{
my ($file) = @_;
@@ -335,7 +355,7 @@ sub walk
if (-d $path) {
push @dirs, $path;
} else {
- parse_file($path);
+ timed_parse_file($path);
}
}
}