From patchwork Sat May 6 04:07:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 9714543 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 3F7CE60234 for ; Sat, 6 May 2017 04:08:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3415C281B7 for ; Sat, 6 May 2017 04:08:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 28A5728678; Sat, 6 May 2017 04:08:11 +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 58814281B7 for ; Sat, 6 May 2017 04:08:10 +0000 (UTC) Received: (qmail 27888 invoked by uid 550); 6 May 2017 04:08:08 -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 27854 invoked from network); 6 May 2017 04:08:06 -0000 Date: Fri, 5 May 2017 21:07:47 -0700 From: Greg KH To: kernel-hardening@lists.openwall.com, Petr Mladek , Sergey Senozhatsky Cc: linux-kernel@vger.kernel.org, Catalin Marinas , Will Deacon , Steven Rostedt , William Roberts , Chris Fries , Dave Weinstein Message-ID: <20170506040747.GF32707@kroah.com> References: <20170506040641.GA32707@kroah.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170506040641.GA32707@kroah.com> User-Agent: Mutt/1.8.2 (2017-04-18) Subject: [kernel-hardening] [RFC 5/6] lib: vsprintf: Add "%paP", "%padP" options X-Virus-Scanned: ClamAV using ClamSMTP From: Chris Fries Add %paP and %padP for physical address that need to always be shown regardless of kptr restrictions. Cc: William Roberts Cc: Dave Weinstein Signed-off-by: Chris Fries Signed-off-by: Greg Kroah-Hartman --- Documentation/printk-formats.txt | 10 ++++++---- lib/vsprintf.c | 12 +++++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt index 8994c65aa3b0..7ee51269096f 100644 --- a/Documentation/printk-formats.txt +++ b/Documentation/printk-formats.txt @@ -82,18 +82,20 @@ Struct Resources: Physical addresses types phys_addr_t: - %pa[p] 0x01234567 or 0x0123456789abcdef + %pa[p][P] 0x01234567 or 0x0123456789abcdef For printing a phys_addr_t type (and its derivatives, such as resource_size_t) which can vary based on build options, regardless of - the width of the CPU data path. Passed by reference. + the width of the CPU data path. Passed by reference. Use the trailing + 'P' if it needs to be always shown. DMA addresses types dma_addr_t: - %pad 0x01234567 or 0x0123456789abcdef + %pad[P] 0x01234567 or 0x0123456789abcdef For printing a dma_addr_t type which can vary based on build options, - regardless of the width of the CPU data path. Passed by reference. + regardless of the width of the CPU data path. Passed by reference. Use + the trailing 'P' if it needs to be always shown. Raw buffer as an escaped string: diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 404d477d4bd2..37f9d615e622 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1394,23 +1394,29 @@ static noinline_for_stack char *address_val(char *buf, char *end, const void *addr, const char *fmt) { unsigned long long num; + int cleanse = kptr_restrict_cleanse_addresses(); + int decleanse_idx = 1; int size; switch (fmt[1]) { case 'd': num = *(const dma_addr_t *)addr; size = sizeof(dma_addr_t); + decleanse_idx = 2; break; case 'p': + decleanse_idx = 2; + /* fall thru */ default: num = *(const phys_addr_t *)addr; size = sizeof(phys_addr_t); break; } - return special_hex_number(buf, end, - kptr_restrict_cleanse_addresses() ? 0UL : num, - size); + /* 'P' on the tail means don't restrict the pointer. */ + cleanse = cleanse && (fmt[decleanse_idx] != 'P'); + + return special_hex_number(buf, end, cleanse ? 0UL : num, size); } static noinline_for_stack