Skip to contentSkip to conversation

checkpatch: add warning on invalid %p extensions

PATCH Superseded [email protected] 2 participants 2 messages Feb 10, 2017 Checkpatch

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 checkpatch: add warning on invalid %p extensions

From: William Roberts <[email protected]>

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

---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)
scripts/checkpatch.pl +6 -0
index 982c52c..fa22751 100755
@@ -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*\)/ ) {
Signature · 1 line
2.7.4
maintainer NAK
#1 lore raw
Quoted 28 lines · On Fri, 2017-02-10 at 14:43 -0800, [email protected] wrote:

From: William Roberts <[email protected]>

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'

(quoted diff) +1 -0
+			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'

(quoted diff) +1 -0
+			sprintf(buf, "%pn", x); // NOT OK
---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)
scripts/checkpatch.pl +0 -0
index 982c52c..fa22751 100755

scripts/checkpatch.pl sub process { · line 6104

Quoted 9 lines
scripts/checkpatch.pl +6 -0
@@ -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.