From patchwork Fri Feb 10 20:12:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Perches X-Patchwork-Id: 9567425 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1036B60216 for ; Fri, 10 Feb 2017 20:12:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3875285BD for ; Fri, 10 Feb 2017 20:12:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8416285C6; Fri, 10 Feb 2017 20:12:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 02EB7285BD for ; Fri, 10 Feb 2017 20:12:46 +0000 (UTC) Received: (qmail 7732 invoked by uid 550); 10 Feb 2017 20:12:45 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 7702 invoked from network); 10 Feb 2017 20:12:43 -0000 X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: soda17_501829ca92e1d X-Filterd-Recvd-Size: 2222 Message-ID: <1486757549.2192.20.camel@perches.com> From: Joe Perches To: william.c.roberts@intel.com, linux-kernel@vger.kernel.org, apw@canonical.com, Andew Morton Cc: keescook@chromium.org, kernel-hardening@lists.openwall.com Date: Fri, 10 Feb 2017 12:12:29 -0800 In-Reply-To: <1486755469-21573-1-git-send-email-william.c.roberts@intel.com> References: <1486755469-21573-1-git-send-email-william.c.roberts@intel.com> X-Mailer: Evolution 3.22.3-0ubuntu0.1 Mime-Version: 1.0 Subject: [kernel-hardening] Re: [PATCH] checkpatch: add warning on %pk instead of %pK usage X-Virus-Scanned: ClamAV using ClamSMTP On Fri, 2017-02-10 at 11:37 -0800, william.c.roberts@intel.com wrote: > From: William Roberts > > Sample output: > WARNING: %pk is close to %pK, did you mean %pK?. > \#20: FILE: drivers/char/applicom.c:230: > + printk(KERN_INFO "Could not allocate IRQ %d for PCI Applicom device. %pk\n", dev->irq, pci_get_class); There isn't a single instance of this in the kernel tree. Maybe if this is really useful, then all the %p extensions should be enumerated and all unknown uses should have warnings. Something like: --- scripts/checkpatch.pl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index ad5ea5c545b2..8a90b457e8b5 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -5305,6 +5305,15 @@ sub process { } } +# check for vsprintf extension %p misuses + if ($line =~ /\b$logFunctions\s*\(.*$String/) { + my $format = get_quoted_string($line, $rawline); + if ($format =~ /(\%[\*\d\.]*p(?![\WFfSsBKRraEhMmIiUDdgVCbGN]).)/) { + WARN("VSPRINTF_POINTER_EXTENSION", + "Invalid vsprintf pointer extension '$1'\n" . $herecurr); + } + } + # check for logging continuations if ($line =~ /\bprintk\s*\(\s*KERN_CONT\b|\bpr_cont\s*\(/) { WARN("LOGGING_CONTINUATION",