From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752587AbdBJWtP (ORCPT ); Fri, 10 Feb 2017 17:49:15 -0500 Received: from smtprelay0165.hostedemail.com ([216.40.44.165]:50013 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752468AbdBJWtO (ORCPT ); Fri, 10 Feb 2017 17:49:14 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::,RULES_HIT:41:355:379:541:599:800:960:973:982:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2197:2199:2393:2559:2562:2828:2915:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3870:3871:3873:3874:4321:4605:5007:7576:7903:8957:10004:10028:10400:10848:11026:11232:11473:11658:11914:12043:12296:12438:12555:12740:12760:12895:12986:13069:13311:13357:13439:14181:14659:14721:21063:21080:21221:21434:21451:30054:30064:30070:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:27,LUA_SUMMARY:none X-HE-Tag: dolls35_8a6f26f68be07 X-Filterd-Recvd-Size: 2530 Message-ID: <1486766950.2192.29.camel@perches.com> Subject: Re: [PATCH v2] checkpatch: add warning on invalid %p extensions From: Joe Perches To: william.c.roberts@intel.com, linux-kernel@vger.kernel.org, apw@canonical.com Cc: keescook@chromium.org, kernel-hardening@lists.openwall.com Date: Fri, 10 Feb 2017 14:49:10 -0800 In-Reply-To: <1486766608-8791-1-git-send-email-william.c.roberts@intel.com> References: <1486766608-8791-1-git-send-email-william.c.roberts@intel.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.3-0ubuntu0.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2017-02-10 at 14:43 -0800, william.c.roberts@intel.com wrote: > From: William Roberts > > 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 > --- > 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 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.