Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1703156pxb; Mon, 8 Mar 2021 04:27:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYAc9QTAYS3OikLVc+YYgJwqpm2YQGNJdzzZYcnSH4xafNFNnOMfGbqbdKBfPMQiINy16N X-Received: by 2002:a17:906:600f:: with SMTP id o15mr15119934ejj.76.1615206453332; Mon, 08 Mar 2021 04:27:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615206453; cv=none; d=google.com; s=arc-20160816; b=bQWbmWP8jfZ0Uc3k9NY7dDAsOfNYJmzhN0ZU5ukskbVo3bwuluP31soR8YZE9KfdIK ZOLxK3mFIpzBe9JAonxUhD75j4pDknY9Sari3LsG+HsZ1/90Gos7lVqJzXKGYwfjMnhR 906Ac4bWwiDfumA2TJrP6nlt73fGpDmIZ4I0OcQIHfg9wjy9XfTBN0cgCC2is+kaRaBo RiaydOBvJMxKMY7TxsaOnlxxYJoNe7ib6Uszxa58RsvS7X7X7RLOfkEbcQeixg8YXw0S fweTLVIO//wU42aVKn65gXTqfEmNYXwjU5i+TjWf5mliDSG2jNBpUABAhlGO25stlDKn BTnQ== 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; bh=tLC/tgI64EEsWSU2GUD0WY3ILds+TQ6RTHmx4L/R/8s=; b=gHhYMDXjr8WmSMpz0Wt0Yaws/rwvqkjv74r76RAuAkVzGMgfY1MERxakAnjUkY5UBN 6Zxlxpc1eauMVIMJwMYt/+kazg18Yn+rMWoN22vj7s7rPbZ0bjnGg9PrduJ+e9RPLUdL 3z2HOZhCI50vSwbycdPeiMQ4MJr9fWOKD/fNFK6qXeRxge0FqSaV0n0YB+NzzYHD/D6l GSLW/2aTKJevVwxHAyMpv/LcIOY/1tiWg1RhoC3s41CA6WGEuV6uLNgiJZ95Tn5QWinr g79c9yRJ+XaY5xKR/aO5JjgGFIBnO/HllFIP1FUhMEVZCe9QJTV2w09VyiltomTNef4u CRaw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si7033218edb.511.2021.03.08.04.27.11; Mon, 08 Mar 2021 04:27:33 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229627AbhCHMXA (ORCPT + 99 others); Mon, 8 Mar 2021 07:23:00 -0500 Received: from mail-vs1-f43.google.com ([209.85.217.43]:38791 "EHLO mail-vs1-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232026AbhCHMWw (ORCPT ); Mon, 8 Mar 2021 07:22:52 -0500 Received: by mail-vs1-f43.google.com with SMTP id e21so2709358vsh.5 for ; Mon, 08 Mar 2021 04:22:52 -0800 (PST) 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=tLC/tgI64EEsWSU2GUD0WY3ILds+TQ6RTHmx4L/R/8s=; b=NDPtbZvUqJ+0kZcEGgK1MJUiqw/emjlUOXHFmBMslVZaOygmJ+7vdkaokChd/+ADZZ ad7q8v8L1wNQO8NP96Ble7tZy2oCXsU8AYdsJl/FNuvWfX9y757+WW90ueID5OGEqfrR x45BKgAL0dGAQhqJ2eIedTO7VJVXeCDaYTlvGI//cxlHYElqUmQEcAv1MBa8YYQ5+2wH aPkI8C24bSLH2tEh5iBeDrLhb/43p4wHXk2vr947ueJMGlrpQplAvm1Eldsfi6IKV7BB n1YJLlh84cGe1818RhZ6TbKzc0xVM6gEMtcJ8E/MbwQEAJJ6jRBkkSYqPr1WuNUoxMES qJbw== X-Gm-Message-State: AOAM531lllFnLNJ4rpAj0wHsKL9nP/8ZQpUtr12nqLRkvBRkPkY25z5Q cPP9eJzWULQnnWeMbxxIf6zO0Q5nC7fxqOM6SF8= X-Received: by 2002:a67:fe90:: with SMTP id b16mr13045613vsr.40.1615206172118; Mon, 08 Mar 2021 04:22:52 -0800 (PST) MIME-Version: 1.0 References: <20210305194206.3165917-1-elver@google.com> <20210305194206.3165917-2-elver@google.com> In-Reply-To: From: Geert Uytterhoeven Date: Mon, 8 Mar 2021 13:22:40 +0100 Message-ID: Subject: Re: [PATCH 2/2] lib/vsprintf: reduce space taken by no_hash_pointers warning To: Petr Mladek Cc: Marco Elver , Linux Kernel Mailing List , Vlastimil Babka , Timur Tabi , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Petr, On Mon, Mar 8, 2021 at 11:16 AM Petr Mladek wrote: > On Fri 2021-03-05 20:42:06, Marco Elver wrote: > > Move the no_hash_pointers warning string into __initconst section, so > > that it is discarded after init. Remove common start/end characters. > > Also remove repeated lines from the array, since the compiler can't > > remove duplicate strings for us since the array must appear in > > __initconst as defined. > > > > Note, a similar message appears in kernel/trace/trace.c, but compiling > > the feature is guarded by CONFIG_TRACING. It is not immediately obvious > > if a space-concious kernel would prefer CONFIG_TRACING=n. Therefore, it > > makes sense to keep the message for no_hash_pointers as __initconst, and > > not move the NOTICE-printing to a common function. > > > > Link: https://lkml.kernel.org/r/CAMuHMdULKZCJevVJcp7TxzLdWLjsQPhE8hqxhnztNi9bjT_cEw@mail.gmail.com > > Reported-by: Geert Uytterhoeven > > Signed-off-by: Marco Elver > > --- > > lib/vsprintf.c | 30 +++++++++++++++++------------- > > 1 file changed, 17 insertions(+), 13 deletions(-) > > > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > > index 4a14889ccb35..1095689c9c97 100644 > > --- a/lib/vsprintf.c > > +++ b/lib/vsprintf.c > > @@ -2094,26 +2094,30 @@ char *fwnode_string(char *buf, char *end, struct fwnode_handle *fwnode, > > bool no_hash_pointers __ro_after_init; > > EXPORT_SYMBOL_GPL(no_hash_pointers); > > > > +static const char no_hash_pointers_warning[8][55] __initconst = { > > + "******************************************************", > > + " NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE ", > > + " This system shows unhashed kernel memory addresses ", > > + " via the console, logs, and other interfaces. This ", > > + " might reduce the security of your system. ", > > + " If you see this message and you are not debugging ", > > + " the kernel, report this immediately to your system ", > > + " administrator! ", > > +}; > > + > > static int __init no_hash_pointers_enable(char *str) > > { > > + /* Indices into no_hash_pointers_warning; -1 is an empty line. */ > > + const int lines[] = { 0, 1, -1, 2, 3, 4, -1, 5, 6, 7, -1, 1, 0 }; > > + int i; > > + > > if (no_hash_pointers) > > return 0; > > > > 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"); > > + for (i = 0; i < ARRAY_SIZE(lines); i++) > > + pr_warn("**%54s**\n", i == -1 ? "" : no_hash_pointers_warning[lines[i]]); > > Is this worth it, please? Could anyone provide some numbers how Yeah, the code indeed starts to look a bit cumbersome... > the kernel size increases between releases? I'd say 20 KiB per release, on average. > The number of code lines is basically just growing. The same is true > for the amount of printed messages. Yeah, we keep on adding more messages. But do we really need to print a message of 13 lines? If you consider this critical for security, perhaps it should use pr_crit(), or pr_alert()? But please don't print more than a single line. Perhaps it should print a URL to a message instead, like the "software license" option in Android systems and apps? > This patch is saving some lines of text that might be effectively > compressed. But it adds some code and array with indexes. Does it > make any significant imrovement in the compressed kernel image? > > Geert was primary concerned about the runtime memory consuption. > It will be solved by the __initconst. The rest affects only > the size of the compressed image on disk. I'm actually concerned about both. Platforms (and boot loaders) may have limitations for kernel image size, too. Static memory consumption is also more easily measured, so I tend to run bloat-o-meter, and dive into anything that adds more than 1 KiB. And yes, this message is a low-hanging fruit... Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds