From patchwork Sun Oct 1 00:06:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobin Harding X-Patchwork-Id: 9979609 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 6F74E60327 for ; Sun, 1 Oct 2017 00:09:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6213C27E63 for ; Sun, 1 Oct 2017 00:09:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5577428D00; Sun, 1 Oct 2017 00:09: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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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 7B4F727E63 for ; Sun, 1 Oct 2017 00:09:47 +0000 (UTC) Received: (qmail 8114 invoked by uid 550); 1 Oct 2017 00:09:34 -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 Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 1356 invoked from network); 1 Oct 2017 00:07:36 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tobin.cc; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=mDKzQg UWWwItyKaWolSMrZmA0jTNm4/C7PSo1xCtWuE=; b=CsP/4M8CinEUbg3JNuo4GG Azh6qe/1GRz2p+TWHfD7q2qHt3gSExiKfF09ro7CpWlCXASl1CZPxTwpczAkGkaE EnL+/oZcE/K1I8nguOnw5G6uY892rlFVcuK/JVc/HnDEOfwNOPV7lwTOCt0W0S9q JeASyi9yD6fBPLsKQFD9m4F3AFXwnWxo2NoM42FlVdtsDNJUjFPzTK46XLc776Ay oVcgAlRpVisE5kOR61yuCdIOTJSG6tVkxb112if/ITk02W1JfXx+0A3yIvbnSyui 4Y7AdXBJxzXauHNhwEdyqjS4EdUyen6KvY5MSFrAJl79fbG8q26RSkbwYymzlKDw == DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=mDKzQgUWWwItyKaWolSMrZmA0jTNm4/C7PSo1xCtW uE=; b=qAtmAsKMwGILV8vDDc2i6G7YIJgbVyaPugYOxxsyt4bdB87QbBPSFyw/l VJqKs1CaOcZh8uKO+F6f+Fe6m4gM4ZcxeZXbrdYjdtOkklpAe5YySNPsUjlsEqr1 KZkg6fNsqe6q+oOStNpS1DTTXQhuopAhm+HjQOQ/yDW0ISaKx6QF5xAQ1UGEn/rw hF/aamZN9ucPC75UC06JC5ST/1CED+XfSfQYXCPOczv0/suubD2KgUv+d7wdMfEO LjWUb21m9nvwv5RQvUhq7hFwVnBTqBcawiUz8HV65w3URNjW4EZrci14whOOh4dL iKW7B3Zd+p+qMEnHX+3616hyY30Lg== X-ME-Sender: X-Sasl-enc: maYqSjbGk/9TlzZb+HkIKTnbz4aqfbXcypcpIoua5ksL 1506816443 From: "Tobin C. Harding" To: Greg KH , Petr Mladek , Joe Perches , Ian Campbell , Sergey Senozhatsky Cc: "Tobin C. Harding" , kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org, Catalin Marinas , Will Deacon , Steven Rostedt , William Roberts , Chris Fries , Dave Weinstein Date: Sun, 1 Oct 2017 11:06:49 +1100 Message-Id: <1506816410-10230-6-git-send-email-me@tobin.cc> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506816410-10230-1-git-send-email-me@tobin.cc> References: <1506816410-10230-1-git-send-email-me@tobin.cc> Subject: [kernel-hardening] [RFC V2 5/6] lib: vsprintf: add "%paP", "%papP", and "%padP" specifiers X-Virus-Scanned: ClamAV using ClamSMTP Add %papP and %padP for address types that need to always be shown regardless of kptr restrictions. Add %paP is a synonym for %papP, this is inline with current implementation (%pa is a synonym for %pap). Signed-off-by: Tobin C. Harding Signed-off-by: Greg Kroah-Hartman --- Documentation/printk-formats.txt | 19 +++++++++++++++---- Documentation/sysctl/kernel.txt | 4 ++-- lib/vsprintf.c | 9 +++++++-- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt index 16c9abc..d247bc8 100644 --- a/Documentation/printk-formats.txt +++ b/Documentation/printk-formats.txt @@ -119,26 +119,37 @@ For printing struct resources. The ``R`` and ``r`` specifiers result in a printed resource with (``R``) or without (``r``) a decoded flags member. Passed by reference. +Physical addresses types +======================== + +:: + + %pa[P] 0x01234567 or 0x0123456789abcdef + +Synonymous with ``%pap[P]`` (for printing ``phys_addr_t``). See below. + Physical addresses types ``phys_addr_t`` ======================================== :: - %pa[p] 0x01234567 or 0x0123456789abcdef + %pap[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/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt index b6d45bc..f1d52eb 100644 --- a/Documentation/sysctl/kernel.txt +++ b/Documentation/sysctl/kernel.txt @@ -400,8 +400,8 @@ however kernel pointers printed using %pP will continue to be printed. When kptr_restrict is set to (4), kernel pointers printed with %p, %pK, %pa, and %p[rR] will be replaced with 0's regardless of -privileges. Kernel pointers printed using %pP will continue to be -printed. +privileges. Kernel pointers printed using %pP, %paP, %papP, %padP will +continue to be printed. ============================================================== diff --git a/lib/vsprintf.c b/lib/vsprintf.c index e009325..1a35a7f 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1395,21 +1395,26 @@ 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 through */ default: num = *(const phys_addr_t *)addr; size = sizeof(phys_addr_t); break; } - - if (kptr_restrict_cleanse_addresses()) + /* 'P' on the tail means don't restrict the pointer. */ + if (cleanse && (fmt[decleanse_idx] != 'P')) num = 0UL; return special_hex_number(buf, end, num, size);