Re: [PATCH] leaking_addresses: add generic 32-bit support

2017-12-30 Thread Tobin C. Harding
On Tue, Dec 26, 2017 at 07:48:55AM +0530, Kaiwan N Billimoria wrote:
> The script attempts to detect the architecture it's running upon; as of now,
> we explicitly support x86_64, PPC64 and x86_32.
> If it's one of them, we proceed "normally". If we fail to detect the arch,
> we fallback to 64-bit scanning, unless the user has passed either of these
> option switches: "--opt-32bit" and/or "--page-offset-32bit=".
> 
> If so, we switch to scanning for leaked addresses based on the value of
> PAGE_OFFSET (via an auto-detected or fallback mechanism).
> 
> As of now, we have code (or "rules") to detect special cases for x86_64 and 
> PPC64
> (in the get_address_re sub). Also, we now have also builtin "stubs", for lack 
> of a better term, where additional rules for other 64-bit arch's can be 
> plugged into the code,
> in future, as applicable.
> 
> Signed-off-by: Kaiwan N Billimoria 
> 
> ---
>  scripts/leaking_addresses.pl | 190 
> +++
>  1 file changed, 156 insertions(+), 34 deletions(-)
> 
> This patch is based on Tobin's suggestions and my replies to them (see prev 
> email in this thread).

Hi,

Can you resend this with a version number please. Also can you include what 
testing you have done
please. I'm away on Christmas holidays at the moment but I'll review soon as 
I'm back.

Thanks,
Tobin.


Re: [PATCH] leaking_addresses: add generic 32-bit support

2017-12-30 Thread Tobin C. Harding
On Tue, Dec 26, 2017 at 07:48:55AM +0530, Kaiwan N Billimoria wrote:
> The script attempts to detect the architecture it's running upon; as of now,
> we explicitly support x86_64, PPC64 and x86_32.
> If it's one of them, we proceed "normally". If we fail to detect the arch,
> we fallback to 64-bit scanning, unless the user has passed either of these
> option switches: "--opt-32bit" and/or "--page-offset-32bit=".
> 
> If so, we switch to scanning for leaked addresses based on the value of
> PAGE_OFFSET (via an auto-detected or fallback mechanism).
> 
> As of now, we have code (or "rules") to detect special cases for x86_64 and 
> PPC64
> (in the get_address_re sub). Also, we now have also builtin "stubs", for lack 
> of a better term, where additional rules for other 64-bit arch's can be 
> plugged into the code,
> in future, as applicable.
> 
> Signed-off-by: Kaiwan N Billimoria 
> 
> ---
>  scripts/leaking_addresses.pl | 190 
> +++
>  1 file changed, 156 insertions(+), 34 deletions(-)
> 
> This patch is based on Tobin's suggestions and my replies to them (see prev 
> email in this thread).

Hi,

Can you resend this with a version number please. Also can you include what 
testing you have done
please. I'm away on Christmas holidays at the moment but I'll review soon as 
I'm back.

Thanks,
Tobin.


Re: [PATCH] leaking_addresses: add generic 32-bit support

2017-12-25 Thread Kaiwan N Billimoria
The script attempts to detect the architecture it's running upon; as of now,
we explicitly support x86_64, PPC64 and x86_32.
If it's one of them, we proceed "normally". If we fail to detect the arch,
we fallback to 64-bit scanning, unless the user has passed either of these
option switches: "--opt-32bit" and/or "--page-offset-32bit=".

If so, we switch to scanning for leaked addresses based on the value of
PAGE_OFFSET (via an auto-detected or fallback mechanism).

As of now, we have code (or "rules") to detect special cases for x86_64 and 
PPC64
(in the get_address_re sub). Also, we now have also builtin "stubs", for lack 
of a better term, where additional rules for other 64-bit arch's can be plugged 
into the code,
in future, as applicable.

Signed-off-by: Kaiwan N Billimoria 

---
 scripts/leaking_addresses.pl | 190 +++
 1 file changed, 156 insertions(+), 34 deletions(-)

This patch is based on Tobin's suggestions and my replies to them (see prev 
email in this thread).


diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl
index a29e13e577a7..b0807b3a3c7c 100755
--- a/scripts/leaking_addresses.pl
+++ b/scripts/leaking_addresses.pl
@@ -1,10 +1,10 @@
 #!/usr/bin/env perl
 #
 # (c) 2017 Tobin C. Harding 
-
+# (c) 2017 Kaiwan N Billimoria 
 # Licensed under the terms of the GNU GPL License version 2
 #
-# leaking_addresses.pl: Scan 64 bit kernel for potential leaking addresses.
+# leaking_addresses.pl: Scan kernel for potential leaking addresses.
 #  - Scans dmesg output.
 #  - Walks directory tree and parses each file (for each directory in @DIRS).
 #
@@ -32,11 +32,6 @@ my @DIRS = ('/proc', '/sys');
 # Timer for parsing each file, in seconds.
 my $TIMEOUT = 10;
 
-# Script can only grep for kernel addresses on the following architectures. If
-# your architecture is not listed here and has a grep'able kernel address 
please
-# consider submitting a patch.
-my @SUPPORTED_ARCHITECTURES = ('x86_64', 'ppc64');
-
 # Command line options.
 my $help = 0;
 my $debug = 0;
@@ -48,7 +43,9 @@ 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.
+my $opt_32_bit = 0;# Detect (only) 32-bit kernel leaking addresses.
+my $page_offset_32bit = 0; # 32-bit: value of CONFIG_PAGE_OFFSET.
+my $kernel_config_file = "";   # Kernel configuration file.
 
 # Do not parse these files (absolute path).
 my @skip_parse_files_abs = ('/proc/kmsg',
@@ -104,10 +101,12 @@ Options:
  --squash-by-path  Show one result per unique path.
  --squash-by-filename  Show one result per unique filename.
--kernel-config-file= Kernel configuration file (e.g 
/boot/config)
+   --opt-32bit Detect (only) 32-bit kernel leaking 
addresses.
+   --page-offset-32bit=   PAGE_OFFSET value (for 32-bit kernels).
-d, --debug Display debugging output.
-   -h, --help, --versionq  Display this help and exit.
+   -h, --help, --version   Display this help and exit.
 
-Scans the running (64 bit) kernel for potential leaking addresses.
+Scans the running kernel for potential leaking addresses.
 
 EOM
exit($exitcode);
@@ -123,7 +122,9 @@ GetOptions(
'squash-by-path'=> \$squash_by_path,
'squash-by-filename'=> \$squash_by_filename,
'raw'   => \$raw,
-   'kernel-config-file=s'  => \$kernel_config_file,
+   'opt-32bit' => \$opt_32_bit,
+   'page-offset-32bit=o'   => \$page_offset_32bit,
+   'kernel-config-file=s'  => \$kernel_config_file,
 ) or help(1);
 
 help(0) if ($help);
@@ -139,16 +140,15 @@ if (!$input_raw and ($squash_by_path or 
$squash_by_filename)) {
exit(128);
 }
 
-if (!is_supported_architecture()) {
-   printf "\nScript does not support your architecture, sorry.\n";
-   printf "\nCurrently we support: \n\n";
-   foreach(@SUPPORTED_ARCHITECTURES) {
-   printf "\t%s\n", $_;
-   }
+show_detected_architecture() if $debug;
 
-   my $archname = $Config{archname};
-   printf "\n\$ perl -MConfig -e \'print \"\$Config{archname}\\n\"\'\n";
-   printf "%s\n", $archname;
+if (!is_known_architecture()) {
+   printf STDERR "\nFATAL: Script does not recognize your architecture\n";
+
+   my $arch = `uname -m`;
+   chomp $arch;
+   printf "\n\$ uname -m\n";
+   printf "%s\n", $arch;
 
exit(129);
 }
@@ -168,21 +168,45 @@ sub dprint
printf(STDERR @_) if $debug;
 }
 
-sub is_supported_architecture
+sub is_known_architecture
 {
-   return (is_x86_64() or is_ppc64());
+   return (is_64bit() or is_32bit());

Re: [PATCH] leaking_addresses: add generic 32-bit support

2017-12-25 Thread Kaiwan N Billimoria
The script attempts to detect the architecture it's running upon; as of now,
we explicitly support x86_64, PPC64 and x86_32.
If it's one of them, we proceed "normally". If we fail to detect the arch,
we fallback to 64-bit scanning, unless the user has passed either of these
option switches: "--opt-32bit" and/or "--page-offset-32bit=".

If so, we switch to scanning for leaked addresses based on the value of
PAGE_OFFSET (via an auto-detected or fallback mechanism).

As of now, we have code (or "rules") to detect special cases for x86_64 and 
PPC64
(in the get_address_re sub). Also, we now have also builtin "stubs", for lack 
of a better term, where additional rules for other 64-bit arch's can be plugged 
into the code,
in future, as applicable.

Signed-off-by: Kaiwan N Billimoria 

---
 scripts/leaking_addresses.pl | 190 +++
 1 file changed, 156 insertions(+), 34 deletions(-)

This patch is based on Tobin's suggestions and my replies to them (see prev 
email in this thread).


diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl
index a29e13e577a7..b0807b3a3c7c 100755
--- a/scripts/leaking_addresses.pl
+++ b/scripts/leaking_addresses.pl
@@ -1,10 +1,10 @@
 #!/usr/bin/env perl
 #
 # (c) 2017 Tobin C. Harding 
-
+# (c) 2017 Kaiwan N Billimoria 
 # Licensed under the terms of the GNU GPL License version 2
 #
-# leaking_addresses.pl: Scan 64 bit kernel for potential leaking addresses.
+# leaking_addresses.pl: Scan kernel for potential leaking addresses.
 #  - Scans dmesg output.
 #  - Walks directory tree and parses each file (for each directory in @DIRS).
 #
@@ -32,11 +32,6 @@ my @DIRS = ('/proc', '/sys');
 # Timer for parsing each file, in seconds.
 my $TIMEOUT = 10;
 
-# Script can only grep for kernel addresses on the following architectures. If
-# your architecture is not listed here and has a grep'able kernel address 
please
-# consider submitting a patch.
-my @SUPPORTED_ARCHITECTURES = ('x86_64', 'ppc64');
-
 # Command line options.
 my $help = 0;
 my $debug = 0;
@@ -48,7 +43,9 @@ 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.
+my $opt_32_bit = 0;# Detect (only) 32-bit kernel leaking addresses.
+my $page_offset_32bit = 0; # 32-bit: value of CONFIG_PAGE_OFFSET.
+my $kernel_config_file = "";   # Kernel configuration file.
 
 # Do not parse these files (absolute path).
 my @skip_parse_files_abs = ('/proc/kmsg',
@@ -104,10 +101,12 @@ Options:
  --squash-by-path  Show one result per unique path.
  --squash-by-filename  Show one result per unique filename.
--kernel-config-file= Kernel configuration file (e.g 
/boot/config)
+   --opt-32bit Detect (only) 32-bit kernel leaking 
addresses.
+   --page-offset-32bit=   PAGE_OFFSET value (for 32-bit kernels).
-d, --debug Display debugging output.
-   -h, --help, --versionq  Display this help and exit.
+   -h, --help, --version   Display this help and exit.
 
-Scans the running (64 bit) kernel for potential leaking addresses.
+Scans the running kernel for potential leaking addresses.
 
 EOM
exit($exitcode);
@@ -123,7 +122,9 @@ GetOptions(
'squash-by-path'=> \$squash_by_path,
'squash-by-filename'=> \$squash_by_filename,
'raw'   => \$raw,
-   'kernel-config-file=s'  => \$kernel_config_file,
+   'opt-32bit' => \$opt_32_bit,
+   'page-offset-32bit=o'   => \$page_offset_32bit,
+   'kernel-config-file=s'  => \$kernel_config_file,
 ) or help(1);
 
 help(0) if ($help);
@@ -139,16 +140,15 @@ if (!$input_raw and ($squash_by_path or 
$squash_by_filename)) {
exit(128);
 }
 
-if (!is_supported_architecture()) {
-   printf "\nScript does not support your architecture, sorry.\n";
-   printf "\nCurrently we support: \n\n";
-   foreach(@SUPPORTED_ARCHITECTURES) {
-   printf "\t%s\n", $_;
-   }
+show_detected_architecture() if $debug;
 
-   my $archname = $Config{archname};
-   printf "\n\$ perl -MConfig -e \'print \"\$Config{archname}\\n\"\'\n";
-   printf "%s\n", $archname;
+if (!is_known_architecture()) {
+   printf STDERR "\nFATAL: Script does not recognize your architecture\n";
+
+   my $arch = `uname -m`;
+   chomp $arch;
+   printf "\n\$ uname -m\n";
+   printf "%s\n", $arch;
 
exit(129);
 }
@@ -168,21 +168,45 @@ sub dprint
printf(STDERR @_) if $debug;
 }
 
-sub is_supported_architecture
+sub is_known_architecture
 {
-   return (is_x86_64() or is_ppc64());
+   return (is_64bit() or is_32bit());
 }
 
-sub is_x86_64
+sub is_32bit
 {
-   my $archname = 

Re: [PATCH] leaking_addresses: add generic 32-bit support

2017-12-25 Thread Kaiwan N Billimoria
Hey, Merry Xmas all !!   :-)

Re inline below,
Updated patch to follow..

On Mon, 18 Dec 2017 16:57:46 +1100
"Tobin C. Harding"  wrote:

> On Mon, Dec 18, 2017 at 09:24:47AM +0530, kaiwan.billimo...@gmail.com
> wrote:
> > The script attempts to detect the architecture it's running upon;
> > as of now, we explicitly support x86_64, PPC64 and x86_32.
> > If it's one of them, we proceed "normally". If we fail to detect
> > the arch, we fallback to 64-bit scanning, unless the user has
> > passed either of these option switches: "--32-bit" and/or
> > "--page-offset-32bit=".
> > 
> > If so, we switch to scanning for leaked addresses based on the
> > value of PAGE_OFFSET (via an auto-detected or fallback mechanism).
> > 
> > As of now, we have code (or "rules") to detect special cases for
> > x86_64 and ppc64 (in the get_address_re sub). Also, we now have
> > also builtin "stubs", for lack of a better term, where additional
> > rules for other 64-bit arch's can be plugged in, in future, as
> > applicable.
> > 
> > Signed-off-by: Kaiwan N Billimoria 
> > ---
> > 
> > This is a patch based on Tobin's latest tree, 'leaks' branch. 
> > Applies on top of commit 6c3942594657 (leaking_addresses: add
> > support for 5 page table levels (origin/leaks))  
> 
> That commit is not the tip of the branch. leaks branch is currently at
> 
> commit 266891c62bf0 (leaking_addresses: add support for 5 page table
> levels)
> 
> > 
> > Thanks,
> > Kaiwan.
> > 
> >  scripts/leaking_addresses.pl | 213
> > +-- 1 file changed, 184
> > insertions(+), 29 deletions(-)
> > 
> > diff --git a/scripts/leaking_addresses.pl
> > b/scripts/leaking_addresses.pl index a29e13e577a7..a667f243c95b
> > 100755 --- a/scripts/leaking_addresses.pl
> > +++ b/scripts/leaking_addresses.pl
> > @@ -1,10 +1,10 @@
> >  #!/usr/bin/env perl
> >  #
> >  # (c) 2017 Tobin C. Harding 
> > -
> > +# (c) 2017 Kaiwan N Billimoria 
> >  # Licensed under the terms of the GNU GPL License version 2
> >  #
> > -# leaking_addresses.pl: Scan 64 bit kernel for potential leaking
> > addresses. +# leaking_addresses.pl: Scan kernel for potential
> > leaking addresses. #  - Scans dmesg output.
> >  #  - Walks directory tree and parses each file (for each directory
> > in @DIRS). #
> > @@ -35,7 +35,7 @@ my $TIMEOUT = 10;
> >  # Script can only grep for kernel addresses on the following
> > architectures. If # your architecture is not listed here and has a
> > grep'able kernel address please # consider submitting a patch.
> > -my @SUPPORTED_ARCHITECTURES = ('x86_64', 'ppc64');
> > +my @SUPPORTED_ARCHITECTURES = ('x86_64', 'ppc64', 'i[3456]86');
> >  
> >  # Command line options.
> >  my $help = 0;
> > @@ -48,7 +48,9 @@ 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.
> > +my $opt_32_bit = 0;# Detect 32-bit kernel leaking
> > addresses. +my $page_offset_32bit = 0; # 32-bit: value of
> > CONFIG_PAGE_OFFSET. +my $kernel_config_file = "";   # Kernel
> > configuration file. 
> >  # Do not parse these files (absolute path).
> >  my @skip_parse_files_abs = ('/proc/kmsg',
> > @@ -97,17 +99,19 @@ Version: $V
> >  
> >  Options:
> >  
> > -   -o, --output-raw= Save results for future
> > processing.
> > -   -i, --input-raw=  Read results from file
> > instead of scanning.
> > - --raw Show raw results (default).
> > - --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= Kernel configuration file
> > (e.g /boot/config)
> > -   -d, --debug Display debugging output.
> > -   -h, --help, --versionq  Display this help and exit.
> > +   -o, --output-raw= Save results for future
> > processing.
> > +   -i, --input-raw=  Read results from file
> > instead of scanning.
> > +   --raw   Show raw results
> > (default).
> > +   --suppress-dmesgDo not show dmesg
> > results.
> > +   --squash-by-pathShow one result per
> > unique path.
> > +   --squash-by-filenameShow one result per
> > unique filename.
> > +   --32-bitDetect 32-bit kernel
> > leaking addresses.
> > +   --page-offset-32bit=   PAGE_OFFSET value (for
> > 32-bit kernels).
> > +   --kernel-config-file= Kernel configuration file
> > (e.g /boot/config).
> > +   -d, --debug 

Re: [PATCH] leaking_addresses: add generic 32-bit support

2017-12-25 Thread Kaiwan N Billimoria
Hey, Merry Xmas all !!   :-)

Re inline below,
Updated patch to follow..

On Mon, 18 Dec 2017 16:57:46 +1100
"Tobin C. Harding"  wrote:

> On Mon, Dec 18, 2017 at 09:24:47AM +0530, kaiwan.billimo...@gmail.com
> wrote:
> > The script attempts to detect the architecture it's running upon;
> > as of now, we explicitly support x86_64, PPC64 and x86_32.
> > If it's one of them, we proceed "normally". If we fail to detect
> > the arch, we fallback to 64-bit scanning, unless the user has
> > passed either of these option switches: "--32-bit" and/or
> > "--page-offset-32bit=".
> > 
> > If so, we switch to scanning for leaked addresses based on the
> > value of PAGE_OFFSET (via an auto-detected or fallback mechanism).
> > 
> > As of now, we have code (or "rules") to detect special cases for
> > x86_64 and ppc64 (in the get_address_re sub). Also, we now have
> > also builtin "stubs", for lack of a better term, where additional
> > rules for other 64-bit arch's can be plugged in, in future, as
> > applicable.
> > 
> > Signed-off-by: Kaiwan N Billimoria 
> > ---
> > 
> > This is a patch based on Tobin's latest tree, 'leaks' branch. 
> > Applies on top of commit 6c3942594657 (leaking_addresses: add
> > support for 5 page table levels (origin/leaks))  
> 
> That commit is not the tip of the branch. leaks branch is currently at
> 
> commit 266891c62bf0 (leaking_addresses: add support for 5 page table
> levels)
> 
> > 
> > Thanks,
> > Kaiwan.
> > 
> >  scripts/leaking_addresses.pl | 213
> > +-- 1 file changed, 184
> > insertions(+), 29 deletions(-)
> > 
> > diff --git a/scripts/leaking_addresses.pl
> > b/scripts/leaking_addresses.pl index a29e13e577a7..a667f243c95b
> > 100755 --- a/scripts/leaking_addresses.pl
> > +++ b/scripts/leaking_addresses.pl
> > @@ -1,10 +1,10 @@
> >  #!/usr/bin/env perl
> >  #
> >  # (c) 2017 Tobin C. Harding 
> > -
> > +# (c) 2017 Kaiwan N Billimoria 
> >  # Licensed under the terms of the GNU GPL License version 2
> >  #
> > -# leaking_addresses.pl: Scan 64 bit kernel for potential leaking
> > addresses. +# leaking_addresses.pl: Scan kernel for potential
> > leaking addresses. #  - Scans dmesg output.
> >  #  - Walks directory tree and parses each file (for each directory
> > in @DIRS). #
> > @@ -35,7 +35,7 @@ my $TIMEOUT = 10;
> >  # Script can only grep for kernel addresses on the following
> > architectures. If # your architecture is not listed here and has a
> > grep'able kernel address please # consider submitting a patch.
> > -my @SUPPORTED_ARCHITECTURES = ('x86_64', 'ppc64');
> > +my @SUPPORTED_ARCHITECTURES = ('x86_64', 'ppc64', 'i[3456]86');
> >  
> >  # Command line options.
> >  my $help = 0;
> > @@ -48,7 +48,9 @@ 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.
> > +my $opt_32_bit = 0;# Detect 32-bit kernel leaking
> > addresses. +my $page_offset_32bit = 0; # 32-bit: value of
> > CONFIG_PAGE_OFFSET. +my $kernel_config_file = "";   # Kernel
> > configuration file. 
> >  # Do not parse these files (absolute path).
> >  my @skip_parse_files_abs = ('/proc/kmsg',
> > @@ -97,17 +99,19 @@ Version: $V
> >  
> >  Options:
> >  
> > -   -o, --output-raw= Save results for future
> > processing.
> > -   -i, --input-raw=  Read results from file
> > instead of scanning.
> > - --raw Show raw results (default).
> > - --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= Kernel configuration file
> > (e.g /boot/config)
> > -   -d, --debug Display debugging output.
> > -   -h, --help, --versionq  Display this help and exit.
> > +   -o, --output-raw= Save results for future
> > processing.
> > +   -i, --input-raw=  Read results from file
> > instead of scanning.
> > +   --raw   Show raw results
> > (default).
> > +   --suppress-dmesgDo not show dmesg
> > results.
> > +   --squash-by-pathShow one result per
> > unique path.
> > +   --squash-by-filenameShow one result per
> > unique filename.
> > +   --32-bitDetect 32-bit kernel
> > leaking addresses.
> > +   --page-offset-32bit=   PAGE_OFFSET value (for
> > 32-bit kernels).
> > +   --kernel-config-file= Kernel configuration file
> > (e.g /boot/config).
> > +   -d, --debug Display debugging output.
> > +   -h, --help, --version   Display this help and
> 

Re: [PATCH] leaking_addresses: add generic 32-bit support

2017-12-17 Thread Tobin C. Harding
On Mon, Dec 18, 2017 at 09:24:47AM +0530, kaiwan.billimo...@gmail.com wrote:
> The script attempts to detect the architecture it's running upon; as of now,
> we explicitly support x86_64, PPC64 and x86_32.
> If it's one of them, we proceed "normally". If we fail to detect the arch,
> we fallback to 64-bit scanning, unless the user has passed either of these
> option switches: "--32-bit" and/or "--page-offset-32bit=".
> 
> If so, we switch to scanning for leaked addresses based on the value of
> PAGE_OFFSET (via an auto-detected or fallback mechanism).
> 
> As of now, we have code (or "rules") to detect special cases for x86_64 and 
> ppc64
> (in the get_address_re sub). Also, we now have also builtin "stubs", for lack 
> of a better term,
> where additional rules for other 64-bit arch's can be plugged in, in future,
> as applicable.
> 
> Signed-off-by: Kaiwan N Billimoria 
> ---
> 
> This is a patch based on Tobin's latest tree, 'leaks' branch. 
> Applies on top of commit 6c3942594657 (leaking_addresses: add support for 5 
> page table levels (origin/leaks))

That commit is not the tip of the branch. leaks branch is currently at

commit 266891c62bf0 (leaking_addresses: add support for 5 page table levels)

> 
> Thanks,
> Kaiwan.
> 
>  scripts/leaking_addresses.pl | 213 
> +--
>  1 file changed, 184 insertions(+), 29 deletions(-)
> 
> diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl
> index a29e13e577a7..a667f243c95b 100755
> --- a/scripts/leaking_addresses.pl
> +++ b/scripts/leaking_addresses.pl
> @@ -1,10 +1,10 @@
>  #!/usr/bin/env perl
>  #
>  # (c) 2017 Tobin C. Harding 
> -
> +# (c) 2017 Kaiwan N Billimoria 
>  # Licensed under the terms of the GNU GPL License version 2
>  #
> -# leaking_addresses.pl: Scan 64 bit kernel for potential leaking addresses.
> +# leaking_addresses.pl: Scan kernel for potential leaking addresses.
>  #  - Scans dmesg output.
>  #  - Walks directory tree and parses each file (for each directory in @DIRS).
>  #
> @@ -35,7 +35,7 @@ my $TIMEOUT = 10;
>  # Script can only grep for kernel addresses on the following architectures. 
> If
>  # your architecture is not listed here and has a grep'able kernel address 
> please
>  # consider submitting a patch.
> -my @SUPPORTED_ARCHITECTURES = ('x86_64', 'ppc64');
> +my @SUPPORTED_ARCHITECTURES = ('x86_64', 'ppc64', 'i[3456]86');
>  
>  # Command line options.
>  my $help = 0;
> @@ -48,7 +48,9 @@ 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.
> +my $opt_32_bit = 0;# Detect 32-bit kernel leaking addresses.
> +my $page_offset_32bit = 0; # 32-bit: value of CONFIG_PAGE_OFFSET.
> +my $kernel_config_file = "";   # Kernel configuration file.
>  
>  # Do not parse these files (absolute path).
>  my @skip_parse_files_abs = ('/proc/kmsg',
> @@ -97,17 +99,19 @@ Version: $V
>  
>  Options:
>  
> -   -o, --output-raw= Save results for future processing.
> -   -i, --input-raw=  Read results from file instead of 
> scanning.
> - --raw Show raw results (default).
> - --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= Kernel configuration file (e.g 
> /boot/config)
> -   -d, --debug Display debugging output.
> -   -h, --help, --versionq  Display this help and exit.
> +   -o, --output-raw= Save results for future processing.
> +   -i, --input-raw=  Read results from file instead of 
> scanning.
> +   --raw   Show raw results (default).
> +   --suppress-dmesgDo not show dmesg results.
> +   --squash-by-pathShow one result per unique path.
> +   --squash-by-filenameShow one result per unique 
> filename.
> +   --32-bitDetect 32-bit kernel leaking 
> addresses.
> +   --page-offset-32bit=   PAGE_OFFSET value (for 32-bit 
> kernels).
> +   --kernel-config-file= Kernel configuration file (e.g 
> /boot/config).
> +   -d, --debug Display debugging output.
> +   -h, --help, --version   Display this help and exit.

We don't need this, it's already indented.

> -Scans the running (64 bit) kernel for potential leaking addresses.
> +Scans the running kernel for potential leaking addresses.
>  
>  EOM
> exit($exitcode);
> @@ -123,7 +127,9 @@ GetOptions(
> 

Re: [PATCH] leaking_addresses: add generic 32-bit support

2017-12-17 Thread Tobin C. Harding
On Mon, Dec 18, 2017 at 09:24:47AM +0530, kaiwan.billimo...@gmail.com wrote:
> The script attempts to detect the architecture it's running upon; as of now,
> we explicitly support x86_64, PPC64 and x86_32.
> If it's one of them, we proceed "normally". If we fail to detect the arch,
> we fallback to 64-bit scanning, unless the user has passed either of these
> option switches: "--32-bit" and/or "--page-offset-32bit=".
> 
> If so, we switch to scanning for leaked addresses based on the value of
> PAGE_OFFSET (via an auto-detected or fallback mechanism).
> 
> As of now, we have code (or "rules") to detect special cases for x86_64 and 
> ppc64
> (in the get_address_re sub). Also, we now have also builtin "stubs", for lack 
> of a better term,
> where additional rules for other 64-bit arch's can be plugged in, in future,
> as applicable.
> 
> Signed-off-by: Kaiwan N Billimoria 
> ---
> 
> This is a patch based on Tobin's latest tree, 'leaks' branch. 
> Applies on top of commit 6c3942594657 (leaking_addresses: add support for 5 
> page table levels (origin/leaks))

That commit is not the tip of the branch. leaks branch is currently at

commit 266891c62bf0 (leaking_addresses: add support for 5 page table levels)

> 
> Thanks,
> Kaiwan.
> 
>  scripts/leaking_addresses.pl | 213 
> +--
>  1 file changed, 184 insertions(+), 29 deletions(-)
> 
> diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl
> index a29e13e577a7..a667f243c95b 100755
> --- a/scripts/leaking_addresses.pl
> +++ b/scripts/leaking_addresses.pl
> @@ -1,10 +1,10 @@
>  #!/usr/bin/env perl
>  #
>  # (c) 2017 Tobin C. Harding 
> -
> +# (c) 2017 Kaiwan N Billimoria 
>  # Licensed under the terms of the GNU GPL License version 2
>  #
> -# leaking_addresses.pl: Scan 64 bit kernel for potential leaking addresses.
> +# leaking_addresses.pl: Scan kernel for potential leaking addresses.
>  #  - Scans dmesg output.
>  #  - Walks directory tree and parses each file (for each directory in @DIRS).
>  #
> @@ -35,7 +35,7 @@ my $TIMEOUT = 10;
>  # Script can only grep for kernel addresses on the following architectures. 
> If
>  # your architecture is not listed here and has a grep'able kernel address 
> please
>  # consider submitting a patch.
> -my @SUPPORTED_ARCHITECTURES = ('x86_64', 'ppc64');
> +my @SUPPORTED_ARCHITECTURES = ('x86_64', 'ppc64', 'i[3456]86');
>  
>  # Command line options.
>  my $help = 0;
> @@ -48,7 +48,9 @@ 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.
> +my $opt_32_bit = 0;# Detect 32-bit kernel leaking addresses.
> +my $page_offset_32bit = 0; # 32-bit: value of CONFIG_PAGE_OFFSET.
> +my $kernel_config_file = "";   # Kernel configuration file.
>  
>  # Do not parse these files (absolute path).
>  my @skip_parse_files_abs = ('/proc/kmsg',
> @@ -97,17 +99,19 @@ Version: $V
>  
>  Options:
>  
> -   -o, --output-raw= Save results for future processing.
> -   -i, --input-raw=  Read results from file instead of 
> scanning.
> - --raw Show raw results (default).
> - --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= Kernel configuration file (e.g 
> /boot/config)
> -   -d, --debug Display debugging output.
> -   -h, --help, --versionq  Display this help and exit.
> +   -o, --output-raw= Save results for future processing.
> +   -i, --input-raw=  Read results from file instead of 
> scanning.
> +   --raw   Show raw results (default).
> +   --suppress-dmesgDo not show dmesg results.
> +   --squash-by-pathShow one result per unique path.
> +   --squash-by-filenameShow one result per unique 
> filename.
> +   --32-bitDetect 32-bit kernel leaking 
> addresses.
> +   --page-offset-32bit=   PAGE_OFFSET value (for 32-bit 
> kernels).
> +   --kernel-config-file= Kernel configuration file (e.g 
> /boot/config).
> +   -d, --debug Display debugging output.
> +   -h, --help, --version   Display this help and exit.

We don't need this, it's already indented.

> -Scans the running (64 bit) kernel for potential leaking addresses.
> +Scans the running kernel for potential leaking addresses.
>  
>  EOM
> exit($exitcode);
> @@ -123,7 +127,9 @@ GetOptions(
> 'squash-by-path'=> \$squash_by_path,
> 'squash-by-filename'=> 

[PATCH] leaking_addresses: add generic 32-bit support

2017-12-17 Thread kaiwan . billimoria
The script attempts to detect the architecture it's running upon; as of now,
we explicitly support x86_64, PPC64 and x86_32.
If it's one of them, we proceed "normally". If we fail to detect the arch,
we fallback to 64-bit scanning, unless the user has passed either of these
option switches: "--32-bit" and/or "--page-offset-32bit=".

If so, we switch to scanning for leaked addresses based on the value of
PAGE_OFFSET (via an auto-detected or fallback mechanism).

As of now, we have code (or "rules") to detect special cases for x86_64 and 
ppc64
(in the get_address_re sub). Also, we now have also builtin "stubs", for lack 
of a better term,
where additional rules for other 64-bit arch's can be plugged in, in future,
as applicable.

Signed-off-by: Kaiwan N Billimoria 
---

This is a patch based on Tobin's latest tree, 'leaks' branch. 
Applies on top of commit 6c3942594657 (leaking_addresses: add support for 5 
page table levels (origin/leaks))

Thanks,
Kaiwan.

 scripts/leaking_addresses.pl | 213 +--
 1 file changed, 184 insertions(+), 29 deletions(-)

diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl
index a29e13e577a7..a667f243c95b 100755
--- a/scripts/leaking_addresses.pl
+++ b/scripts/leaking_addresses.pl
@@ -1,10 +1,10 @@
 #!/usr/bin/env perl
 #
 # (c) 2017 Tobin C. Harding 
-
+# (c) 2017 Kaiwan N Billimoria 
 # Licensed under the terms of the GNU GPL License version 2
 #
-# leaking_addresses.pl: Scan 64 bit kernel for potential leaking addresses.
+# leaking_addresses.pl: Scan kernel for potential leaking addresses.
 #  - Scans dmesg output.
 #  - Walks directory tree and parses each file (for each directory in @DIRS).
 #
@@ -35,7 +35,7 @@ my $TIMEOUT = 10;
 # Script can only grep for kernel addresses on the following architectures. If
 # your architecture is not listed here and has a grep'able kernel address 
please
 # consider submitting a patch.
-my @SUPPORTED_ARCHITECTURES = ('x86_64', 'ppc64');
+my @SUPPORTED_ARCHITECTURES = ('x86_64', 'ppc64', 'i[3456]86');
 
 # Command line options.
 my $help = 0;
@@ -48,7 +48,9 @@ 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.
+my $opt_32_bit = 0;# Detect 32-bit kernel leaking addresses.
+my $page_offset_32bit = 0; # 32-bit: value of CONFIG_PAGE_OFFSET.
+my $kernel_config_file = "";   # Kernel configuration file.
 
 # Do not parse these files (absolute path).
 my @skip_parse_files_abs = ('/proc/kmsg',
@@ -97,17 +99,19 @@ Version: $V
 
 Options:
 
-   -o, --output-raw= Save results for future processing.
-   -i, --input-raw=  Read results from file instead of 
scanning.
- --raw Show raw results (default).
- --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= Kernel configuration file (e.g 
/boot/config)
-   -d, --debug Display debugging output.
-   -h, --help, --versionq  Display this help and exit.
+   -o, --output-raw= Save results for future processing.
+   -i, --input-raw=  Read results from file instead of 
scanning.
+   --raw   Show raw results (default).
+   --suppress-dmesgDo not show dmesg results.
+   --squash-by-pathShow one result per unique path.
+   --squash-by-filenameShow one result per unique filename.
+   --32-bitDetect 32-bit kernel leaking addresses.
+   --page-offset-32bit=   PAGE_OFFSET value (for 32-bit kernels).
+   --kernel-config-file= Kernel configuration file (e.g 
/boot/config).
+   -d, --debug Display debugging output.
+   -h, --help, --version   Display this help and exit.
 
-Scans the running (64 bit) kernel for potential leaking addresses.
+Scans the running kernel for potential leaking addresses.
 
 EOM
exit($exitcode);
@@ -123,7 +127,9 @@ GetOptions(
'squash-by-path'=> \$squash_by_path,
'squash-by-filename'=> \$squash_by_filename,
'raw'   => \$raw,
-   'kernel-config-file=s'  => \$kernel_config_file,
+   '32-bit'=> \$opt_32_bit,
+   'page-offset-32bit=o'   => \$page_offset_32bit,
+   'kernel-config-file=s'  => \$kernel_config_file,
 ) or help(1);
 
 help(0) if ($help);
@@ -139,11 +145,16 @@ if (!$input_raw and ($squash_by_path or 
$squash_by_filename)) {
exit(128);

[PATCH] leaking_addresses: add generic 32-bit support

2017-12-17 Thread kaiwan . billimoria
The script attempts to detect the architecture it's running upon; as of now,
we explicitly support x86_64, PPC64 and x86_32.
If it's one of them, we proceed "normally". If we fail to detect the arch,
we fallback to 64-bit scanning, unless the user has passed either of these
option switches: "--32-bit" and/or "--page-offset-32bit=".

If so, we switch to scanning for leaked addresses based on the value of
PAGE_OFFSET (via an auto-detected or fallback mechanism).

As of now, we have code (or "rules") to detect special cases for x86_64 and 
ppc64
(in the get_address_re sub). Also, we now have also builtin "stubs", for lack 
of a better term,
where additional rules for other 64-bit arch's can be plugged in, in future,
as applicable.

Signed-off-by: Kaiwan N Billimoria 
---

This is a patch based on Tobin's latest tree, 'leaks' branch. 
Applies on top of commit 6c3942594657 (leaking_addresses: add support for 5 
page table levels (origin/leaks))

Thanks,
Kaiwan.

 scripts/leaking_addresses.pl | 213 +--
 1 file changed, 184 insertions(+), 29 deletions(-)

diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl
index a29e13e577a7..a667f243c95b 100755
--- a/scripts/leaking_addresses.pl
+++ b/scripts/leaking_addresses.pl
@@ -1,10 +1,10 @@
 #!/usr/bin/env perl
 #
 # (c) 2017 Tobin C. Harding 
-
+# (c) 2017 Kaiwan N Billimoria 
 # Licensed under the terms of the GNU GPL License version 2
 #
-# leaking_addresses.pl: Scan 64 bit kernel for potential leaking addresses.
+# leaking_addresses.pl: Scan kernel for potential leaking addresses.
 #  - Scans dmesg output.
 #  - Walks directory tree and parses each file (for each directory in @DIRS).
 #
@@ -35,7 +35,7 @@ my $TIMEOUT = 10;
 # Script can only grep for kernel addresses on the following architectures. If
 # your architecture is not listed here and has a grep'able kernel address 
please
 # consider submitting a patch.
-my @SUPPORTED_ARCHITECTURES = ('x86_64', 'ppc64');
+my @SUPPORTED_ARCHITECTURES = ('x86_64', 'ppc64', 'i[3456]86');
 
 # Command line options.
 my $help = 0;
@@ -48,7 +48,9 @@ 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.
+my $opt_32_bit = 0;# Detect 32-bit kernel leaking addresses.
+my $page_offset_32bit = 0; # 32-bit: value of CONFIG_PAGE_OFFSET.
+my $kernel_config_file = "";   # Kernel configuration file.
 
 # Do not parse these files (absolute path).
 my @skip_parse_files_abs = ('/proc/kmsg',
@@ -97,17 +99,19 @@ Version: $V
 
 Options:
 
-   -o, --output-raw= Save results for future processing.
-   -i, --input-raw=  Read results from file instead of 
scanning.
- --raw Show raw results (default).
- --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= Kernel configuration file (e.g 
/boot/config)
-   -d, --debug Display debugging output.
-   -h, --help, --versionq  Display this help and exit.
+   -o, --output-raw= Save results for future processing.
+   -i, --input-raw=  Read results from file instead of 
scanning.
+   --raw   Show raw results (default).
+   --suppress-dmesgDo not show dmesg results.
+   --squash-by-pathShow one result per unique path.
+   --squash-by-filenameShow one result per unique filename.
+   --32-bitDetect 32-bit kernel leaking addresses.
+   --page-offset-32bit=   PAGE_OFFSET value (for 32-bit kernels).
+   --kernel-config-file= Kernel configuration file (e.g 
/boot/config).
+   -d, --debug Display debugging output.
+   -h, --help, --version   Display this help and exit.
 
-Scans the running (64 bit) kernel for potential leaking addresses.
+Scans the running kernel for potential leaking addresses.
 
 EOM
exit($exitcode);
@@ -123,7 +127,9 @@ GetOptions(
'squash-by-path'=> \$squash_by_path,
'squash-by-filename'=> \$squash_by_filename,
'raw'   => \$raw,
-   'kernel-config-file=s'  => \$kernel_config_file,
+   '32-bit'=> \$opt_32_bit,
+   'page-offset-32bit=o'   => \$page_offset_32bit,
+   'kernel-config-file=s'  => \$kernel_config_file,
 ) or help(1);
 
 help(0) if ($help);
@@ -139,11 +145,16 @@ if (!$input_raw and ($squash_by_path or 
$squash_by_filename)) {
exit(128);
 }
 
-if (!is_supported_architecture()) {
-   printf "\nScript does