[13/13] Re-enable and clean up "check_config()" in headers_check.pl
diff mbox

Message ID 1446579994-9937-14-git-send-email-palmer@dabbelt.com
State New
Headers show

Commit Message

Palmer Dabbelt Nov. 3, 2015, 7:46 p.m. UTC
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 <palmer@dabbelt.com>
Reviewed-by: Andrew Waterman <waterman@eecs.berkeley.edu>
Reviewed-by: Albert Ou <aou@eecs.berkeley.edu>
---
 scripts/headers_check.pl | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

Comments

kbuild test robot Nov. 3, 2015, 8:25 p.m. UTC | #1
Hi Palmer,

[auto build test WARNING on v4.3-rc7]
[also WARNING on: next-20151103]

url:    https://github.com/0day-ci/linux/commits/Palmer-Dabbelt/Remove-ifdef-CONFIG_64BIT-from-all-asm-generic-fcntl-h/20151104-035501
base:   https://github.com/0day-ci/linux Palmer-Dabbelt/Remove-ifdef-CONFIG_64BIT-from-all-asm-generic-fcntl-h/20151104-035501
config: blackfin-TCM-BF537_defconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=blackfin 

All warnings (new ones prefixed by >>):

>> ./usr/include/asm/fixed_code.h:14: leaks CONFIG_PHY_RAM_BASE_ADDRESS to userspace where it is not valid
   ./usr/include/asm/fixed_code.h:15: leaks CONFIG_PHY_RAM_BASE_ADDRESS to userspace where it is not valid
   ./usr/include/asm/fixed_code.h:18: leaks CONFIG_PHY_RAM_BASE_ADDRESS to userspace where it is not valid
   ./usr/include/asm/fixed_code.h:20: leaks CONFIG_PHY_RAM_BASE_ADDRESS to userspace where it is not valid
   ./usr/include/asm/fixed_code.h:22: leaks CONFIG_PHY_RAM_BASE_ADDRESS to userspace where it is not valid
   ./usr/include/asm/fixed_code.h:24: leaks CONFIG_PHY_RAM_BASE_ADDRESS to userspace where it is not valid
   ./usr/include/asm/fixed_code.h:25: leaks CONFIG_PHY_RAM_BASE_ADDRESS to userspace where it is not valid
   ./usr/include/asm/fixed_code.h:26: leaks CONFIG_PHY_RAM_BASE_ADDRESS to userspace where it is not valid
   ./usr/include/asm/fixed_code.h:27: leaks CONFIG_PHY_RAM_BASE_ADDRESS to userspace where it is not valid
   ./usr/include/asm/fixed_code.h:28: leaks CONFIG_PHY_RAM_BASE_ADDRESS to userspace where it is not valid
   ./usr/include/asm/fixed_code.h:29: leaks CONFIG_PHY_RAM_BASE_ADDRESS to userspace where it is not valid
   ./usr/include/asm/fixed_code.h:30: leaks CONFIG_PHY_RAM_BASE_ADDRESS to userspace where it is not valid
   ./usr/include/asm/fixed_code.h:32: leaks CONFIG_PHY_RAM_BASE_ADDRESS to userspace where it is not valid
   ./usr/include/asm/fixed_code.h:34: leaks CONFIG_PHY_RAM_BASE_ADDRESS to userspace where it is not valid
   ./usr/include/asm/fixed_code.h:36: leaks CONFIG_PHY_RAM_BASE_ADDRESS to userspace where it is not valid

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
kbuild test robot Nov. 3, 2015, 8:26 p.m. UTC | #2
Hi Palmer,

[auto build test WARNING on v4.3-rc7]
[also WARNING on: next-20151103]

url:    https://github.com/0day-ci/linux/commits/Palmer-Dabbelt/Remove-ifdef-CONFIG_64BIT-from-all-asm-generic-fcntl-h/20151104-035501
base:   https://github.com/0day-ci/linux Palmer-Dabbelt/Remove-ifdef-CONFIG_64BIT-from-all-asm-generic-fcntl-h/20151104-035501
config: alpha-defconfig (attached as .config)
reproduce:
        wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=alpha 

All warnings (new ones prefixed by >>):

>> ./usr/include/asm/setup.h:16: leaks CONFIG_ALPHA_LEGACY_START_ADDRESS to userspace where it is not valid

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

Patch
diff mbox

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";
 	}
 }