linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] checkpatch: warn for use of %px
@ 2017-12-06  3:37 Tobin C. Harding
  2017-12-06  3:37 ` [PATCH v2 1/3] checkpatch: add sub routine get_stat_real() Tobin C. Harding
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Tobin C. Harding @ 2017-12-06  3:37 UTC (permalink / raw)
  To: Joe Perches; +Cc: Tobin C. Harding, Andy Whitcroft, linux-kernel

Patch 1 and 2 are cleanup patches. Each adds a new subroutine to remove
duplicate code.

Patch 3: Make checkpatch emit a warning for usage of specifier %px. 

The initial idea to emit the warning was given on LKML by Andrew Morton,
v1 requested permission to use 'Suggested-by' tag. This version does not
add that tag.

thanks,
Tobin.

v2:
 - change new sub name stat_real() -> get_stat_real()
 - add new sub get_stat_here()
 - (add new sub routines as separate patches)
 - add 'Acked-by' tag for Joe
 - remove 'Suggested-by' tag for Andrew Morton

Tobin C. Harding (3):
  checkpatch: add sub routine get_stat_real()
  checkpatch: add sub routine get_stat_here()
  checkpatch: warn for use of %px

 scripts/checkpatch.pl | 114 +++++++++++++++++++++++++-------------------------
 1 file changed, 58 insertions(+), 56 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/3] checkpatch: add sub routine get_stat_real()
  2017-12-06  3:37 [PATCH v2 0/3] checkpatch: warn for use of %px Tobin C. Harding
@ 2017-12-06  3:37 ` Tobin C. Harding
  2017-12-06  3:37 ` [PATCH v2 2/3] checkpatch: add sub routine get_stat_here() Tobin C. Harding
  2017-12-06  3:37 ` [PATCH v2 3/3] checkpatch: warn for use of %px Tobin C. Harding
  2 siblings, 0 replies; 8+ messages in thread
From: Tobin C. Harding @ 2017-12-06  3:37 UTC (permalink / raw)
  To: Joe Perches; +Cc: Tobin C. Harding, Andy Whitcroft, linux-kernel

checkpatch currently contains duplicate code. We can define a sub
routine and call that instead. This reduces code duplication and line
count.

Add subroutine get_stat_real()

Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
 scripts/checkpatch.pl | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 040aa79e1d9d..5a63aa36300a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1612,6 +1612,17 @@ sub raw_line {
 	return $line;
 }
 
+sub get_stat_real {
+	my ($linenr, $lc) = @_;
+
+	my $stat_real = raw_line($linenr, 0);
+	for (my $count = $linenr + 1; $count <= $lc; $count++) {
+		$stat_real = $stat_real . "\n" . raw_line($count, 0);
+	}
+
+	return $stat_real;
+}
+
 sub cat_vet {
 	my ($vet) = @_;
 	my ($res, $coded);
@@ -5759,10 +5770,7 @@ sub process {
 				}
 			}
 			if ($bad_extension ne "") {
-				my $stat_real = raw_line($linenr, 0);
-				for (my $count = $linenr + 1; $count <= $lc; $count++) {
-					$stat_real = $stat_real . "\n" . raw_line($count, 0);
-				}
+				my $stat_real = get_stat_real($linenr, $lc);
 				WARN("VSPRINTF_POINTER_EXTENSION",
 				     "Invalid vsprintf pointer extension '$bad_extension'\n" . "$here\n$stat_real\n");
 			}
@@ -5877,10 +5885,7 @@ sub process {
 		     $stat !~ /(?:$Compare)\s*\bsscanf\s*$balanced_parens/)) {
 			my $lc = $stat =~ tr@\n@@;
 			$lc = $lc + $linenr;
-			my $stat_real = raw_line($linenr, 0);
-		        for (my $count = $linenr + 1; $count <= $lc; $count++) {
-				$stat_real = $stat_real . "\n" . raw_line($count, 0);
-			}
+			my $stat_real = get_stat_real($linenr, $lc);
 			WARN("NAKED_SSCANF",
 			     "unchecked sscanf return value\n" . "$here\n$stat_real\n");
 		}
@@ -5891,10 +5896,7 @@ sub process {
 		    $line =~ /\bsscanf\b/) {
 			my $lc = $stat =~ tr@\n@@;
 			$lc = $lc + $linenr;
-			my $stat_real = raw_line($linenr, 0);
-		        for (my $count = $linenr + 1; $count <= $lc; $count++) {
-				$stat_real = $stat_real . "\n" . raw_line($count, 0);
-			}
+			my $stat_real = get_stat_real($linenr, $lc);
 			if ($stat_real =~ /\bsscanf\b\s*\(\s*$FuncArg\s*,\s*("[^"]+")/) {
 				my $format = $6;
 				my $count = $format =~ tr@%@%@;
@@ -6289,10 +6291,7 @@ sub process {
 
 				my $lc = $stat =~ tr@\n@@;
 				$lc = $lc + $linenr;
-				my $stat_real = raw_line($linenr, 0);
-				for (my $count = $linenr + 1; $count <= $lc; $count++) {
-					$stat_real = $stat_real . "\n" . raw_line($count, 0);
-				}
+				my $stat_real = get_stat_real($linenr, $lc);
 
 				my $skip_args = "";
 				if ($arg_pos > 1) {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/3] checkpatch: add sub routine get_stat_here()
  2017-12-06  3:37 [PATCH v2 0/3] checkpatch: warn for use of %px Tobin C. Harding
  2017-12-06  3:37 ` [PATCH v2 1/3] checkpatch: add sub routine get_stat_real() Tobin C. Harding
@ 2017-12-06  3:37 ` Tobin C. Harding
  2017-12-06  3:37 ` [PATCH v2 3/3] checkpatch: warn for use of %px Tobin C. Harding
  2 siblings, 0 replies; 8+ messages in thread
From: Tobin C. Harding @ 2017-12-06  3:37 UTC (permalink / raw)
  To: Joe Perches; +Cc: Tobin C. Harding, Andy Whitcroft, linux-kernel

checkpatch currently contains duplicate code. We can define a sub
routine and call that instead. This reduces code duplication and line
count.

Add subroutine get_stat_here()

Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
 scripts/checkpatch.pl | 54 +++++++++++++++++++--------------------------------
 1 file changed, 20 insertions(+), 34 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 5a63aa36300a..4534c9a9aefa 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1623,6 +1623,17 @@ sub get_stat_real {
 	return $stat_real;
 }
 
+sub get_stat_here {
+	my ($linenr, $cnt, $here) = @_;
+
+	my $herectx = $here . "\n";
+	for (my $n = 0; $n < $cnt; $n++) {
+		$herectx .= raw_line($linenr, $n) . "\n";
+	}
+
+	return $herectx;
+}
+
 sub cat_vet {
 	my ($vet) = @_;
 	my ($res, $coded);
@@ -4911,12 +4922,8 @@ sub process {
 			#print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
 
 			$ctx =~ s/\n*$//;
-			my $herectx = $here . "\n";
 			my $stmt_cnt = statement_rawlines($ctx);
-
-			for (my $n = 0; $n < $stmt_cnt; $n++) {
-				$herectx .= raw_line($linenr, $n) . "\n";
-			}
+			my $herectx = get_stat_here($linenr, $stmt_cnt, $here);
 
 			if ($dstat ne '' &&
 			    $dstat !~ /^(?:$Ident|-?$Constant),$/ &&			# 10, // foo(),
@@ -4988,12 +4995,9 @@ sub process {
 # check for macros with flow control, but without ## concatenation
 # ## concatenation is commonly a macro that defines a function so ignore those
 			if ($has_flow_statement && !$has_arg_concat) {
-				my $herectx = $here . "\n";
 				my $cnt = statement_rawlines($ctx);
+				my $herectx = get_stat_here($linenr, $cnt, $here);
 
-				for (my $n = 0; $n < $cnt; $n++) {
-					$herectx .= raw_line($linenr, $n) . "\n";
-				}
 				WARN("MACRO_WITH_FLOW_CONTROL",
 				     "Macros with flow control statements should be avoided\n" . "$herectx");
 			}
@@ -5033,11 +5037,7 @@ sub process {
 
 				$ctx =~ s/\n*$//;
 				my $cnt = statement_rawlines($ctx);
-				my $herectx = $here . "\n";
-
-				for (my $n = 0; $n < $cnt; $n++) {
-					$herectx .= raw_line($linenr, $n) . "\n";
-				}
+				my $herectx = get_stat_here($linenr, $cnt, $here);
 
 				if (($stmts =~ tr/;/;/) == 1 &&
 				    $stmts !~ /^\s*(if|while|for|switch)\b/) {
@@ -5051,11 +5051,7 @@ sub process {
 			} elsif ($dstat =~ /^\+\s*#\s*define\s+$Ident.*;\s*$/) {
 				$ctx =~ s/\n*$//;
 				my $cnt = statement_rawlines($ctx);
-				my $herectx = $here . "\n";
-
-				for (my $n = 0; $n < $cnt; $n++) {
-					$herectx .= raw_line($linenr, $n) . "\n";
-				}
+				my $herectx = get_stat_here($linenr, $cnt, $here);
 
 				WARN("TRAILING_SEMICOLON",
 				     "macros should not use a trailing semicolon\n" . "$herectx");
@@ -5178,12 +5174,8 @@ sub process {
 				}
 			}
 			if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) {
-				my $herectx = $here . "\n";
 				my $cnt = statement_rawlines($block);
-
-				for (my $n = 0; $n < $cnt; $n++) {
-					$herectx .= raw_line($linenr, $n) . "\n";
-				}
+				my $herectx = get_stat_here($linenr, $cnt, $here);
 
 				WARN("BRACES",
 				     "braces {} are not necessary for single statement blocks\n" . $herectx);
@@ -6026,12 +6018,9 @@ sub process {
 			}
 			if ($r1 !~ /^sizeof\b/ && $r2 =~ /^sizeof\s*\S/ &&
 			    !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) {
-				my $ctx = '';
-				my $herectx = $here . "\n";
 				my $cnt = statement_rawlines($stat);
-				for (my $n = 0; $n < $cnt; $n++) {
-					$herectx .= raw_line($linenr, $n) . "\n";
-				}
+				my $herectx = get_stat_here($linenr, $cnt, $here);
+
 				if (WARN("ALLOC_WITH_MULTIPLY",
 					 "Prefer $newfunc over $oldfunc with multiply\n" . $herectx) &&
 				    $cnt == 1 &&
@@ -6114,12 +6103,9 @@ sub process {
 		if ($^V && $^V ge 5.10.0 &&
 		    defined $stat &&
 		    $stat =~ /^\+[$;\s]*(?:case[$;\s]+\w+[$;\s]*:[$;\s]*|)*[$;\s]*\bdefault[$;\s]*:[$;\s]*;/g) {
-			my $ctx = '';
-			my $herectx = $here . "\n";
 			my $cnt = statement_rawlines($stat);
-			for (my $n = 0; $n < $cnt; $n++) {
-				$herectx .= raw_line($linenr, $n) . "\n";
-			}
+			my $herectx = get_stat_here($linenr, $cnt, $here);
+
 			WARN("DEFAULT_NO_BREAK",
 			     "switch default: should use break\n" . $herectx);
 		}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 3/3] checkpatch: warn for use of %px
  2017-12-06  3:37 [PATCH v2 0/3] checkpatch: warn for use of %px Tobin C. Harding
  2017-12-06  3:37 ` [PATCH v2 1/3] checkpatch: add sub routine get_stat_real() Tobin C. Harding
  2017-12-06  3:37 ` [PATCH v2 2/3] checkpatch: add sub routine get_stat_here() Tobin C. Harding
@ 2017-12-06  3:37 ` Tobin C. Harding
  2017-12-07 21:06   ` Tobin C. Harding
  2 siblings, 1 reply; 8+ messages in thread
From: Tobin C. Harding @ 2017-12-06  3:37 UTC (permalink / raw)
  To: Joe Perches; +Cc: Tobin C. Harding, Andy Whitcroft, linux-kernel

Usage of the new %px specifier potentially leaks sensitive
inforamtion. Printing kernel addresses exposes the kernel layout in
memory, this is potentially exploitable. We have tools in the kernel to
help us do the right thing. We can have checkpatch warn developers of
potential dangers of using %px.

Have checkpatch emit a warning for usage of specifier %px.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
Co-developed-by: Joe Perches <joe@perches.com>
Acked-by: Joe Perches <joe@perches.com>
---
 scripts/checkpatch.pl | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4534c9a9aefa..6df99d1ebca5 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5750,21 +5750,38 @@ sub process {
 		    defined $stat &&
 		    $stat =~ /^\+(?![^\{]*\{\s*).*\b(\w+)\s*\(.*$String\s*,/s &&
 		    $1 !~ /^_*volatile_*$/) {
-			my $bad_extension = "";
+			my $specifier;
+			my $extension;
+			my $bad_specifier = "";
+			my $stat_real;
+
 			my $lc = $stat =~ tr@\n@@;
 			$lc = $lc + $linenr;
 		        for (my $count = $linenr; $count <= $lc; $count++) {
 				my $fmt = get_quoted_string($lines[$count - 1], raw_line($count, 0));
 				$fmt =~ s/%%//g;
-				if ($fmt =~ /(\%[\*\d\.]*p(?![\WFfSsBKRraEhMmIiUDdgVCbGNOx]).)/) {
-					$bad_extension = $1;
-					last;
+
+				while ($fmt =~ /(\%[\*\d\.]*p(\w))/g) {
+					$specifier = $1;
+					$extension = $2;
+					if ($extension !~ /[FfSsBKRraEhMmIiUDdgVCbGNOx]/) {
+						$bad_specifier = $specifier;
+						last;
+					}
+					if ($extension eq "x" && !defined($stat_real)) {
+						if (!defined($stat_real)) {
+							$stat_real = get_stat_real($linenr, $lc);
+						}
+						WARN("VSPRINTF_SPECIFIER_PX",
+						     "Using vsprintf specifier '\%px' potentially exposes the kernel memory layout, if you don't really need the address please consider using '\%p'.\n" . "$here\n$stat_real\n");
+					}
 				}
+
 			}
-			if ($bad_extension ne "") {
-				my $stat_real = get_stat_real($linenr, $lc);
+			if ($bad_specifier ne "") {
+				$stat_real = get_stat_real($linenr, $lc);
 				WARN("VSPRINTF_POINTER_EXTENSION",
-				     "Invalid vsprintf pointer extension '$bad_extension'\n" . "$here\n$stat_real\n");
+				     "Invalid vsprintf pointer extension '$bad_specifier'\n" . "$here\n$stat_real\n");
 			}
 		}
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 3/3] checkpatch: warn for use of %px
  2017-12-06  3:37 ` [PATCH v2 3/3] checkpatch: warn for use of %px Tobin C. Harding
@ 2017-12-07 21:06   ` Tobin C. Harding
  2017-12-07 21:15     ` Tobin C. Harding
  2017-12-07 21:17     ` Joe Perches
  0 siblings, 2 replies; 8+ messages in thread
From: Tobin C. Harding @ 2017-12-07 21:06 UTC (permalink / raw)
  To: Joe Perches; +Cc: Andy Whitcroft, linux-kernel

On Wed, Dec 06, 2017 at 02:37:08PM +1100, Tobin C. Harding wrote:
> Usage of the new %px specifier potentially leaks sensitive
> inforamtion. Printing kernel addresses exposes the kernel layout in
> memory, this is potentially exploitable. We have tools in the kernel to
> help us do the right thing. We can have checkpatch warn developers of
> potential dangers of using %px.
> 
> Have checkpatch emit a warning for usage of specifier %px.
> 
> Signed-off-by: Tobin C. Harding <me@tobin.cc>
> Co-developed-by: Joe Perches <joe@perches.com>

  Co-Developed-by:

Woops.

Joe I didn't quite understand what you meant when you said that this
could go in via any tree. I'm still learning the whole kernel tree
management thing. Don't checkpatch patches go in via Andy's tree?

https://git.kernel.org/pub/scm/linux/kernel/git/apw/checkpatch.git/

In any case, please drop this set. I'll fix the tag and re-spin.

thanks,
Tobin.

> Acked-by: Joe Perches <joe@perches.com>
> ---
>  scripts/checkpatch.pl | 31 ++++++++++++++++++++++++-------
>  1 file changed, 24 insertions(+), 7 deletions(-)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 4534c9a9aefa..6df99d1ebca5 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -5750,21 +5750,38 @@ sub process {
>  		    defined $stat &&
>  		    $stat =~ /^\+(?![^\{]*\{\s*).*\b(\w+)\s*\(.*$String\s*,/s &&
>  		    $1 !~ /^_*volatile_*$/) {
> -			my $bad_extension = "";
> +			my $specifier;
> +			my $extension;
> +			my $bad_specifier = "";
> +			my $stat_real;
> +
>  			my $lc = $stat =~ tr@\n@@;
>  			$lc = $lc + $linenr;
>  		        for (my $count = $linenr; $count <= $lc; $count++) {
>  				my $fmt = get_quoted_string($lines[$count - 1], raw_line($count, 0));
>  				$fmt =~ s/%%//g;
> -				if ($fmt =~ /(\%[\*\d\.]*p(?![\WFfSsBKRraEhMmIiUDdgVCbGNOx]).)/) {
> -					$bad_extension = $1;
> -					last;
> +
> +				while ($fmt =~ /(\%[\*\d\.]*p(\w))/g) {
> +					$specifier = $1;
> +					$extension = $2;
> +					if ($extension !~ /[FfSsBKRraEhMmIiUDdgVCbGNOx]/) {
> +						$bad_specifier = $specifier;
> +						last;
> +					}
> +					if ($extension eq "x" && !defined($stat_real)) {
> +						if (!defined($stat_real)) {
> +							$stat_real = get_stat_real($linenr, $lc);
> +						}
> +						WARN("VSPRINTF_SPECIFIER_PX",
> +						     "Using vsprintf specifier '\%px' potentially exposes the kernel memory layout, if you don't really need the address please consider using '\%p'.\n" . "$here\n$stat_real\n");
> +					}
>  				}
> +
>  			}
> -			if ($bad_extension ne "") {
> -				my $stat_real = get_stat_real($linenr, $lc);
> +			if ($bad_specifier ne "") {
> +				$stat_real = get_stat_real($linenr, $lc);
>  				WARN("VSPRINTF_POINTER_EXTENSION",
> -				     "Invalid vsprintf pointer extension '$bad_extension'\n" . "$here\n$stat_real\n");
> +				     "Invalid vsprintf pointer extension '$bad_specifier'\n" . "$here\n$stat_real\n");
>  			}
>  		}
>  
> -- 
> 2.7.4
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 3/3] checkpatch: warn for use of %px
  2017-12-07 21:06   ` Tobin C. Harding
@ 2017-12-07 21:15     ` Tobin C. Harding
  2017-12-07 21:27       ` Joe Perches
  2017-12-07 21:17     ` Joe Perches
  1 sibling, 1 reply; 8+ messages in thread
From: Tobin C. Harding @ 2017-12-07 21:15 UTC (permalink / raw)
  To: Joe Perches; +Cc: Andy Whitcroft, linux-kernel

On Fri, Dec 08, 2017 at 08:06:53AM +1100, Tobin C. Harding wrote:
> On Wed, Dec 06, 2017 at 02:37:08PM +1100, Tobin C. Harding wrote:
> > Usage of the new %px specifier potentially leaks sensitive
> > inforamtion. Printing kernel addresses exposes the kernel layout in
> > memory, this is potentially exploitable. We have tools in the kernel to
> > help us do the right thing. We can have checkpatch warn developers of
> > potential dangers of using %px.
> > 
> > Have checkpatch emit a warning for usage of specifier %px.
> > 
> > Signed-off-by: Tobin C. Harding <me@tobin.cc>
> > Co-developed-by: Joe Perches <joe@perches.com>
> 
>   Co-Developed-by:
> 
> Woops.
> 
> Joe I didn't quite understand what you meant when you said that this
> could go in via any tree. I'm still learning the whole kernel tree
> management thing. Don't checkpatch patches go in via Andy's tree?
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/apw/checkpatch.git/

Oh, I see that tree is not super active. If there are no NACK's do you
want me to put this through my tree? Perhaps once the Co-Developed-by
stuff is in an acceptable form we could put them all together? Please do
say if I'm going about things wrong, here to learn.

thanks,
Tobin.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 3/3] checkpatch: warn for use of %px
  2017-12-07 21:06   ` Tobin C. Harding
  2017-12-07 21:15     ` Tobin C. Harding
@ 2017-12-07 21:17     ` Joe Perches
  1 sibling, 0 replies; 8+ messages in thread
From: Joe Perches @ 2017-12-07 21:17 UTC (permalink / raw)
  To: Tobin C. Harding; +Cc: Andy Whitcroft, linux-kernel

On Fri, 2017-12-08 at 08:06 +1100, Tobin C. Harding wrote:
> On Wed, Dec 06, 2017 at 02:37:08PM +1100, Tobin C. Harding wrote:
> > Usage of the new %px specifier potentially leaks sensitive
> > inforamtion. Printing kernel addresses exposes the kernel layout in
> > memory, this is potentially exploitable. We have tools in the kernel to
> > help us do the right thing. We can have checkpatch warn developers of
> > potential dangers of using %px.
> > 
> > Have checkpatch emit a warning for usage of specifier %px.
> > 
> > Signed-off-by: Tobin C. Harding <me@tobin.cc>
> > Co-developed-by: Joe Perches <joe@perches.com>
> 
>   Co-Developed-by:
> 
> Woops.
> 
> Joe I didn't quite understand what you meant when you said that this
> could go in via any tree. I'm still learning the whole kernel tree
> management thing. Don't checkpatch patches go in via Andy's tree?
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/apw/checkpatch.git/

No, not in quite awhile.

Most checkpatch patches go through Andrew Morton's
quilt/mm tree.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 3/3] checkpatch: warn for use of %px
  2017-12-07 21:15     ` Tobin C. Harding
@ 2017-12-07 21:27       ` Joe Perches
  0 siblings, 0 replies; 8+ messages in thread
From: Joe Perches @ 2017-12-07 21:27 UTC (permalink / raw)
  To: Tobin C. Harding; +Cc: Andy Whitcroft, linux-kernel

On Fri, 2017-12-08 at 08:15 +1100, Tobin C. Harding wrote:
> On Fri, Dec 08, 2017 at 08:06:53AM +1100, Tobin C. Harding wrote:
> > On Wed, Dec 06, 2017 at 02:37:08PM +1100, Tobin C. Harding wrote:
> > > Usage of the new %px specifier potentially leaks sensitive
> > > inforamtion. Printing kernel addresses exposes the kernel layout in
> > > memory, this is potentially exploitable. We have tools in the kernel to
> > > help us do the right thing. We can have checkpatch warn developers of
> > > potential dangers of using %px.
> > > 
> > > Have checkpatch emit a warning for usage of specifier %px.
> > > 
> > > Signed-off-by: Tobin C. Harding <me@tobin.cc>
> > > Co-developed-by: Joe Perches <joe@perches.com>
> > 
> >   Co-Developed-by:
> > 
> > Woops.
> > 
> > Joe I didn't quite understand what you meant when you said that this
> > could go in via any tree. I'm still learning the whole kernel tree
> > management thing. Don't checkpatch patches go in via Andy's tree?
> > 
> > https://git.kernel.org/pub/scm/linux/kernel/git/apw/checkpatch.git/
> 
> Oh, I see that tree is not super active. If there are no NACK's do you
> want me to put this through my tree? Perhaps once the Co-Developed-by
> stuff is in an acceptable form we could put them all together? Please do
> say if I'm going about things wrong, here to learn.

No worries, you could push it through your tree.

btw:  Here's an attempt at the case-sensitive signature matching
---
 scripts/checkpatch.pl | 47 ++++++++++++++++++++++++------------------
-----
 1 file changed, 24 insertions(+), 23 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 6b130a4116fa..59e8d62e0eb0 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -461,16 +461,18 @@ our $logFunctions = qr{(?x:
 	seq_vprintf|seq_printf|seq_puts
 )};
 
-our $signature_tags = qr{(?xi:
-	Signed-off-by:|
-	Acked-by:|
-	Tested-by:|
-	Reviewed-by:|
-	Reported-by:|
-	Suggested-by:|
-	To:|
-	Cc:
-)};
+our @valid_signatures = (
+	"Signed-off-by:",
+	"Acked-by:",
+	"Tested-by:",
+	"Reviewed-by:",
+	"Reported-by:",
+	"Suggested-by:",
+	"Co-Developed-by:",
+	"To:",
+	"Cc:"
+);
+my $signature_tags = "(?x:" . join('|', @valid_signatures) . ")";
 
 our @typeListMisordered = (
 	qr{char\s+(?:un)?signed},
@@ -2467,35 +2469,34 @@ sub process {
 			my $sign_off = $2;
 			my $space_after = $3;
 			my $email = $4;
-			my $ucfirst_sign_off = ucfirst(lc($sign_off));
+			my $preferred_sign_off = ucfirst(lc($sign_off));
 
-			if ($sign_off !~ /$signature_tags/) {
+			if ($sign_off !~ /$signature_tags/i) {
 				WARN("BAD_SIGN_OFF",
 				     "Non-standard signature: $sign_off\n" . $herecurr);
-			}
-			if (defined $space_before && $space_before ne "") {
+			} elsif ($sign_off !~ /$signature_tags/) {
+				$preferred_sign_off = $valid_signatures[ grep { $valid_signatures[$_] eq $sign_off } 0..$#valid_signatures ];
 				if (WARN("BAD_SIGN_OFF",
-					 "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr) &&
+					 "'$preferred_sign_off' is the preferred signature form\n" . $herecurr) &&
 				    $fix) {
-					$fixed[$fixlinenr] =
-					    "$ucfirst_sign_off $email";
+					$fixed[$fixlinenr] = "$preferred_sign_off $email";
 				}
 			}
-			if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {
+			if (defined $space_before && $space_before ne "") {
 				if (WARN("BAD_SIGN_OFF",
-					 "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr) &&
+					 "Do not use whitespace before $preferred_sign_off\n" . $herecurr) &&
 				    $fix) {
 					$fixed[$fixlinenr] =
-					    "$ucfirst_sign_off $email";
+					    "$preferred_sign_off $email";
 				}
-
 			}
+
 			if (!defined $space_after || $space_after ne " ") {
 				if (WARN("BAD_SIGN_OFF",
-					 "Use a single space after $ucfirst_sign_off\n" . $herecurr) &&
+					 "Use a single space after $preferred_sign_off\n" . $herecurr) &&
 				    $fix) {
 					$fixed[$fixlinenr] =
-					    "$ucfirst_sign_off $email";
+					    "$preferred_sign_off $email";
 				}
 			}
 

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-12-07 21:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-06  3:37 [PATCH v2 0/3] checkpatch: warn for use of %px Tobin C. Harding
2017-12-06  3:37 ` [PATCH v2 1/3] checkpatch: add sub routine get_stat_real() Tobin C. Harding
2017-12-06  3:37 ` [PATCH v2 2/3] checkpatch: add sub routine get_stat_here() Tobin C. Harding
2017-12-06  3:37 ` [PATCH v2 3/3] checkpatch: warn for use of %px Tobin C. Harding
2017-12-07 21:06   ` Tobin C. Harding
2017-12-07 21:15     ` Tobin C. Harding
2017-12-07 21:27       ` Joe Perches
2017-12-07 21:17     ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).