Commit dd98c252 authored by Tobin C. Harding's avatar Tobin C. Harding

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: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarTobin C. Harding <me@tobin.cc>
parent 62139c12
...@@ -29,6 +29,9 @@ my $V = '0.01'; ...@@ -29,6 +29,9 @@ my $V = '0.01';
# Directories to scan. # Directories to scan.
my @DIRS = ('/proc', '/sys'); 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 # 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 # your architecture is not listed here and has a grep'able kernel address please
# consider submitting a patch. # consider submitting a patch.
...@@ -284,6 +287,23 @@ sub skip_parse ...@@ -284,6 +287,23 @@ sub skip_parse
return skip($path, \@skip_parse_files_abs, \@skip_parse_files_any); 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 sub parse_file
{ {
my ($file) = @_; my ($file) = @_;
...@@ -335,7 +355,7 @@ sub walk ...@@ -335,7 +355,7 @@ sub walk
if (-d $path) { if (-d $path) {
push @dirs, $path; push @dirs, $path;
} else { } else {
parse_file($path); timed_parse_file($path);
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment