From patchwork Wed Nov 29 23:38:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tobin C. Harding" X-Patchwork-Id: 842810 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=tobin.cc header.i=@tobin.cc header.b="RTadynS6"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="NK27xd13"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynH7Z6ZZ8z9s84 for ; Thu, 30 Nov 2017 10:39:38 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753275AbdK2XjD (ORCPT ); Wed, 29 Nov 2017 18:39:03 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:53663 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752983AbdK2Xi6 (ORCPT ); Wed, 29 Nov 2017 18:38:58 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 2BDDC20CA7; Wed, 29 Nov 2017 18:38:57 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Wed, 29 Nov 2017 18:38:57 -0500 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; s=fm1; bh=ejvtU4+wX9zV7uSdk S95QGwdFtdzhNLb7A6YBpHNEmk=; b=RTadynS6d+4fGfUTn4eZ0Xqb/X06Z0jFo ToPQo27FdIuk0v6O4XMOalbmYZ0ZhP8nMxRi7UIg1yJ7OqEopCmTh9xjgN8TS6ji KqVwAmir4sGUn1CZOKdLMoCAOYzYMiZ6WbU5bAcZRkeZ2Eh3t9PVAhPLipj7hj2m vx4F4z5w9mb5q+lSjSvLbhXXRbqczCG+y2EkTcvES20NFJmcy17PrQCXVihjJFDk 4aWYjPsFjN6jmj7yHJh+6E2eGygCBktP3xqsMgajaGlywlf/g6An/EJ131ISwyu+ RWZtbpSUARTBmRd30SH7RXds0kRJzDz7lA3iz6XTAYRZ2DN1vp72g== 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; s= fm1; bh=ejvtU4+wX9zV7uSdkS95QGwdFtdzhNLb7A6YBpHNEmk=; b=NK27xd13 B4HdzEQIk4pxlSwYOK9g2RQ5DmuHVxeOnwwfb4QLLlh3icnYByPkevu7hN7Pk/DU 7mney16yiKs1+Tcu8mDlQLvQShJgo3jxv4v9d1zLDqZX/J5jdmotli3r02TK/AdE c7s5j05cISP7Ihn7dNhw+IwMYObYF/vsmdMg4q210lT+K/0pI9Bgmdc7WfiyHd+P OM7HTvaYwCfcwiiSfRykrqAEj8cM0AHeAnHa8eolez4EH4DgvfJUf9R0n3KIQ9QA BNf/ue5h4BbRmU/75P8kaRvCgh6ja28q4Ou07nsjOcUxzYzj0qaG+r4/OXIA2pET 9RPZBzSscULGKw== X-ME-Sender: Received: from localhost (202-159-174-127.dyn.iinet.net.au [202.159.174.127]) by mail.messagingengine.com (Postfix) with ESMTPA id 29C97243F9; Wed, 29 Nov 2017 18:38:56 -0500 (EST) From: "Tobin C. Harding" To: Linus Torvalds Cc: "Tobin C. Harding" , David Laight , Kees Cook , "Jason A. Donenfeld" , Theodore Ts'o , Paolo Bonzini , Tycho Andersen , "Roberts, William C" , Tejun Heo , Jordan Glover , Greg KH , Petr Mladek , Joe Perches , Ian Campbell , Sergey Senozhatsky , Catalin Marinas , Will Deacon , Steven Rostedt , Chris Fries , Dave Weinstein , Daniel Micay , Djalal Harouni , =?utf-8?q?Radim_Krcm=C3=A1r?= , David Miller , Stephen Rothwell , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Andrew Morton , kernel-hardening@lists.openwall.com, Linux Kernel Mailing List , Network Development Subject: [PATCH 2/2] printk: add specifier %pz, for zeroed address Date: Thu, 30 Nov 2017 10:38:38 +1100 Message-Id: <1511998718-4158-3-git-send-email-me@tobin.cc> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511998718-4158-1-git-send-email-me@tobin.cc> References: <1511998718-4158-1-git-send-email-me@tobin.cc> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Currently %pK [at times] zeros addresses. It would be nice to remove %pK entirely. Printing zero addresses is useful if we want to sanitize an address but there may be userland tools that currently rely on the address format (i.e the correct width). Add printk specifier %pz. Signed-off-by: Tobin C. Harding --- Documentation/printk-formats.txt | 11 +++++++++++ lib/vsprintf.c | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/Documentation/printk-formats.txt b/Documentation/printk-formats.txt index aa0a776c817a..f88b06485378 100644 --- a/Documentation/printk-formats.txt +++ b/Documentation/printk-formats.txt @@ -122,6 +122,17 @@ uniquely grep'able. If, in the future, we need to modify the way the Kernel handles printing pointers it will be nice to be able to find the call sites. +Zeroed Addresses +================ + +:: + + %pz 00000000 or 0000000000000000 + +For printing zeroed addresses. This is useful if you are want to sanitize +an address but there may be userland tools that depend on the correct width +of the address for parsing. + Struct Resources ================ diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 81e9ce8f52f9..ebf911618858 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1727,6 +1727,19 @@ static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec) return number(buf, end, hashval, spec); } +static noinline_for_stack +char *zero_string(char *buf, char *end, struct printf_spec spec) +{ + spec.base = 16; + spec.flags |= SMALL; + if (spec.field_width == -1) { + spec.field_width = 2 * sizeof(void *); + spec.flags |= ZEROPAD; + } + + return number(buf, end, 0, spec); +} + /* * Show a '%p' thing. A kernel extension is that the '%p' is followed * by an extra set of alphanumeric characters that are extended format @@ -1833,6 +1846,9 @@ static char *ptr_to_id(char *buf, char *end, void *ptr, struct printf_spec spec) * C full compatible string * * - 'x' For printing the address. Equivalent to "%lx". + * - 'z' For printing zeroed addresses. This is useful if you are want to + * sanitize an address but there may be userland tools that depend on the + * correct width of the address for parsing. * * ** Please update also Documentation/printk-formats.txt when making changes ** * @@ -1960,6 +1976,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, } case 'x': return pointer_string(buf, end, ptr, spec); + case 'z': + return zero_string(buf, end, spec); } /* default is to _not_ leak addresses, hash before printing */