All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] checkpatch: add warning on invalid %p extensions
@ 2017-02-10 22:43 ` william.c.roberts
  0 siblings, 0 replies; 4+ messages in thread
From: william.c.roberts @ 2017-02-10 22:43 UTC (permalink / raw)
  To: linux-kernel, joe, apw; +Cc: keescook, kernel-hardening, William Roberts

From: William Roberts <william.c.roberts@intel.com>

The kernel supports %p extensions as documented in
Documentation/printk-formats.txt. Warn on possibly
improper use of non-extension characters.

One issue would be the usage of %pk when %pK should have
been used. This has a side-effect of appearing to work
alright, but does not respect the kptr_restrict setting
as %pK does.

Sample output:
WARNING: Invalid vsprintf pointer extension '%pk'
+			printk(KERN_INFO "Could not allocate IRQ %d for PCI Applicom device. %pk\n", dev->irq, pci_get_class); // NOT OK

WARNING: Invalid vsprintf pointer extension '%pn'
+			sprintf(buf, "%pn", x); // NOT OK

Signed-off-by: William Roberts <william.c.roberts@intel.com>
---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 982c52c..fa22751 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6096,6 +6096,12 @@ sub process {
 			      "recursive locking is bad, do not use this ever.\n" . $herecurr);
 		}
 
+# check for vsprintf extension %p<foo> misuses
+		if (get_quoted_string($line, $rawline) =~ /(\%[\*\d\.]*p(?![\WFfSsBKRraEhMmIiUDdgVCbGN]).)/) {
+			WARN("VSPRINTF_POINTER_EXTENSION",
+			     "Invalid vsprintf pointer extension '$1'\n" . $herecurr);
+		}
+
 # check for lockdep_set_novalidate_class
 		if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
 		    $line =~ /__lockdep_no_validate__\s*\)/ ) {
-- 
2.7.4

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

* [kernel-hardening] [PATCH v2] checkpatch: add warning on invalid %p extensions
@ 2017-02-10 22:43 ` william.c.roberts
  0 siblings, 0 replies; 4+ messages in thread
From: william.c.roberts @ 2017-02-10 22:43 UTC (permalink / raw)
  To: linux-kernel, joe, apw; +Cc: keescook, kernel-hardening, William Roberts

From: William Roberts <william.c.roberts@intel.com>

The kernel supports %p extensions as documented in
Documentation/printk-formats.txt. Warn on possibly
improper use of non-extension characters.

One issue would be the usage of %pk when %pK should have
been used. This has a side-effect of appearing to work
alright, but does not respect the kptr_restrict setting
as %pK does.

Sample output:
WARNING: Invalid vsprintf pointer extension '%pk'
+			printk(KERN_INFO "Could not allocate IRQ %d for PCI Applicom device. %pk\n", dev->irq, pci_get_class); // NOT OK

WARNING: Invalid vsprintf pointer extension '%pn'
+			sprintf(buf, "%pn", x); // NOT OK

Signed-off-by: William Roberts <william.c.roberts@intel.com>
---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 982c52c..fa22751 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6096,6 +6096,12 @@ sub process {
 			      "recursive locking is bad, do not use this ever.\n" . $herecurr);
 		}
 
+# check for vsprintf extension %p<foo> misuses
+		if (get_quoted_string($line, $rawline) =~ /(\%[\*\d\.]*p(?![\WFfSsBKRraEhMmIiUDdgVCbGN]).)/) {
+			WARN("VSPRINTF_POINTER_EXTENSION",
+			     "Invalid vsprintf pointer extension '$1'\n" . $herecurr);
+		}
+
 # check for lockdep_set_novalidate_class
 		if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
 		    $line =~ /__lockdep_no_validate__\s*\)/ ) {
-- 
2.7.4

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

* Re: [PATCH v2] checkpatch: add warning on invalid %p extensions
  2017-02-10 22:43 ` [kernel-hardening] " william.c.roberts
@ 2017-02-10 22:49   ` Joe Perches
  -1 siblings, 0 replies; 4+ messages in thread
From: Joe Perches @ 2017-02-10 22:49 UTC (permalink / raw)
  To: william.c.roberts, linux-kernel, apw; +Cc: keescook, kernel-hardening

On Fri, 2017-02-10 at 14:43 -0800, william.c.roberts@intel.com wrote:
> From: William Roberts <william.c.roberts@intel.com>
> 
> The kernel supports %p extensions as documented in
> Documentation/printk-formats.txt. Warn on possibly
> improper use of non-extension characters.
> 
> One issue would be the usage of %pk when %pK should have
> been used. This has a side-effect of appearing to work
> alright, but does not respect the kptr_restrict setting
> as %pK does.
> 
> Sample output:
> WARNING: Invalid vsprintf pointer extension '%pk'
> +			printk(KERN_INFO "Could not allocate IRQ %d for PCI Applicom device. %pk\n", dev->irq, pci_get_class); // NOT OK
> 
> WARNING: Invalid vsprintf pointer extension '%pn'
> +			sprintf(buf, "%pn", x); // NOT OK
> 
> Signed-off-by: William Roberts <william.c.roberts@intel.com>
> ---
>  scripts/checkpatch.pl | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 982c52c..fa22751 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -6096,6 +6096,12 @@ sub process {
>  			      "recursive locking is bad, do not use this ever.\n" . $herecurr);
>  		}
>  
> +# check for vsprintf extension %p<foo> misuses
> +		if (get_quoted_string($line, $rawline) =~ /(\%[\*\d\.]*p(?![\WFfSsBKRraEhMmIiUDdgVCbGN]).)/) {
> +			WARN("VSPRINTF_POINTER_EXTENSION",
> +			     "Invalid vsprintf pointer extension '$1'\n" . $herecurr);
> +		}
> +

nack.

You can't just use get_quoted_string.

You have to verify that the thing being scanned is
actually a format.  There are many quoted uses of
%p like %%pil and %%pstate used by inline assembly.

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

* [kernel-hardening] Re: [PATCH v2] checkpatch: add warning on invalid %p extensions
@ 2017-02-10 22:49   ` Joe Perches
  0 siblings, 0 replies; 4+ messages in thread
From: Joe Perches @ 2017-02-10 22:49 UTC (permalink / raw)
  To: william.c.roberts, linux-kernel, apw; +Cc: keescook, kernel-hardening

On Fri, 2017-02-10 at 14:43 -0800, william.c.roberts@intel.com wrote:
> From: William Roberts <william.c.roberts@intel.com>
> 
> The kernel supports %p extensions as documented in
> Documentation/printk-formats.txt. Warn on possibly
> improper use of non-extension characters.
> 
> One issue would be the usage of %pk when %pK should have
> been used. This has a side-effect of appearing to work
> alright, but does not respect the kptr_restrict setting
> as %pK does.
> 
> Sample output:
> WARNING: Invalid vsprintf pointer extension '%pk'
> +			printk(KERN_INFO "Could not allocate IRQ %d for PCI Applicom device. %pk\n", dev->irq, pci_get_class); // NOT OK
> 
> WARNING: Invalid vsprintf pointer extension '%pn'
> +			sprintf(buf, "%pn", x); // NOT OK
> 
> Signed-off-by: William Roberts <william.c.roberts@intel.com>
> ---
>  scripts/checkpatch.pl | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 982c52c..fa22751 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -6096,6 +6096,12 @@ sub process {
>  			      "recursive locking is bad, do not use this ever.\n" . $herecurr);
>  		}
>  
> +# check for vsprintf extension %p<foo> misuses
> +		if (get_quoted_string($line, $rawline) =~ /(\%[\*\d\.]*p(?![\WFfSsBKRraEhMmIiUDdgVCbGN]).)/) {
> +			WARN("VSPRINTF_POINTER_EXTENSION",
> +			     "Invalid vsprintf pointer extension '$1'\n" . $herecurr);
> +		}
> +

nack.

You can't just use get_quoted_string.

You have to verify that the thing being scanned is
actually a format.  There are many quoted uses of
%p like %%pil and %%pstate used by inline assembly.

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

end of thread, other threads:[~2017-02-10 22:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-10 22:43 [PATCH v2] checkpatch: add warning on invalid %p extensions william.c.roberts
2017-02-10 22:43 ` [kernel-hardening] " william.c.roberts
2017-02-10 22:49 ` Joe Perches
2017-02-10 22:49   ` [kernel-hardening] " Joe Perches

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.