From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932643AbbKCTr1 (ORCPT ); Tue, 3 Nov 2015 14:47:27 -0500 Received: from mail-pa0-f45.google.com ([209.85.220.45]:35118 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932594AbbKCTrD (ORCPT ); Tue, 3 Nov 2015 14:47:03 -0500 From: Palmer Dabbelt To: arnd@arndb.de To: dhowells@redhat.com Cc: viro@zeniv.linux.org.uk Cc: ast@plumgrid.com Cc: aishchuk@linux.vnet.ibm.com Cc: aarcange@redhat.com Cc: akpm@linux-foundation.org Cc: luto@kernel.org Cc: acme@kernel.org Cc: bhe@redhat.com Cc: 3chas3@gmail.com Cc: chris@zankel.net Cc: dave@sr71.net Cc: dyoung@redhat.com Cc: drysdale@google.com Cc: davem@davemloft.net Cc: ebiederm@xmission.com Cc: geoff@infradead.org Cc: gregkh@linuxfoundation.org Cc: hpa@zytor.com Cc: mingo@kernel.org Cc: iulia.manda21@gmail.com Cc: plagnioj@jcrosoft.com Cc: jikos@kernel.org Cc: josh@joshtriplett.org Cc: kexec@lists.infradead.org Cc: linux-api@vger.kernel.org Cc: linux-arch@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: linux-xtensa@linux-xtensa.org Cc: mathieu.desnoyers@efficios.com Cc: jcmvbkbc@gmail.com Cc: paulmck@linux.vnet.ibm.com Cc: a.p.zijlstra@chello.nl Cc: tglx@linutronix.de Cc: tomi.valkeinen@ti.com Cc: vgoyal@redhat.com Cc: x86@kernel.org Cc: Palmer Dabbelt Subject: [PATCH 13/13] Re-enable and clean up "check_config()" in headers_check.pl Date: Tue, 3 Nov 2015 11:46:34 -0800 Message-Id: <1446579994-9937-14-git-send-email-palmer@dabbelt.com> X-Mailer: git-send-email 2.4.10 In-Reply-To: <1446579994-9937-1-git-send-email-palmer@dabbelt.com> References: <1442271047-4908-1-git-send-email-palmer@dabbelt.com> <1446579994-9937-1-git-send-email-palmer@dabbelt.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I recently got bit by a CONFIG_ in userspace bug. This has apparently happened before, but the check got disabled for triggering too much. In order to reduce false positives, I added some hueristics to avoid detecting comments. Since these tests all pass, I've now re-enabled them. Signed-off-by: Palmer Dabbelt Reviewed-by: Andrew Waterman Reviewed-by: Albert Ou --- scripts/headers_check.pl | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/scripts/headers_check.pl b/scripts/headers_check.pl index 62320f9..1634b51 100755 --- a/scripts/headers_check.pl +++ b/scripts/headers_check.pl @@ -27,6 +27,7 @@ my $ret = 0; my $line; my $lineno = 0; my $filename; +my $check_config_in_multiline_comment = 0; foreach my $file (@files) { $filename = $file; @@ -40,7 +41,7 @@ foreach my $file (@files) { &check_asm_types(); &check_sizetypes(); &check_declarations(); - # Dropped for now. Too much noise &check_config(); + &check_config(); } close $fh; } @@ -78,7 +79,21 @@ sub check_declarations sub check_config { - if ($line =~ m/[^a-zA-Z0-9_]+CONFIG_([a-zA-Z0-9_]+)[^a-zA-Z0-9_]/) { + my $nocomments = $line; + $nocomments =~ s/\/\*.*\*\///; # Remove ANSI-style comments (/* to */) + $nocomments =~ s/\/\/.*//; # Remove C99-style comments (// to EOL) + + # Check to see if we're within a multiline comment, and if so + # just remove the whole line. I tried matching on '^ * ', but + # there's one header that doesn't prepend multi-line comments + # with * so that won't work. + if ($nocomments =~ m/\/\*/) { $check_config_in_multiline_comment = 1; } + if ($nocomments =~ m/\*\//) { $check_config_in_multiline_comment = 0; } + if ($check_config_in_multiline_comment == 1) { $nocomments = "" } + + # Check to see if there is something that looks like CONFIG_ + # inside a userspace-accessible header file and if so, print that out. + if ($nocomments =~ m/[^a-zA-Z0-9_]+CONFIG_([a-zA-Z0-9_]+)[^a-zA-Z0-9_]/) { printf STDERR "$filename:$lineno: leaks CONFIG_$1 to userspace where it is not valid\n"; } } -- 2.4.10