Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp955148pxb; Wed, 3 Mar 2021 22:24:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJzeCd2mHaee61wvLyMzWC83kVYJTwSvb1XdpgBIohQea5bNH7xYC5pSNvsHJAnWcw+H5sUz X-Received: by 2002:a05:6402:2058:: with SMTP id bc24mr2662353edb.243.1614839071855; Wed, 03 Mar 2021 22:24:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614839071; cv=none; d=google.com; s=arc-20160816; b=e4EvPJAVCT5Yz3nmre/9VqwZDZUeWjDrb8LOuZq+dq/Nl42t11eBmLCVBApivdkhR9 gXAb8YyR+aEliGgzkmxB7YZe5uWuy64kyi8C2+172OBk8CKXvQE3mN/++Atic8RIB4Ej YmTh6gdSzAuzCufo4KyHrD9NRfOMnd16NfPhSkzB4cyAwghXHg6sjRrhBOlQNfrfIYkr i9nNVa/nkYPmAYGCDA/tewP+NmceOKlgtEhUMU4DB8qjbkKZt2oZF5YfoV2QiX7ENYE5 v+a/lMWL2xkk0P93bxT2MAh39RqlwVx0cH5UrU9rVTeCzo6ZENtD65NFgxgcSLzXhuX5 Bmvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=P8t0odw1Ol/O1AJt7AOmSfFmioJI8iKFTJw2MTf4RQk=; b=Gm/++dOtWtYjwl92f/eUV1ZigtzbwGIUzPcvPmMAGbf/sSkUIxZpLmyX+8c54Yvcwm FwOCYnhkmDn0QAgTummi2RH1VVRsfjZVKH7af9lXg0zA6VwCP2HCOHTy+brbv9psqVni z9IRd2K3EcEIUNh5Xg8wC16p2BZV3hs/caqqW390vD1ADj0QzihwwjPAsyyC58rjagh7 KwiPQdOilrr4KNvkhQcpHRuuasOX/05fA91c4PLDsSgaC3g8SOnBE6Kn0cMf1vWh1X3b MDZ0+y9X4e0zwDogVETTCrKNR0wyzPx3dpUViwrjt3IrzeD/mqc1kldL345GB5Og+j8C 8HKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="VZjeLG/V"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d2si8904568eds.543.2021.03.03.22.24.09; Wed, 03 Mar 2021 22:24:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="VZjeLG/V"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384092AbhCBOhO (ORCPT + 99 others); Tue, 2 Mar 2021 09:37:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350742AbhCBMrB (ORCPT ); Tue, 2 Mar 2021 07:47:01 -0500 Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70CB1C0611C1 for ; Tue, 2 Mar 2021 04:45:19 -0800 (PST) Received: by mail-ot1-x32d.google.com with SMTP id u3so1598859otg.13 for ; Tue, 02 Mar 2021 04:45:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=P8t0odw1Ol/O1AJt7AOmSfFmioJI8iKFTJw2MTf4RQk=; b=VZjeLG/VmDpZEhwakOm/C7M36eMfX6VH99FsCxtBHuYibjeDhhGg0cvUo2xWhk1xRl ITnbW5pDNNm56LVLMnz95TVyMZw+4ye6JeNNjAEsfZYQKO/W8vdbJgBitWYG/tebNzPB WYvO2W38Wf26BYXZCc/RMeN2U9HVeGdS/4gwMAuDHuzCcVugyFUQIZ0rscZ7URyxhAxm Q4umHI/3xPuOnfRQLxoQW3coC09JsYLpUsh1IYZWG6H1xOfJXlXLPOoDpMLoWmKsJ3Uh GQtmjfxr++rj1kZyGqmAlts79oqlRgX4Vky41WcNJR816vx2cPIp7u9fPZbLqi3gh9Jy RMPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=P8t0odw1Ol/O1AJt7AOmSfFmioJI8iKFTJw2MTf4RQk=; b=VYPT5ryeO8FJiVFM/jc0VVbRoPcjsy892rjz+5e17t20XI6q/PPmR4IgUhPBUA7+3q CXP90HahRLtCnq0jcE8UMNUV6dr0HlgrgSdjWizhDWzZsXJ2kP0+ZI0+EBGq/W3DCUif EQq+cHeLrOu9fICFVQBJo3r1Lrh474b9ydQ6anykNtjM8ylkjNXmhiwBORjTWhcwCY5R 1eLbWT4En+bqLBJLqjhC0CsIxIllGOoMBPNUObIux7ekgaF4GeqiNvHsQqAKliZYFVos nOKkvg5GjBy4i/cYgLh9yk7u+iwsc7S59+Hfz8nh0eRn+mfyq7EcYLK4LHBvfhthj0za DeTQ== X-Gm-Message-State: AOAM533DPRcBnIZiCX8vwxFncVwSGn67IyBXRp+Fd6unues3McF5lExi /N2oUlcURHkf7EBytUQTnWwnnTswlgEdm1+RFPctgA== X-Received: by 2002:a05:6830:1355:: with SMTP id r21mr10547387otq.17.1614689118519; Tue, 02 Mar 2021 04:45:18 -0800 (PST) MIME-Version: 1.0 References: <20210214161348.369023-1-timur@kernel.org> <20210214161348.369023-4-timur@kernel.org> In-Reply-To: From: Marco Elver Date: Tue, 2 Mar 2021 13:45:07 +0100 Message-ID: Subject: Re: [PATCH 3/3] [v4] lib/vsprintf: no_hash_pointers prints all addresses as unhashed To: Geert Uytterhoeven Cc: Timur Tabi , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Vlastimil Babka , Andy Shevchenko , Matthew Wilcox , Andrew Morton , Linus Torvalds , roman.fietze@magna.com, Kees Cook , John Ogness , Akinobu Mita , Alexander Potapenko , Andrey Konovalov , Rasmus Villemoes , Pavel Machek , Tetsuo Handa , Linux Kernel Mailing List , Linux MM Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2 Mar 2021 at 12:51, Geert Uytterhoeven wrote: > Hi Timur, > > On Sun, Feb 14, 2021 at 5:17 PM Timur Tabi wrote: > > If the no_hash_pointers command line parameter is set, then > > printk("%p") will print pointers as unhashed, which is useful for > > debugging purposes. This change applies to any function that uses > > vsprintf, such as print_hex_dump() and seq_buf_printf(). > > > > A large warning message is displayed if this option is enabled. > > Unhashed pointers expose kernel addresses, which can be a security > > risk. > > > > Also update test_printf to skip the hashed pointer tests if the > > command-line option is set. > > > > Signed-off-by: Timur Tabi > > Thanks for your patch, which is now commit 5ead723a20e0447b > ("lib/vsprintf: no_hash_pointers prints all addresses as unhashed") in > v5.12-rc1. > > > --- a/lib/vsprintf.c > > +++ b/lib/vsprintf.c > > @@ -2090,6 +2090,32 @@ 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 */ > > +bool no_hash_pointers __ro_after_init; > > +EXPORT_SYMBOL_GPL(no_hash_pointers); > > + > > +static int __init no_hash_pointers_enable(char *str) > > +{ > > + no_hash_pointers = true; > > + > > + pr_warn("**********************************************************\n"); > > + pr_warn("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **\n"); > > + pr_warn("** **\n"); > > + pr_warn("** This system shows unhashed kernel memory addresses **\n"); > > + pr_warn("** via the console, logs, and other interfaces. This **\n"); > > + pr_warn("** might reduce the security of 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 system **\n"); > > + pr_warn("** administrator! **\n"); > > + pr_warn("** **\n"); > > + pr_warn("** NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE **\n"); > > + pr_warn("**********************************************************\n"); > > + > > + return 0; > > +} > > +early_param("no_hash_pointers", no_hash_pointers_enable); > > While bloat-o-meter is not smart enough to notice the real size impact, > this does add more than 500 bytes of string data to the kernel. > Do we really need such a large message? > Perhaps the whole no_hash_pointers machinery should be protected by > "#ifdef CONFIG_DEBUG_KERNEL"? We recently stumbled across this, and it appears an increasing number of production kernels enable CONFIG_DEBUG_KERNEL [1], so it likely isn't the solution (we tried to use CONFIG_DEBUG_KERNEL in similar way, and it wasn't reliable). Having no_hash_pointers frees us of having to rely on CONFIG_DEBUG_KERNEL. (Perhaps somebody else will comment, but I believe there were strong objections to making the pointer hashing dependent on more Kconfig options.) [1] https://lkml.kernel.org/r/20210223082043.1972742-1-elver@google.com Would placing the strings into an __initconst array help? Thanks, -- Marco