Lines Matching +full:sub +full:- +full:path
2 # SPDX-License-Identifier: GPL-2.0-only
7 # - Scans dmesg output.
8 # - Walks directory tree and parses each file (for each directory in @DIRS).
10 # Use --debug to output path before parsing, this is useful to find files that
41 # Kernel addresses vary by architecture. We can only auto-detect the following
42 # architectures (using `uname -m`). (flag --32-bit overrides auto-detection.)
52 my $squash_by_path = 0; # Summary report grouped by absolute path.
55 my $opt_32bit = 0; # Scan 32-bit kernel.
56 my $page_offset_32bit = 0; # Page offset for 32-bit kernel.
61 '/proc/device-tree',
81 sub help
91 -o, --output-raw=<file> Save results for future processing.
92 -i, --input-raw=<file> Read results from file instead of scanning.
93 --raw Show raw results (default).
94 --suppress-dmesg Do not show dmesg results.
95 --squash-by-path Show one result per unique path.
96 --squash-by-filename Show one result per unique filename.
97 --kernel-config-file=<file> Kernel configuration file (e.g /boot/config)
98 --32-bit Scan 32-bit kernel.
99 --page-offset-32-bit=o Page offset (for 32-bit kernel 0xABCD1234).
100 -d, --debug Display debugging output.
101 -h, --help Display this help and exit.
112 'o|output-raw=s' => \$output_raw,
113 'i|input-raw=s' => \$input_raw,
114 'suppress-dmesg' => \$suppress_dmesg,
115 'squash-by-path' => \$squash_by_path,
116 'squash-by-filename' => \$squash_by_filename,
118 'kernel-config-file=s' => \$kernel_config_file,
119 '32-bit' => \$opt_32bit,
120 'page-offset-32-bit=o' => \$page_offset_32bit,
131 printf "\nSummary reporting only available with --input-raw=<file>\n";
132 printf "(First run scan with --output-raw=<file>.)\n";
144 printf("If you are running a 32-bit architecture you may use:\n");
145 printf("\n\t--32-bit or --page-offset-32-bit=<page offset>\n\n");
147 my $archname = `uname -m`;
148 printf("Machine hardware name (`uname -m`): %s\n", $archname);
163 sub dprint
168 sub is_supported_architecture
173 sub is_32bit
175 # Allow --32-bit or --page-offset-32-bit to override
183 sub is_ix86_32
185 state $arch = `uname -m`;
194 sub is_arch
197 my $arch = `uname -m`;
206 sub is_x86_64
212 sub is_ppc64
220 sub get_kernel_config_option
227 # Allow --kernel-config-file to override.
230 } elsif (-R "/proc/config.gz") {
240 my $file = '/boot/config-' . `uname -r`;
254 system("rm -f $tmp_file");
261 sub option_from_file
280 sub is_false_positive
302 sub is_false_positive_32bit
319 sub get_page_offset
324 # Allow --page-offset-32bit to override.
336 sub is_in_vsyscall_memory_region
348 sub may_leak_address
375 sub get_address_re
386 sub get_x86_64_re
400 sub parse_dmesg
402 open my $cmd, '-|', 'dmesg';
411 # True if we should skip this path.
412 sub skip
414 my ($path) = @_;
417 return 1 if (/^$path$/);
420 my($filename, $dirs, $suffix) = fileparse($path);
428 sub timed_parse_file
433 local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required.
445 sub parse_file
449 if (! -R $file) {
453 if (! -T $file) {
467 # Checks if the actual path name is leaking a kernel address.
468 sub check_path_for_leaks
470 my ($path) = @_;
472 if (may_leak_address($path)) {
473 printf("Path name may contain address: $path\n");
478 sub walk
490 my $path = "$pwd/$file";
491 next if (-l $path);
494 next if (($path =~ /^\/proc\/[0-9]+$/) &&
495 ($path !~ /^\/proc\/1$/));
497 next if (skip($path));
499 check_path_for_leaks($path);
501 if (-d $path) {
502 push @dirs, $path;
506 dprint("parsing: $path\n");
507 timed_parse_file($path);
512 sub format_output
535 squash_by($paths, 'path');
539 sub dump_raw_output
555 sub parse_raw_file
580 sub print_dmesg
598 sub squash_by
611 my $lines = $ref->{$_};
617 sub cache_path
622 my $path = substr($line, 0, $index);
625 add_to_cache($paths, $path, substr($line, $index));
628 sub cache_filename
633 my $path = substr($line, 0, $index);
634 my $filename = basename($path);
640 sub add_to_cache
644 if (!$cache->{$key}) {
645 $cache->{$key} = ();
647 push @{$cache->{$key}}, $value;