mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Tobin C. Harding" <me@tobin.cc>
To: me@tobin.cc, kaiwan.billimoria@gmail.com
Cc: "Kirill A. Shutemov" <kirill@shutemov.name>,
	Alexander Kapshuk <alexander.kapshuk@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	kernel-hardening@lists.openwall.com
Subject: [PATCH 4/5] leaking_addresses: add support for kernel config file
Date: Thu,  7 Dec 2017 15:32:24 +1100	[thread overview]
Message-ID: <1512621145-4783-5-git-send-email-me@tobin.cc> (raw)
In-Reply-To: <1512621145-4783-1-git-send-email-me@tobin.cc>

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>
Co-Developed-by: Kaiwan N Billimoria <kaiwan.billimoria@gmail.com>
---

get_kernel_config_option() is not super clean, any improvements most welcome.

Kaiwan,

This needs your Signed-off-by tag if you want me to apply it with
the Co-Developed-tag

thanks,
Tobin.

 scripts/leaking_addresses.pl | 64 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 63 insertions(+), 1 deletion(-)

diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl
index cb69ccd4153a..892bfe9e01fe 100755
--- a/scripts/leaking_addresses.pl
+++ b/scripts/leaking_addresses.pl
@@ -42,10 +42,10 @@ my $debug = 0;
 my $raw = 0;
 my $output_raw = "";	# Write raw results to file.
 my $input_raw = "";	# Read raw results from file instead of scanning.
-
 my $suppress_dmesg = 0;		# Don't show dmesg in output.
 my $squash_by_path = 0;		# Summary report grouped by absolute path.
 my $squash_by_filename = 0;	# Summary report grouped by filename.
+my $kernel_config_file = "";	# Kernel configuration file.
 
 # Do not parse these files (absolute path).
 my @skip_parse_files_abs = ('/proc/kmsg',
@@ -100,6 +100,7 @@ Options:
 	      --suppress-dmesg		Do not show dmesg results.
 	      --squash-by-path		Show one result per unique path.
 	      --squash-by-filename	Show one result per unique filename.
+	--kernel-config-file=<file>     Kernel configuration file (e.g /boot/config)
 	-d, --debug			Display debugging output.
 	-h, --help, --versionq		Display this help and exit.
 
@@ -119,6 +120,7 @@ GetOptions(
 	'squash-by-path'        => \$squash_by_path,
 	'squash-by-filename'    => \$squash_by_filename,
 	'raw'                   => \$raw,
+	'kernel-config-file=s'	=> \$kernel_config_file,
 ) or help(1);
 
 help(0) if ($help);
@@ -188,6 +190,66 @@ sub is_ppc64
 	return 0;
 }
 
+# gets config option value from kernel config file
+sub get_kernel_config_option
+{
+	my ($option) = @_;
+	my $value = "";
+	my $tmp_file = "";
+	my @config_files;
+
+	# Allow --kernel-config-file to override.
+	if ($kernel_config_file ne "") {
+		@config_files = ($kernel_config_file);
+	} elsif (-R "/proc/config.gz") {
+		my $tmp_file = "/tmp/tmpkconf";
+
+		if (system("gunzip < /proc/config.gz > $tmp_file")) {
+			dprint "$0: system(gunzip < /proc/config.gz) failed\n";
+		} else {
+			@config_files = ($tmp_file);
+		}
+
+	} else {
+		my $file = '/boot/config-' . `uname -r`;
+		@config_files = ($file, '/boot/config');
+	}
+
+	foreach my $file (@config_files) {
+#		chomp $config_file;
+		$value = option_from_file($option, $file);
+		if ($value ne "") {
+			last;
+		}
+	}
+
+	if ($tmp_file ne "") {
+		system("rm -f $tmp_file");
+	}
+
+	return $value;
+}
+
+# Parses $file and returns kernel configuration option value.
+sub option_from_file
+{
+	my ($option, $file) = @_;
+	my $str = "";
+	my $val = "";
+
+	open(my $fh, "<", $file) or return "";
+	while (my $line = <$fh> ) {
+		if ($line =~ /^$option/) {
+			($str, $val) = split /=/, $line;
+			chomp($val);
+			last;
+		}
+	}
+
+	close $fh;
+	return $val;
+}
+
 sub is_false_positive
 {
 	my ($match) = @_;
-- 
2.7.4

  parent reply	other threads:[~2017-12-07  4:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-07  4:32 [PATCH 0/5] leaking_addresses: support 5 page table level Tobin C. Harding
2017-12-07  4:32 ` [PATCH 1/5] leaking_addresses: remove command examples Tobin C. Harding
2017-12-07  4:32 ` [PATCH 2/5] leaking_addresses: indent dependant options Tobin C. Harding
2017-12-07  4:32 ` [PATCH 3/5] leaking_addresses: add range check for vsyscall memory Tobin C. Harding
2017-12-07  4:32 ` Tobin C. Harding [this message]
2017-12-08  1:55   ` [PATCH 4/5] leaking_addresses: add support for kernel config file Kaiwan N Billimoria
2017-12-07  4:32 ` [PATCH 5/5] leaking_addresses: add support for 5 page table levels Tobin C. Harding

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1512621145-4783-5-git-send-email-me@tobin.cc \
    --to=me@tobin.cc \
    --cc=alexander.kapshuk@gmail.com \
    --cc=kaiwan.billimoria@gmail.com \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=kirill@shutemov.name \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®