From patchwork Fri Feb 10 22:43:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Roberts, William C" X-Patchwork-Id: 9567587 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 AE92760572 for ; Fri, 10 Feb 2017 22:43:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A606A285DE for ; Fri, 10 Feb 2017 22:43:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9AAF3285E7; Fri, 10 Feb 2017 22:43:48 +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 AE268285DE for ; Fri, 10 Feb 2017 22:43:47 +0000 (UTC) Received: (qmail 7855 invoked by uid 550); 10 Feb 2017 22:43: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 7822 invoked from network); 10 Feb 2017 22:43:44 -0000 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,143,1484035200"; d="scan'208";a="57410646" From: william.c.roberts@intel.com To: linux-kernel@vger.kernel.org, joe@perches.com, apw@canonical.com Cc: keescook@chromium.org, kernel-hardening@lists.openwall.com, William Roberts Date: Fri, 10 Feb 2017 14:43:28 -0800 Message-Id: <1486766608-8791-1-git-send-email-william.c.roberts@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [kernel-hardening] [PATCH v2] checkpatch: add warning on invalid %p extensions X-Virus-Scanned: ClamAV using ClamSMTP 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); + } + # check for lockdep_set_novalidate_class if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ || $line =~ /__lockdep_no_validate__\s*\)/ ) {