From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADB11C433E0 for ; Tue, 2 Feb 2021 21:37:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 503DA64F67 for ; Tue, 2 Feb 2021 21:37:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 503DA64F67 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E26876B0006; Tue, 2 Feb 2021 16:37:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DD6236B006C; Tue, 2 Feb 2021 16:37:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C53796B0070; Tue, 2 Feb 2021 16:37:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0240.hostedemail.com [216.40.44.240]) by kanga.kvack.org (Postfix) with ESMTP id B067F6B0006 for ; Tue, 2 Feb 2021 16:37:26 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 73B17180AD817 for ; Tue, 2 Feb 2021 21:37:26 +0000 (UTC) X-FDA: 77774639292.12.stew03_4800ad2275ce Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 4F71C1801E575 for ; Tue, 2 Feb 2021 21:36:54 +0000 (UTC) X-HE-Tag: stew03_4800ad2275ce X-Filterd-Recvd-Size: 4384 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Tue, 2 Feb 2021 21:36:53 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 878BF64E4A; Tue, 2 Feb 2021 21:36:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612301812; bh=CWKxJvbj5TQL0gN/TZC078q/51NUI9ShZk363Dx5J6o=; h=From:To:Subject:Date:From; b=bZ7xHGf/3iT3mRNlMienc3MxR0NCLq/VyfZ3wDYUFOukO2PC5u2zGZ3MZZc5eJK+C xGRafK06ss3dTTH7VuYX2aDd8GkrBrYVmOXsvIqWJU38pvGMsciMlYYYiKjySn/hNz 36Stmzat1sr6A2LtZSje64u/+dPNOQowb0Tp1sK7gNpnlmvZI7djl3x9EQn4MVOA4m 3+UXz28WnNPBbwf1ujeY7MBp4u0OndyFCFeFXAo7A5Ccak7ja+NiOIkZig+PF4Pk61 UG8KwRa4u6tSRnhF1XLyLfWyd165zr/tD74u/LyxU2q9pk9ysFmtV3v78Y/zJizLbh fhEeD2WPbwGBw== From: Timur Tabi To: Petr Mladek , Steven Rostedt , Sergey Senozhatsky , linux-kernel@vger.kernel.org, vbabka@suse.cz, linux-mm@kvack.org, willy@infradead.org, akpm@linux-foundation.org, torvalds@linux-foundation.org, roman.fietze@magna.com, keescook@chromium.org, john.ogness@linutronix.de, akinobu.mita@gmail.com Subject: [PATCH][RESEND] lib/vsprintf: make-printk-non-secret printks all addresses as unhashed Date: Tue, 2 Feb 2021 15:36:33 -0600 Message-Id: <20210202213633.755469-1-timur@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: If the make-printk-non-secret command-line parameter is set, then printk("%p") will print addresses as unhashed. This is useful for debugging purposes. A large warning message is displayed if this option is enabled, because unhashed addresses, while useful for debugging, exposes kernel addresses which can be a security risk. Signed-off-by: Timur Tabi --- lib/vsprintf.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 3b53c73580c5..b9f87084afb0 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -2090,6 +2090,30 @@ char *fwnode_string(char *buf, char *end, struct f= wnode_handle *fwnode, return widen_string(buf, buf - buf_start, end, spec); } =20 +/* Disable pointer hashing if requested */ +static bool debug_never_hash_pointers __ro_after_init; + +static int __init debug_never_hash_pointers_enable(char *str) +{ + debug_never_hash_pointers =3D true; + pr_warn("**********************************************************\n")= ; + pr_warn("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **\n")= ; + pr_warn("** **\n")= ; + pr_warn("** All pointers that are printed to the console will **\n")= ; + pr_warn("** be printed as unhashed. **\n")= ; + pr_warn("** **\n")= ; + pr_warn("** Kernel memory addresses are exposed, which may **\n")= ; + pr_warn("** compromise security on your system. **\n")= ; + pr_warn("** **\n")= ; + pr_warn("** If you see this message and you are not debugging **\n")= ; + pr_warn("** the kernel, report this immediately to your vendor! **\n")= ; + pr_warn("** **\n")= ; + pr_warn("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **\n")= ; + pr_warn("**********************************************************\n")= ; + return 0; +} +early_param("make-printk-non-secret", debug_never_hash_pointers_enable); + /* * Show a '%p' thing. A kernel extension is that the '%p' is followed * by an extra set of alphanumeric characters that are extended format @@ -2297,8 +2321,14 @@ char *pointer(const char *fmt, char *buf, char *en= d, void *ptr, } } =20 - /* default is to _not_ leak addresses, hash before printing */ - return ptr_to_id(buf, end, ptr, spec); + /* + * default is to _not_ leak addresses, so hash before printing, unless + * make-printk-non-secret is specified on the command line. + */ + if (unlikely(debug_never_hash_pointers)) + return pointer_string(buf, end, ptr, spec); + else + return ptr_to_id(buf, end, ptr, spec); } =20 /* --=20 2.25.1