From patchwork Mon Feb 19 02:50:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobin Harding X-Patchwork-Id: 10227041 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 C30CD602B1 for ; Mon, 19 Feb 2018 02:51:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B42EC2886C for ; Mon, 19 Feb 2018 02:51:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A911F2887B; Mon, 19 Feb 2018 02:51:33 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_MED 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 BF6CC28871 for ; Mon, 19 Feb 2018 02:51:32 +0000 (UTC) Received: (qmail 3337 invoked by uid 550); 19 Feb 2018 02:51:19 -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 3158 invoked from network); 19 Feb 2018 02:51:16 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tobin.cc; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=9Ij8tsZbZzOlKE+qd 7wd9Qy/gM1Rpa/rXs/vDMFq5dI=; b=jgYJzbIsBrd0RMDOJXOhknmVNeKvab5ZS M5R89rFE6tDar29QZo7xCwQp1ldqFr8a5agNYeh2l20O4gix27pQ0mh5K0NL3DyO nxMdClB/0Aw3K9nMdlOyR6CiMDnmJl6AEYdkx5eouwFenEE7Klpeu20mu4wvEFmt 5AoTQFGAjduU9PGB8I2rICGT3OWsuK9Xkx3YVbXqr9+ZiB3o6GuxiJHf4DuCYB5f qZ//WkX0oOri7bCCYSYVzAczM0YD9bapHxkg+whXGZpXys128nTBoDl54T+HWKw0 2Lc/rL46E0Ru9r/TnNf2LK19KN1uO9pAZO6KgeAdkxd1NfOs1qzpQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=9Ij8tsZbZzOlKE+qd7wd9Qy/gM1Rpa/rXs/vDMFq5dI=; b=T31a2dgV v7s31XZ+MFOiCQw2H/jqI9PVkyxEFSsfxXPRRWJ90T3iuLbCd3GkPUjuvCb6qYD8 aM3ofDE+fH0U9bHXvAJSFQ4UVcJ6e+BuMyXZcHayI9VWiMwIzroXeV/mSjeWin9x T+h4Xfi9RaiUUxpY1HTFRfO/rkjXYjka+Q9CNv8pnxTCRffeyUh7JFfXOKYPIaZQ 5m7B8Z/HOLsgJDm//crlH/Iv1Rzno05diWDHOXMjKPSpBO/3rBsx/6DjNuJ5La9n jE3JhZ1YgvSjq7hT6b3cjTOLdOp61Mpt4BHDtDrVpy2GZpW43TCkGcVwyo3NdRNj q8iMlvoe0fHjbg== X-ME-Sender: From: "Tobin C. Harding" To: Kernel Hardening Cc: "Tobin C. Harding" , Tycho Andersen , LKML Subject: [PATCH 2/4] leaking_addresses: simplify path skipping Date: Mon, 19 Feb 2018 13:50:47 +1100 Message-Id: <1519008649-15782-3-git-send-email-me@tobin.cc> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519008649-15782-1-git-send-email-me@tobin.cc> References: <1519008649-15782-1-git-send-email-me@tobin.cc> X-Virus-Scanned: ClamAV using ClamSMTP Currently script has multiple configuration arrays. This is confusing, evident by the fact that a bunch of the entries are in the wrong place. We can simplify the code by just having a single array for absolute paths to skip and a single array for file names to skip wherever they appear in the scanned directory tree. There are also currently multiple subroutines to handle the different arrays, we can reduce these to a single subroutine also. Simplify the path skipping code. Signed-off-by: Tobin C. Harding --- scripts/leaking_addresses.pl | 90 ++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 61 deletions(-) diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl index 3d5c3096aac8..e7bf15a45a69 100755 --- a/scripts/leaking_addresses.pl +++ b/scripts/leaking_addresses.pl @@ -48,41 +48,26 @@ 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', - '/proc/kcore', - '/proc/fs/ext4/sdb1/mb_groups', - '/proc/1/fd/3', - '/sys/firmware/devicetree', - '/proc/device-tree', - '/sys/kernel/debug/tracing/trace_pipe', - '/sys/kernel/security/apparmor/revision'); - -# Do not parse these files under any subdirectory. -my @skip_parse_files_any = ('0', - '1', - '2', - 'pagemap', - 'events', - 'access', - 'registers', - 'snapshot_raw', - 'trace_pipe_raw', - 'ptmx', - 'trace_pipe'); - -# Do not walk these directories (absolute path). -my @skip_walk_dirs_abs = (); - -# Do not walk these directories under any subdirectory. -my @skip_walk_dirs_any = ('self', - 'thread-self', - 'cwd', - 'fd', - 'usbmon', - 'stderr', - 'stdin', - 'stdout'); +# Skip these absolute paths. +my @skip_abs = ( + '/proc/kmsg', + '/sys/firmware/devicetree', + '/proc/device-tree', + '/sys/kernel/debug/tracing/trace_pipe', + '/sys/kernel/security/apparmor/revision'); + +# Skip these under any subdirectory. +my @skip_any = ( + 'pagemap', + 'events', + 'access', + 'registers', + 'snapshot_raw', + 'trace_pipe_raw', + 'ptmx', + 'trace_pipe', + 'fd', + 'usbmon'); sub help { @@ -417,26 +402,20 @@ sub parse_dmesg # True if we should skip this path. sub skip { - my ($path, $paths_abs, $paths_any) = @_; + my ($path) = @_; - foreach (@$paths_abs) { + foreach (@skip_abs) { return 1 if (/^$path$/); } my($filename, $dirs, $suffix) = fileparse($path); - foreach (@$paths_any) { + foreach (@skip_any) { return 1 if (/^$filename$/); } return 0; } -sub skip_parse -{ - my ($path) = @_; - return skip($path, \@skip_parse_files_abs, \@skip_parse_files_any); -} - sub timed_parse_file { my ($file) = @_; @@ -466,12 +445,6 @@ sub parse_file return; } - if (skip_parse($file)) { - dprint "skipping file: $file\n"; - return; - } - dprint "parsing: $file\n"; - open my $fh, "<", $file or return; while ( <$fh> ) { if (may_leak_address($_)) { @@ -481,21 +454,12 @@ sub parse_file close $fh; } - -# True if we should skip walking this directory. -sub skip_walk -{ - my ($path) = @_; - return skip($path, \@skip_walk_dirs_abs, \@skip_walk_dirs_any) -} - # Recursively walk directory tree. sub walk { my @dirs = @_; while (my $pwd = shift @dirs) { - next if (skip_walk($pwd)); next if (!opendir(DIR, $pwd)); my @files = readdir(DIR); closedir(DIR); @@ -506,11 +470,15 @@ sub walk my $path = "$pwd/$file"; next if (-l $path); + next if (skip($path)); + if (-d $path) { push @dirs, $path; - } else { - timed_parse_file($path); + next; } + + dprint "parsing: $file\n"; + timed_parse_file($path); } } }