Received: by 10.223.164.202 with SMTP id h10csp4830508wrb; Mon, 20 Nov 2017 23:59:09 -0800 (PST) X-Google-Smtp-Source: AGs4zMZezcwOU6uvHVNG9vcSePJ6KDid+8ZQktumimj0UMojKrkUIQxBNWME+TZbS1WgMkZ2BcHT X-Received: by 10.159.206.131 with SMTP id bg3mr16911843plb.124.1511251149611; Mon, 20 Nov 2017 23:59:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511251149; cv=none; d=google.com; s=arc-20160816; b=pfl158D2YJ93QxiHVtdiT9KS5QJbyJAQamQJ7Tx+Ey/wX3X0mnahz+UvO5JU1GSh78 69Et96c4gpY0yJC2RuOUhD5lrtMgJAivMBREulZVBUdD4GVfFk+5cY31GCth28nwiE/b ualkimruIG309082mM/Q0D3Qmaa5lMpi9UqTwRhUcMNqH0lXgd+xpVmP9CAS/xhPbuAo FFjHZKMmyKXl1Fowlgck/L/q/4TlPrgL1HTwuKhX2sVxDJB3FZ9g+txkPGgY+fQQlqih K1RGwrZqcJ+TxXorvS6fE2XmnhbnAPoCPnLDT96TXj69l3o9dy6EUECdo5Ny0NUwk5+3 wHpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :date:cc:to:from:subject:message-id:dkim-signature :arc-authentication-results; bh=NtFNRQ1T7IKhrQ//pCeMxwPZh3E9twIgD5UsQ8yJeik=; b=bM0Xq7LjgqF/tHY2VZ96rKoOZZL03IHUTT8E2oTmE7iu5qejSWpYFkUDRULkAKj08L 3Xv5hEgBqeW9XJT4t6g4N7vwYc2aph1eEftmypobXrhRMqHTrjraliS82C0hVjZFDI24 A0K0BVoFsHNbF9ODmsEjS4JwOBYFS0R9YaLN6+CsC8nqTBNKCpNfIRhomCLOzDv8Ujy5 NAJmlML+r9CI/miCzZVjqIAUynGhcEv7RBam3TUdRqccJ+TPqsDNqr7kIu9nXcotJYPy uI/Fk+Mui5g3qZkl+e/CRRWmIwaal7THOHSzJMCdeZYOaUsLli4vGHim6eI/POoN5ysM FtZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=T4MuXedv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p7si10208132pgc.577.2017.11.20.23.58.58; Mon, 20 Nov 2017 23:59:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=T4MuXedv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751306AbdKUH6U (ORCPT + 73 others); Tue, 21 Nov 2017 02:58:20 -0500 Received: from mail-io0-f196.google.com ([209.85.223.196]:45755 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751228AbdKUH6S (ORCPT ); Tue, 21 Nov 2017 02:58:18 -0500 Received: by mail-io0-f196.google.com with SMTP id z74so18498937iof.12 for ; Mon, 20 Nov 2017 23:58:18 -0800 (PST) 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=A9RKdsx4HoAa+s7R6DQkKXue7O7gIWr4uVyHoSn82OLWTXbDxnxch83O5r26cscXGU rLSHrc2kBHhP2dO5ddKLJecEnjc3NF1vARe7fBVPcP9i9gPj0u4TRGyeaS9+nTxVF5Rd IPgjcpKkFHJMQjfd9xgXG5Ljqjfi2rJUrwcQchgLiGLPdj1WpwdCCIN3sK6Y/4wIF5Oq jD5X2w3dZYL49KLZ68Q+cJvpWeGRKzOC1qb6+JKYLKDmbUV2ycZs7E7jgGzUcTZ9fZlq HZlYvOohADk1FGzc+saeqCOW/A3aGBmKDayHxZjnTXrdC0DopufpA93ahX3EMBmkmYYf QXvA== X-Gm-Message-State: AJaThX5/wOfpKFmA2pPGbPpcF3qGO5DWTYWzpka9NoKkS/Cx23BCPExa bF7HywqgAQ5HFLAB+kvXwhmnwF4p X-Received: by 10.107.204.1 with SMTP id c1mr15271881iog.76.1511251097913; Mon, 20 Nov 2017 23:58:17 -0800 (PST) Received: from klaptop ([49.207.58.167]) by smtp.gmail.com with ESMTPSA id w71sm5232778iof.49.2017.11.20.23.58.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Nov 2017 23:58:17 -0800 (PST) Message-ID: <1511251094.25970.18.camel@gmail.com> Subject: [PATCH v1] scripts: leaking_addresses.pl: add support for 32-bit kernel addresses 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 Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.2 (3.26.2-1.fc27) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 $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) { From 1584803352529621349@xxx Wed Nov 22 21:30:53 +0000 2017 X-GM-THRID: 1584803352529621349 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread