diff options
author | Tobin C. Harding <me@tobin.cc> | 2017-11-08 23:37:06 -0500 |
---|---|---|
committer | Tobin C. Harding <me@tobin.cc> | 2017-11-13 17:29:27 -0500 |
commit | dd98c252aea2a3dcd4014cb71bcdf9588519b800 (patch) | |
tree | 3e093f8ab931482bbc2b29130021e53604e61e68 /scripts/leaking_addresses.pl | |
parent | 62139c1242b573cb647776e3abc503a69fbd2c08 (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/leaking_addresses.pl')
-rwxr-xr-x | scripts/leaking_addresses.pl | 22 |
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'; | |||
29 | # Directories to scan. | 29 | # Directories to scan. |
30 | my @DIRS = ('/proc', '/sys'); | 30 | my @DIRS = ('/proc', '/sys'); |
31 | 31 | ||
32 | # Timer for parsing each file, in seconds. | ||
33 | my $TIMEOUT = 10; | ||
34 | |||
32 | # Script can only grep for kernel addresses on the following architectures. If | 35 | # Script can only grep for kernel addresses on the following architectures. If |
33 | # your architecture is not listed here and has a grep'able kernel address please | 36 | # your architecture is not listed here and has a grep'able kernel address please |
34 | # consider submitting a patch. | 37 | # consider submitting a patch. |
@@ -284,6 +287,23 @@ sub skip_parse | |||
284 | return skip($path, \@skip_parse_files_abs, \@skip_parse_files_any); | 287 | return skip($path, \@skip_parse_files_abs, \@skip_parse_files_any); |
285 | } | 288 | } |
286 | 289 | ||
290 | sub timed_parse_file | ||
291 | { | ||
292 | my ($file) = @_; | ||
293 | |||
294 | eval { | ||
295 | local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required. | ||
296 | alarm $TIMEOUT; | ||
297 | parse_file($file); | ||
298 | alarm 0; | ||
299 | }; | ||
300 | |||
301 | if ($@) { | ||
302 | die unless $@ eq "alarm\n"; # Propagate unexpected errors. | ||
303 | printf STDERR "timed out parsing: %s\n", $file; | ||
304 | } | ||
305 | } | ||
306 | |||
287 | sub parse_file | 307 | sub parse_file |
288 | { | 308 | { |
289 | my ($file) = @_; | 309 | my ($file) = @_; |
@@ -335,7 +355,7 @@ sub walk | |||
335 | if (-d $path) { | 355 | if (-d $path) { |
336 | push @dirs, $path; | 356 | push @dirs, $path; |
337 | } else { | 357 | } else { |
338 | parse_file($path); | 358 | timed_parse_file($path); |
339 | } | 359 | } |
340 | } | 360 | } |
341 | } | 361 | } |