* [PATCH v2 1/4] MAINTAINERS: Update LEAKING_ADDRESSES details
2024-02-22 22:00 [PATCH v2 0/4] leaking_addresses: Provide mechanism to scan binary files Kees Cook
@ 2024-02-22 22:00 ` Kees Cook
2024-02-22 22:00 ` [PATCH v2 2/4] leaking_addresses: Use File::Temp for /tmp files Kees Cook
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Kees Cook @ 2024-02-22 22:00 UTC (permalink / raw)
To: Tycho Andersen
Cc: Kees Cook, Tobin C . Harding, Greg Kroah-Hartman, Guixiong Wei,
linux-kernel, linux-hardening
Tobin hasn't been involved lately, and I can step up to be a reviewer
with Tycho. I'll carry changes via the hardening tree.
Signed-off-by: Kees Cook <keescook@chromium.org>
---
Cc: Tycho Andersen <tycho@tycho.pizza>
Cc: Tobin C. Harding <me@tobin.cc>
---
MAINTAINERS | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/MAINTAINERS b/MAINTAINERS
index 216d02a3fed5..cd651c4df019 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12154,11 +12154,11 @@ F: Documentation/scsi/53c700.rst
F: drivers/scsi/53c700*
LEAKING_ADDRESSES
-M: Tobin C. Harding <me@tobin.cc>
M: Tycho Andersen <tycho@tycho.pizza>
+R: Kees Cook <keescook@chromium.org>
L: linux-hardening@vger.kernel.org
S: Maintained
-T: git git://git.kernel.org/pub/scm/linux/kernel/git/tobin/leaks.git
+T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/hardening
F: scripts/leaking_addresses.pl
LED SUBSYSTEM
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v2 2/4] leaking_addresses: Use File::Temp for /tmp files
2024-02-22 22:00 [PATCH v2 0/4] leaking_addresses: Provide mechanism to scan binary files Kees Cook
2024-02-22 22:00 ` [PATCH v2 1/4] MAINTAINERS: Update LEAKING_ADDRESSES details Kees Cook
@ 2024-02-22 22:00 ` Kees Cook
2024-02-22 22:00 ` [PATCH v2 3/4] leaking_addresses: Ignore input device status lines Kees Cook
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Kees Cook @ 2024-02-22 22:00 UTC (permalink / raw)
To: Tycho Andersen
Cc: Kees Cook, Tobin C. Harding, linux-hardening, Greg Kroah-Hartman,
Guixiong Wei, linux-kernel
Instead of using a statically named path in /tmp, use File::Temp to create
(and remove) the temporary file used for parsing /proc/config.gz.
Signed-off-by: Kees Cook <keescook@chromium.org>
---
Cc: Tycho Andersen <tycho@tycho.pizza>
Cc: "Tobin C. Harding" <me@tobin.cc>
Cc: linux-hardening@vger.kernel.org
---
scripts/leaking_addresses.pl | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl
index e695634d153d..dd05fbcf15c5 100755
--- a/scripts/leaking_addresses.pl
+++ b/scripts/leaking_addresses.pl
@@ -23,6 +23,7 @@ use strict;
use POSIX;
use File::Basename;
use File::Spec;
+use File::Temp qw/tempfile/;
use Cwd 'abs_path';
use Term::ANSIColor qw(:constants);
use Getopt::Long qw(:config no_auto_abbrev);
@@ -221,6 +222,7 @@ sub get_kernel_config_option
{
my ($option) = @_;
my $value = "";
+ my $tmp_fh;
my $tmp_file = "";
my @config_files;
@@ -228,7 +230,8 @@ sub get_kernel_config_option
if ($kernel_config_file ne "") {
@config_files = ($kernel_config_file);
} elsif (-R "/proc/config.gz") {
- my $tmp_file = "/tmp/tmpkconf";
+ ($tmp_fh, $tmp_file) = tempfile("config.gz-XXXXXX",
+ UNLINK => 1);
if (system("gunzip < /proc/config.gz > $tmp_file")) {
dprint("system(gunzip < /proc/config.gz) failed\n");
@@ -250,10 +253,6 @@ sub get_kernel_config_option
}
}
- if ($tmp_file ne "") {
- system("rm -f $tmp_file");
- }
-
return $value;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v2 3/4] leaking_addresses: Ignore input device status lines
2024-02-22 22:00 [PATCH v2 0/4] leaking_addresses: Provide mechanism to scan binary files Kees Cook
2024-02-22 22:00 ` [PATCH v2 1/4] MAINTAINERS: Update LEAKING_ADDRESSES details Kees Cook
2024-02-22 22:00 ` [PATCH v2 2/4] leaking_addresses: Use File::Temp for /tmp files Kees Cook
@ 2024-02-22 22:00 ` Kees Cook
2024-02-22 22:00 ` [PATCH v2 4/4] leaking_addresses: Provide mechanism to scan binary files Kees Cook
2024-02-22 23:55 ` [PATCH v2 0/4] " Tycho Andersen
4 siblings, 0 replies; 6+ messages in thread
From: Kees Cook @ 2024-02-22 22:00 UTC (permalink / raw)
To: Tycho Andersen
Cc: Kees Cook, Tobin C. Harding, linux-hardening, Greg Kroah-Hartman,
Guixiong Wei, linux-kernel
These are false positives from the input subsystem:
/proc/bus/input/devices: B: KEY=402000000 3803078f800d001 feffffdfffefffff fffffffffffffffe
/sys/devices/platform/i8042/serio0/input/input1/uevent: KEY=402000000 3803078f800d001 feffffdfffefffff fffffffffffffffe
/sys/devices/platform/i8042/serio0/input/input1/capabilities/key: 402000000 3803078f800d001 feffffdf
Pass in the filename for more context and expand the "ignored pattern"
matcher to notice these.
Signed-off-by: Kees Cook <keescook@chromium.org>
---
Cc: Tycho Andersen <tycho@tycho.pizza>
Cc: "Tobin C. Harding" <me@tobin.cc>
Cc: linux-hardening@vger.kernel.org
---
scripts/leaking_addresses.pl | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl
index dd05fbcf15c5..73cfcc5c8854 100755
--- a/scripts/leaking_addresses.pl
+++ b/scripts/leaking_addresses.pl
@@ -284,9 +284,10 @@ sub is_false_positive
return is_false_positive_32bit($match);
}
- # 64 bit false positives.
-
- if ($match =~ '\b(0x)?(f|F){16}\b' or
+ # Ignore 64 bit false positives:
+ # 0xfffffffffffffff[0-f]
+ # 0x0000000000000000
+ if ($match =~ '\b(0x)?(f|F){15}[0-9a-f]\b' or
$match =~ '\b(0x)?0{16}\b') {
return 1;
}
@@ -303,7 +304,7 @@ sub is_false_positive_32bit
my ($match) = @_;
state $page_offset = get_page_offset();
- if ($match =~ '\b(0x)?(f|F){8}\b') {
+ if ($match =~ '\b(0x)?(f|F){7}[0-9a-f]\b') {
return 1;
}
@@ -346,18 +347,23 @@ sub is_in_vsyscall_memory_region
# True if argument potentially contains a kernel address.
sub may_leak_address
{
- my ($line) = @_;
+ my ($path, $line) = @_;
my $address_re;
- # Signal masks.
+ # Ignore Signal masks.
if ($line =~ '^SigBlk:' or
$line =~ '^SigIgn:' or
$line =~ '^SigCgt:') {
return 0;
}
- if ($line =~ '\bKEY=[[:xdigit:]]{14} [[:xdigit:]]{16} [[:xdigit:]]{16}\b' or
- $line =~ '\b[[:xdigit:]]{14} [[:xdigit:]]{16} [[:xdigit:]]{16}\b') {
+ # Ignore input device reporting.
+ # /proc/bus/input/devices: B: KEY=402000000 3803078f800d001 feffffdfffefffff fffffffffffffffe
+ # /sys/devices/platform/i8042/serio0/input/input1/uevent: KEY=402000000 3803078f800d001 feffffdfffefffff fffffffffffffffe
+ # /sys/devices/platform/i8042/serio0/input/input1/capabilities/key: 402000000 3803078f800d001 feffffdfffefffff fffffffffffffffe
+ if ($line =~ '\bKEY=[[:xdigit:]]{9,14} [[:xdigit:]]{16} [[:xdigit:]]{16}\b' or
+ ($path =~ '\bkey$' and
+ $line =~ '\b[[:xdigit:]]{9,14} [[:xdigit:]]{16} [[:xdigit:]]{16}\b')) {
return 0;
}
@@ -400,7 +406,7 @@ sub parse_dmesg
{
open my $cmd, '-|', 'dmesg';
while (<$cmd>) {
- if (may_leak_address($_)) {
+ if (may_leak_address("dmesg", $_)) {
print 'dmesg: ' . $_;
}
}
@@ -456,7 +462,7 @@ sub parse_file
open my $fh, "<", $file or return;
while ( <$fh> ) {
chomp;
- if (may_leak_address($_)) {
+ if (may_leak_address($file, $_)) {
printf("$file: $_\n");
}
}
@@ -468,7 +474,7 @@ sub check_path_for_leaks
{
my ($path) = @_;
- if (may_leak_address($path)) {
+ if (may_leak_address($path, $path)) {
printf("Path name may contain address: $path\n");
}
}
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v2 4/4] leaking_addresses: Provide mechanism to scan binary files
2024-02-22 22:00 [PATCH v2 0/4] leaking_addresses: Provide mechanism to scan binary files Kees Cook
` (2 preceding siblings ...)
2024-02-22 22:00 ` [PATCH v2 3/4] leaking_addresses: Ignore input device status lines Kees Cook
@ 2024-02-22 22:00 ` Kees Cook
2024-02-22 23:55 ` [PATCH v2 0/4] " Tycho Andersen
4 siblings, 0 replies; 6+ messages in thread
From: Kees Cook @ 2024-02-22 22:00 UTC (permalink / raw)
To: Tycho Andersen
Cc: Kees Cook, Greg Kroah-Hartman, Tobin C. Harding, Guixiong Wei,
linux-hardening, linux-kernel
Introduce --kallsyms argument for scanning binary files for known symbol
addresses. This would have found the exposure in /sys/kernel/notes:
$ scripts/leaking_addresses.pl --kallsyms=<(sudo cat /proc/kallsyms)
/sys/kernel/notes: hypercall_page @ 156
/sys/kernel/notes: xen_hypercall_set_trap_table @ 156
/sys/kernel/notes: startup_xen @ 132
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
Cc: "Tobin C. Harding" <me@tobin.cc>
Cc: Tycho Andersen <tycho@tycho.pizza>
Cc: Guixiong Wei <guixiongwei@gmail.com>
Cc: linux-hardening@vger.kernel.org
---
scripts/leaking_addresses.pl | 53 ++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl
index 73cfcc5c8854..8e992b18bcd9 100755
--- a/scripts/leaking_addresses.pl
+++ b/scripts/leaking_addresses.pl
@@ -52,10 +52,13 @@ 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 $kallsyms_file = ""; # Kernel symbols file.
my $kernel_config_file = ""; # Kernel configuration file.
my $opt_32bit = 0; # Scan 32-bit kernel.
my $page_offset_32bit = 0; # Page offset for 32-bit kernel.
+my @kallsyms = ();
+
# Skip these absolute paths.
my @skip_abs = (
'/proc/kmsg',
@@ -96,6 +99,8 @@ Options:
--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)
+ --kallsyms=<file> Read kernel symbol addresses from file (for
+ scanning binary files).
--32-bit Scan 32-bit kernel.
--page-offset-32-bit=o Page offset (for 32-bit kernel 0xABCD1234).
-d, --debug Display debugging output.
@@ -116,6 +121,7 @@ GetOptions(
'squash-by-path' => \$squash_by_path,
'squash-by-filename' => \$squash_by_filename,
'raw' => \$raw,
+ 'kallsyms=s' => \$kallsyms_file,
'kernel-config-file=s' => \$kernel_config_file,
'32-bit' => \$opt_32bit,
'page-offset-32-bit=o' => \$page_offset_32bit,
@@ -156,6 +162,25 @@ if ($output_raw) {
select $fh;
}
+if ($kallsyms_file) {
+ open my $fh, '<', $kallsyms_file or die "$0: $kallsyms_file: $!\n";
+ while (<$fh>) {
+ chomp;
+ my @entry = split / /, $_;
+ my $addr_text = $entry[0];
+ if ($addr_text !~ /^0/) {
+ # TODO: Why is hex() so impossibly slow?
+ my $addr = hex($addr_text);
+ my $symbol = $entry[2];
+ # Only keep kernel text addresses.
+ my $long = pack("J", $addr);
+ my $entry = [$long, $symbol];
+ push @kallsyms, $entry;
+ }
+ }
+ close $fh;
+}
+
parse_dmesg();
walk(@DIRS);
@@ -447,6 +472,25 @@ sub timed_parse_file
}
}
+sub parse_binary
+{
+ my ($file) = @_;
+
+ open my $fh, "<:raw", $file or return;
+ local $/ = undef;
+ my $bytes = <$fh>;
+ close $fh;
+
+ foreach my $entry (@kallsyms) {
+ my $addr = $entry->[0];
+ my $symbol = $entry->[1];
+ my $offset = index($bytes, $addr);
+ if ($offset != -1) {
+ printf("$file: $symbol @ $offset\n");
+ }
+ }
+}
+
sub parse_file
{
my ($file) = @_;
@@ -456,6 +500,15 @@ sub parse_file
}
if (! -T $file) {
+ if ($file =~ m|^/sys/kernel/btf/| or
+ $file =~ m|^/sys/devices/pci| or
+ $file =~ m|^/sys/firmware/efi/efivars/| or
+ $file =~ m|^/proc/bus/pci/|) {
+ return;
+ }
+ if (scalar @kallsyms > 0) {
+ parse_binary($file);
+ }
return;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v2 0/4] leaking_addresses: Provide mechanism to scan binary files
2024-02-22 22:00 [PATCH v2 0/4] leaking_addresses: Provide mechanism to scan binary files Kees Cook
` (3 preceding siblings ...)
2024-02-22 22:00 ` [PATCH v2 4/4] leaking_addresses: Provide mechanism to scan binary files Kees Cook
@ 2024-02-22 23:55 ` Tycho Andersen
4 siblings, 0 replies; 6+ messages in thread
From: Tycho Andersen @ 2024-02-22 23:55 UTC (permalink / raw)
To: Kees Cook
Cc: Tobin C. Harding, Greg Kroah-Hartman, Guixiong Wei, linux-kernel,
linux-hardening
Hi Kees,
On Thu, Feb 22, 2024 at 02:00:47PM -0800, Kees Cook wrote:
> Hi,
>
> Since I was in this script for the binary file scanning, I did other
> clean-ups and tweaked the MAINTAINERS file per Tycho's suggestion.
Thanks, the whole series is:
Reviewed-by: Tycho Andersen <tandersen@netflix.com>
I also pinged Tobin off-list with this thread, perhaps he will respond
here.
Tycho
^ permalink raw reply [flat|nested] 6+ messages in thread