From patchwork Tue Nov 21 07:58:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaiwan N Billimoria X-Patchwork-Id: 10067715 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F1DAD6022E for ; Tue, 21 Nov 2017 07:58:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4B1328F46 for ; Tue, 21 Nov 2017 07:58:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D89C528F5B; Tue, 21 Nov 2017 07:58:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 0806B28F46 for ; Tue, 21 Nov 2017 07:58:34 +0000 (UTC) Received: (qmail 25617 invoked by uid 550); 21 Nov 2017 07:58:31 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 24555 invoked from network); 21 Nov 2017 07:58:30 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:mime-version :content-transfer-encoding; bh=NtFNRQ1T7IKhrQ//pCeMxwPZh3E9twIgD5UsQ8yJeik=; b=T4MuXedvkERKoBgG+H7g2VBdNvR84m/Tu9s9Ofs+2GpfAHALb234gyLGiIof1ZE4fK vQ9eogI4Qa4bhRU/EJiUAR883qtdQj22hfB8MVbp23hovQ9S0pEjU8Zs6NSGe9CU6Chp dzC2jhPregEg3ejthM22JZBrqhTSE+++i89AqSPQdWmSaAha+M1LFDzXz9fL/CA23F6B 2J+XpL1XALBJ1edeCqoUveGo16oQIxsOx3ajrOxStyc1YnJZPpnkFvTVKsop9Qpujy6i 3Xyt3bFcrb25OIobTdGF61CTFSeOxu7BsZ9rrpCjHQH4xUOdWfIanWMJU0Q7sTPNCEBq JCxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:mime-version :content-transfer-encoding; bh=NtFNRQ1T7IKhrQ//pCeMxwPZh3E9twIgD5UsQ8yJeik=; b=J3o8dxZ3gLgyejFPL6bJ/PuR+oSOHmlbSwtfD44xqP007yHE1ZL+GXICy/SKf1jcI5 jKHIuNpe9dnMOfzo6GUfBEmWbUH0dcTjgPvBPBNAeGWCYHcrwYCnXY8iHx2pHWPR9lzV 9oh4bERSCxNAtJkZ0Ph290xK9HLK/XCZrDLNhrsDb5CoPAaBH7gHfUz5r15pgDc/0v32 PfCB/o9NYMrXZVaOFpWgZDA09curK1385JYn0HahzNp+d4aaaVPDfHMYRN3x4ho6eUTa pp/iAaKf9UUtjl4BGvgV8tUizIirQWdpbJepCccXYeVVvfZuv40GXCIdPyafynncOJsu 8kMg== X-Gm-Message-State: AJaThX5wMjI3Tu7pr88mCGrsWf3Jf6pvsUyzdEtWeVn6Hf4m57Q29Abk 23TbE+7Ad3Wp+INtduhBsks= X-Google-Smtp-Source: AGs4zMYN9x/2Fw67JIQf5weCrULlBTy26y1NMBvjpsSmvGIaWsVJDf5qQW9CEd+NwkPAoB3eo/XzaA== X-Received: by 10.107.204.1 with SMTP id c1mr15271881iog.76.1511251097913; Mon, 20 Nov 2017 23:58:17 -0800 (PST) Message-ID: <1511251094.25970.18.camel@gmail.com> From: kaiwan.billimoria@gmail.com To: me@tobin.cc Cc: linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com Date: Tue, 21 Nov 2017 13:28:14 +0530 X-Mailer: Evolution 3.26.2 (3.26.2-1.fc27) Mime-Version: 1.0 Subject: [kernel-hardening] [PATCH v1] scripts: leaking_addresses.pl: add support for 32-bit kernel addresses X-Virus-Scanned: ClamAV using ClamSMTP The current leaking_addresses.pl script only supports showing "leaked" 64-bit kernel virtual addresses. This patch adds support for showing "leaked" 32-bit kernel virtual addresses. The way it currently works- once it detects we're running on an i'x'86 platform (where x=3|4|5|6), it takes this arch into account for checking: the essential rationale: virt-addr >= PAGE_OFFSET => it's a kernel virtual address. Note- 1. It's a work in progress; some pending TODOs: - support for ARM-32 - programatically query and set the PAGE_OFFSET based on arch (it's currently hard-coded) 2. Minor edit: the '--raw', '--suppress-dmesg', '--squash-by-path' and '--squash-by-filename' option switches are only meaningful when the '----input-raw=' option is used. So, indent the 'Help' screen lines to reflect the fact. Feedback welcome.. Signed-off-by: Kaiwan N Billimoria --- $address_re = '\b(0x)?ffff[[:xdigit:]]{12}\b'; } elsif (is_ppc64()) { $address_re = '\b(0x)?[89abcdef]00[[:xdigit:]]{13}\b'; + } elsif (is_ix86_32()) { + $address_re = '\b(0x)?[[:xdigit:]]{8}\b'; } while (/($address_re)/g) { diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl index bc5788000018..e139de445ad1 100755 --- a/scripts/leaking_addresses.pl +++ b/scripts/leaking_addresses.pl @@ -12,7 +12,10 @@ # # You may like to set kptr_restrict=2 before running script # (see Documentation/sysctl/kernel.txt). - +# +# 32-bit kernel address support : Kaiwan N Billimoria +# +# use warnings; use strict; use POSIX; @@ -35,7 +38,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,6 +51,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 $bit_size = 64; # Check 64-bit kernel addresses by default +my $PAGE_OFFSET_32BIT = 0xc0000000; + # Do not parse these files (absolute path). my @skip_parse_files_abs = ('/proc/kmsg', '/proc/kcore', @@ -97,10 +103,10 @@ 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. + --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. -d, --debug Display debugging output. -h, --help, --version Display this help and exit. @@ -177,7 +183,7 @@ sub dprint sub is_supported_architecture { - return (is_x86_64() or is_ppc64()); + return (is_x86_64() or is_ppc64() or is_ix86_32()); } sub is_x86_64 @@ -185,6 +191,7 @@ sub is_x86_64 my $archname = $Config{archname}; if ($archname =~ m/x86_64/) { + $bit_size=64; return 1; } return 0; @@ -195,6 +202,19 @@ sub is_ppc64 my $archname = $Config{archname}; if ($archname =~ m/powerpc/ and $archname =~ m/64/) { + $bit_size=64; + return 1; + } + return 0; +} + +# 32-bit x86: is_i'x'86_32() ; where x is [3 or 4 or 5 or 6] +sub is_ix86_32 +{ + my $archname = $Config{archname}; + + if ($archname =~ m/i[3456]86-linux/) { + $bit_size=32; return 1; } return 0; @@ -215,6 +235,15 @@ sub is_false_positive $match =~ '\bf{10}601000\b') { return 1; } + } elsif ($bit_size == 32) { + my $addr32 = eval hex($match); + if ($addr32 < $PAGE_OFFSET_32BIT ) { + return 1; + } + if ($match =~ '\b(0x)?(f|F){8}\b') { + return 1; + } } return 0; @@ -243,6 +272,8 @@ sub may_leak_address