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.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 1CBC8C433E0 for ; Tue, 2 Feb 2021 21:52:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A299264E4A for ; Tue, 2 Feb 2021 21:52:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A299264E4A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 043A36B0005; Tue, 2 Feb 2021 16:52:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F10706B0006; Tue, 2 Feb 2021 16:52:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD72C6B006C; Tue, 2 Feb 2021 16:52:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0045.hostedemail.com [216.40.44.45]) by kanga.kvack.org (Postfix) with ESMTP id BDEC66B0005 for ; Tue, 2 Feb 2021 16:52:20 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 4B4C0181AEF1D for ; Tue, 2 Feb 2021 21:52:20 +0000 (UTC) X-FDA: 77774676840.08.shame47_2e02646275ce Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 2EEB31819E772 for ; Tue, 2 Feb 2021 21:52:20 +0000 (UTC) X-HE-Tag: shame47_2e02646275ce X-Filterd-Recvd-Size: 6245 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Tue, 2 Feb 2021 21:52:19 +0000 (UTC) Received: by mail-pf1-f180.google.com with SMTP id q20so15269404pfu.8 for ; Tue, 02 Feb 2021 13:52:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=3AmuxU7ywET2oWhQ7TVzCDQ74ODSudJlgeUAo7patck=; b=FNR5fqRzqyhtvwocB+X4kQzgidtUnariiCXEH94qfOFqYFzWJqpEIMD1TPblypPxU/ E6tT4HpAeTcwc4M/2+xr5zw2QeD6xIYAkKGypOCrnmqTtKs++mVzLncKGNbyRQP7BQMl kh1bPcPDrgE8rEH5ZUQfirHEOYAbRWl16wP5k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=3AmuxU7ywET2oWhQ7TVzCDQ74ODSudJlgeUAo7patck=; b=S0fQrk/cOTxac4sccsjZvIjbZhrBhvXrakm/M0puyK3WbfNxRadwIsz73K77Kh0R41 mgC9yBbli+hG8JP9LEhnpfk0LDrNSGwtigkNG0wEzK3PIM1JUtta0lWapiU/VYl/5mGi 66/2y0xBkd9FL9spLw6rANYvDh4Drp5sHXfmVIm6qxiIpngTLqMjijsciX3tWT/ZBgS3 ncduO4WiR60chRPBBb7Ts3zLqUPSy5+uz9bKtEDiTCr3sk5gPWilt4NJ2gHHjKd1Ga7n PHt8A2eiCN3Hj0UED2S28OSb2B+p2Lcy4sxQHnJfgpC+kz0n+frO7L3HXewvAoo5olBl o79A== X-Gm-Message-State: AOAM5300hQGT7R5OqeDBlP8hVll4HYDQy5CSgLsDpRrVnfQAcqDakBEN 2BmHbOg4tAhXybOY0VIFQrRO6w== X-Google-Smtp-Source: ABdhPJzvZOYbm8y5fAyTH74CGl9GPQb22ScyZeyUe5QXZKjQkqKn7bw1QDYEqg0aZjux0FutxpcQ5g== X-Received: by 2002:a05:6a00:2ac:b029:1cb:7775:4b1e with SMTP id q12-20020a056a0002acb02901cb77754b1emr16911126pfs.25.1612302738554; Tue, 02 Feb 2021 13:52:18 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id z21sm17952437pgk.15.2021.02.02.13.52.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Feb 2021 13:52:17 -0800 (PST) Date: Tue, 2 Feb 2021 13:52:16 -0800 From: Kees Cook To: Timur Tabi Cc: Petr Mladek , Steven Rostedt , Sergey Senozhatsky , linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, akpm@linux-foundation.org, torvalds@linux-foundation.org, roman.fietze@magna.com, john.ogness@linutronix.de, akinobu.mita@gmail.com Subject: Re: [PATCH] lib/vsprintf: make-printk-non-secret printks all addresses as unhashed Message-ID: <202102021351.AEDE896AB3@keescook> References: <20210202201846.716915-1-timur@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210202201846.716915-1-timur@kernel.org> 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: On Tue, Feb 02, 2021 at 02:18:46PM -0600, Timur Tabi wrote: > 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. Linus has expressly said "no" to things like this in the past: https://lore.kernel.org/lkml/CA+55aFwieC1-nAs+NFq9RTwaR8ef9hWa4MjNBWL41F-8wM49eA@mail.gmail.com/ -Kees > > 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 fwnode_handle *fwnode, > return widen_string(buf, buf - buf_start, end, spec); > } > > +/* 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 = 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 *end, void *ptr, > } > } > > - /* 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); > } > > /* > -- > 2.25.1 > -- Kees Cook