aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobin C. Harding <me@tobin.cc>2017-12-06 21:53:41 -0500
committerTobin C. Harding <me@tobin.cc>2018-04-06 18:50:34 -0400
commitf9d2a42dacf96eb8a10259edafec0f66c9921d52 (patch)
tree7e3b59bbfccbb83d204498b0569acb7741b68438
parent87e37588563da905a8506b8922cfba1d71382a64 (diff)
leaking_addresses: add support for kernel config file
Features that rely on the ability to get kernel configuration options are ready to be implemented in script. In preparation for this we can add support for kernel config options as a separate patch to ease review. Add support for locating and parsing kernel configuration file. Signed-off-by: Tobin C. Harding <me@tobin.cc>
-rwxr-xr-xscripts/leaking_addresses.pl66
1 files changed, 65 insertions, 1 deletions
diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl
index 398e534f0e16..b3ffbf8022ce 100755
--- a/scripts/leaking_addresses.pl
+++ b/scripts/leaking_addresses.pl
@@ -41,10 +41,10 @@ my $debug = 0;
41my $raw = 0; 41my $raw = 0;
42my $output_raw = ""; # Write raw results to file. 42my $output_raw = ""; # Write raw results to file.
43my $input_raw = ""; # Read raw results from file instead of scanning. 43my $input_raw = ""; # Read raw results from file instead of scanning.
44
45my $suppress_dmesg = 0; # Don't show dmesg in output. 44my $suppress_dmesg = 0; # Don't show dmesg in output.
46my $squash_by_path = 0; # Summary report grouped by absolute path. 45my $squash_by_path = 0; # Summary report grouped by absolute path.
47my $squash_by_filename = 0; # Summary report grouped by filename. 46my $squash_by_filename = 0; # Summary report grouped by filename.
47my $kernel_config_file = ""; # Kernel configuration file.
48 48
49# Do not parse these files (absolute path). 49# Do not parse these files (absolute path).
50my @skip_parse_files_abs = ('/proc/kmsg', 50my @skip_parse_files_abs = ('/proc/kmsg',
@@ -99,6 +99,7 @@ Options:
99 --suppress-dmesg Do not show dmesg results. 99 --suppress-dmesg Do not show dmesg results.
100 --squash-by-path Show one result per unique path. 100 --squash-by-path Show one result per unique path.
101 --squash-by-filename Show one result per unique filename. 101 --squash-by-filename Show one result per unique filename.
102 --kernel-config-file=<file> Kernel configuration file (e.g /boot/config)
102 -d, --debug Display debugging output. 103 -d, --debug Display debugging output.
103 -h, --help, --version Display this help and exit. 104 -h, --help, --version Display this help and exit.
104 105
@@ -118,6 +119,7 @@ GetOptions(
118 'squash-by-path' => \$squash_by_path, 119 'squash-by-path' => \$squash_by_path,
119 'squash-by-filename' => \$squash_by_filename, 120 'squash-by-filename' => \$squash_by_filename,
120 'raw' => \$raw, 121 'raw' => \$raw,
122 'kernel-config-file=s' => \$kernel_config_file,
121) or help(1); 123) or help(1);
122 124
123help(0) if ($help); 125help(0) if ($help);
@@ -187,6 +189,68 @@ sub is_ppc64
187 return 0; 189 return 0;
188} 190}
189 191
192# Gets config option value from kernel config file.
193# Returns "" on error or if config option not found.
194sub get_kernel_config_option
195{
196 my ($option) = @_;
197 my $value = "";
198 my $tmp_file = "";
199 my @config_files;
200
201 # Allow --kernel-config-file to override.
202 if ($kernel_config_file ne "") {
203 @config_files = ($kernel_config_file);
204 } elsif (-R "/proc/config.gz") {
205 my $tmp_file = "/tmp/tmpkconf";
206
207 if (system("gunzip < /proc/config.gz > $tmp_file")) {
208 dprint "$0: system(gunzip < /proc/config.gz) failed\n";
209 return "";
210 } else {
211 @config_files = ($tmp_file);
212 }
213 } else {
214 my $file = '/boot/config-' . `uname -r`;
215 chomp $file;
216 @config_files = ($file, '/boot/config');
217 }
218
219 foreach my $file (@config_files) {
220 dprint("parsing config file: %s\n", $file);
221 $value = option_from_file($option, $file);
222 if ($value ne "") {
223 last;
224 }
225 }
226
227 if ($tmp_file ne "") {
228 system("rm -f $tmp_file");
229 }
230
231 return $value;
232}
233
234# Parses $file and returns kernel configuration option value.
235sub option_from_file
236{
237 my ($option, $file) = @_;
238 my $str = "";
239 my $val = "";
240
241 open(my $fh, "<", $file) or return "";
242 while (my $line = <$fh> ) {
243 if ($line =~ /^$option/) {
244 ($str, $val) = split /=/, $line;
245 chomp $val;
246 last;
247 }
248 }
249
250 close $fh;
251 return $val;
252}
253
190sub is_false_positive 254sub is_false_positive
191{ 255{
192 my ($match) = @_; 256 my ($match) = @_;