Received: by 10.223.176.5 with SMTP id f5csp3784145wra; Mon, 29 Jan 2018 19:45:38 -0800 (PST) X-Google-Smtp-Source: AH8x225ZMGjXnMYrkCemagz9moR2FTfETELmv6WS1lfxk36TrS1j/tKJA6+ysuO2YZd+fm88Xq8q X-Received: by 2002:a17:902:24a2:: with SMTP id w31-v6mr22652144pla.262.1517283938079; Mon, 29 Jan 2018 19:45:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517283938; cv=none; d=google.com; s=arc-20160816; b=tYSnS3MuaY+MCTrPnIhDx4hGcb+Fe6Xllkh0IpTFcmJMikrMqXGbHeJMFQi62zG770 Vjc2gtbwtIpA9OqoUAY9NHbub6ZRKn5chYUsdIlGo4IL0YiNKSfptyaJFGd8TPRPXzwv gx6j0ZubWZzNsbee2aoDT1wbftDdiqtIyuEvALVgVRxSLDIkg2BYplyKxcOn2H6SAUzQ c4K7le9ZA+tsCGkYC8hPKR1+49QEaPriIkJuv+6/Y3/juYAd4rf592fsiXEpC62DmpWZ 5kwSUNDqQjTAd31VJHBc2QIzFurEQB6PsXek+pMnuftNQb10BV2s2hwfoYB9sQhlqbQe xb4w== 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 :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature:arc-authentication-results; bh=u2TYpW+C7Rw4gbjFlaMllfTa0bMKbEzeUEtkXdRJ9zs=; b=JK4kouT/TQbBkiQdlDl2UG9FXH6jVq/aSPsKE5To1Au/mibGMKzlFOqQb80a17H9eE MTUQZLq1UbVoWTOnjVYYJvE0FwNuyDBUgQlLJ4d3DFdJQt+s8EGAyjSWczSUrLPSUyVa E19MNnJxagsW1/UKKLX9TiPsC9eJH2wlnLnPIaL6PCIfJdxvlWGscqn0FXQ5AwLPO0C4 UKxUBZxx2/xPR5KJEaaz4Ev+ln7G703+sU5MbUX3PnCKDh8LF4BBha1HKbAleAH7xypz bMFfC0ftiYNxFCpSSK+DyRmR18+jXjoRQ/pRhogfEZ/EnzNCzdu3thgx9pOUMBh3/sfL ZV6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CadzQuR7; 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 x6si8381145pgc.357.2018.01.29.19.45.23; Mon, 29 Jan 2018 19:45:38 -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=CadzQuR7; 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 S1752658AbeA3Do6 (ORCPT + 99 others); Mon, 29 Jan 2018 22:44:58 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:45554 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752076AbeA3Do4 (ORCPT ); Mon, 29 Jan 2018 22:44:56 -0500 Received: by mail-pf0-f195.google.com with SMTP id a88so7480619pfe.12 for ; Mon, 29 Jan 2018 19:44:56 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=u2TYpW+C7Rw4gbjFlaMllfTa0bMKbEzeUEtkXdRJ9zs=; b=CadzQuR7NNQxoq2Zmj2nmZ1jwImpA0+eS8+mG3/O4teDff/SagIIDOOtEPAFi89OuB QCfQNYljOzw8og1JgLBVp4elXRFpN61e4TCWFCMmFIHFQ1VzGU8z2q7Ux2e8+UtcesUa +EkWf1WXd574uR2P+AEUVI/fuv8kCVqHT7BGl7qEcm1UM43dfG1JOVFvSqqSV21d4NEh nHmItj7DcCDgIN+PjM1dUM26GibTt0ES+R9YQK5Xa1Yw6joHwzw2BEinDfOQwwDffSif FleWAwp8QOszbW6Q9J6RDMAx6nD4uXe15rki/x+j8oRtCDgF9d+JYnP9DCf6qdjO6LqS XSBg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=u2TYpW+C7Rw4gbjFlaMllfTa0bMKbEzeUEtkXdRJ9zs=; b=C1A8OeTmUIxCWgkU2cXvluLaTwsKBi7QWugNwHT6jvnWNLG65jRb3DDZ6/jFatr7YZ 4WkTkcECX+5LozXcDKjD3jOWKLzn1yQNf8iqvb89i9qRXLvLVpC0gxWnlzdlQfTVf/sD q2zOTN9KpfAkHrAtvgmJ8zzc1NA+YkbbLRQvtzAV85oZX31b45Y+eChgLMwwFBAWvqWB jUgEigVHOlujVypnw9ulEWmMyv8n8nD+FHeHgYQHXrSKUpM5IpWENlNmi05f4uqKfeoV vZMMAt26wa/eF2sEhY6OZEVUVqJFB8l8WEqwgw6Bz3i3CjMXdUAl3R5TdoOU34vuVGQD 2Law== X-Gm-Message-State: AKwxytdmZXBJ5EVdEadjbgcq8XSVRorkMbWkLQZW9k+Xy3BO9QGx3Mqd GhTOqRDIuAQDvVr2RmOtAma2LqyS X-Received: by 10.99.115.4 with SMTP id o4mr22517735pgc.206.1517283895474; Mon, 29 Jan 2018 19:44:55 -0800 (PST) Received: from klaptop ([106.216.179.128]) by smtp.gmail.com with ESMTPSA id w16sm18857240pfk.18.2018.01.29.19.44.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jan 2018 19:44:54 -0800 (PST) Message-ID: <1517283889.29097.1.camel@gmail.com> Subject: Re: [PATCH] leaking_addresses: add 32-bit support From: kaiwan.billimoria@gmail.com To: "Tobin C. Harding" , Kernel Hardening Cc: LKML Date: Tue, 30 Jan 2018 09:14:49 +0530 In-Reply-To: <1517201477-12326-1-git-send-email-me@tobin.cc> References: <1517201477-12326-1-git-send-email-me@tobin.cc> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.4 (3.26.4-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 Hi Tobin, On Mon, 2018-01-29 at 15:51 +1100, Tobin C. Harding wrote: > Currently script only supports x86_64 and ppc64. It would be nice to be > able to scan 32-bit machines also. We can add support for > 32-bit architectures by modifying how we check for false positives, > taking advantage of the page offset used by the kernel, and using the > correct regular expression. > > Support for 32-bit machines is enabled by the observation the kernel > addresses on 32-bit machines are larger than the page offset. We can > use this to filter false positives when scanning the kernel for leaking > addresses. > > Programmatic determination of the running architecture is not > immediately obvious. We therefore provide a flag to enable scanning of > 32-bit kernels. Also we can check the kernel config file for the offset > and if not found default to 0xc0000000. A command line option to parse > in the page offset is also provided. We do automatically detect > architecture if running on ix86. > > Add support for 32-bit kernels. Add a command line option for page > offset. > > Suggested-by: Kaiwan N Billimoria > Signed-off-by: Tobin C. Harding > --- > > The basis for this patch has been in development for a while by Kaiwan > but didn't get finished before the merge window opened. I'd like to > fast track this and get it to Linus this merge window (considering > Spectre/Meltdown). I have finished this work off and added the > Suggested-by tag. Kaiwan I hope you are not upset by this, extra > ordinary circumstances seemed to require this action. Definitely not; I understand and am glad you're on it a 100%. Apologies that I couldn't work on this right now.. will try and keep track too. Thanks, Kaiwan. > > thanks, > Tobin. > > scripts/leaking_addresses.pl | 84 ++++++++++++++++++++++++++++++++++++++++---- > 1 file changed, 78 insertions(+), 6 deletions(-) > > diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl > index 64a3cfa1175b..c13eb53d1c5a 100755 > --- a/scripts/leaking_addresses.pl > +++ b/scripts/leaking_addresses.pl > @@ -34,7 +34,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', 'x86'); > > # Command line options. > my $help = 0; > @@ -46,6 +46,8 @@ 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_32bit = 0; # Scan 32-bit kernel. > +my $page_offset_32bit = 0; # Page offset for 32-bit kernel. > > # Do not parse these files (absolute path). > my @skip_parse_files_abs = ('/proc/kmsg', > @@ -103,6 +105,8 @@ 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) > + --32-bit Scan 32-bit kernel. > + --page-offset-32-bit=o Page offset (for 32-bit kernel 0xABCD1234). > -d, --debug Display debugging output. > -h, --help, --versionq Display this help and exit. > > @@ -123,6 +127,8 @@ GetOptions( > 'squash-by-filename' => \$squash_by_filename, > 'raw' => \$raw, > 'kernel-config-file=s' => \$kernel_config_file, > + '32-bit' => \$opt_32bit, > + 'page-offset-32-bit=o' => \$page_offset_32bit, > ) or help(1); > > help(0) if ($help); > @@ -138,7 +144,7 @@ if (!$input_raw and ($squash_by_path or $squash_by_filename)) { > exit(128); > } > > -if (!is_supported_architecture()) { > +if (!(is_supported_architecture() or $opt_32bit or $page_offset_32bit)) { > printf "\nScript does not support your architecture, sorry.\n"; > printf "\nCurrently we support: \n\n"; > foreach(@SUPPORTED_ARCHITECTURES) { > @@ -146,6 +152,9 @@ if (!is_supported_architecture()) { > } > printf("\n"); > > + printf("If you are running a 32-bit architecture you may use:\n"); > + printf("\n\t--32-bit or --page-offset-32-bit=\n\n"); > + > my $archname = `uname -m`; > printf("Machine hardware name (`uname -m`): %s\n", $archname); > > @@ -169,7 +178,28 @@ 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_32bit > +{ > + # Allow --32-bit or --page-offset-32-bit to override > + if ($opt_32bit or $page_offset_32bit) { > + return 1; > + } > + > + return is_ix86_32(); > +} > + > +sub is_ix86_32 > +{ > + my $arch = `uname -m`; > + > + chomp $arch; > + if ($arch =~ m/i[3456]86/) { > + return 1; > + } > + return 0; > } > > sub is_arch > @@ -261,6 +291,12 @@ sub is_false_positive > { > my ($match) = @_; > > + if (is_32bit()) { > + return is_false_positive_32bit($match); > + } > + > + # 64 bit false positives. > + > if ($match =~ '\b(0x)?(f|F){16}\b' or > $match =~ '\b(0x)?0{16}\b') { > return 1; > @@ -273,6 +309,40 @@ sub is_false_positive > return 0; > } > > +sub is_false_positive_32bit > +{ > + my ($match) = @_; > + state $page_offset = get_page_offset(); > + > + if ($match =~ '\b(0x)?(f|F){8}\b') { > + return 1; > + } > + > + if (hex($match) < $page_offset) { > + return 1; > + } > + > + return 0; > +} > + > +# returns integer value > +sub get_page_offset > +{ > + my $page_offset; > + my $default_offset = 0xc0000000; > + > + # Allow --page-offset-32bit to override. > + if ($page_offset_32bit != 0) { > + return $page_offset_32bit; > + } > + > + $page_offset = get_kernel_config_option('CONFIG_PAGE_OFFSET'); > + if (!$page_offset) { > + return $default_offset; > + } > + return $page_offset; > +} > + > sub is_in_vsyscall_memory_region > { > my ($match) = @_; > @@ -314,11 +384,13 @@ sub may_leak_address > > sub get_address_re > { > - if (is_x86_64()) { > - return get_x86_64_re(); > - } elsif (is_ppc64()) { > + if (is_ppc64()) { > return '\b(0x)?[89abcdef]00[[:xdigit:]]{13}\b'; > + } elsif (is_32bit()) { > + return '\b(0x)?[[:xdigit:]]{8}\b'; > } > + > + return get_x86_64_re(); > } > > sub get_x86_64_re