From patchwork Fri Jun 28 09:31:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 11021781 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B76F876 for ; Fri, 28 Jun 2019 09:31:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9D5828500 for ; Fri, 28 Jun 2019 09:31:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E44A2880D; Fri, 28 Jun 2019 09:31:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0AA828500 for ; Fri, 28 Jun 2019 09:31:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA6AD6B0007; Fri, 28 Jun 2019 05:31:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D0A868E0003; Fri, 28 Jun 2019 05:31:43 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5B6A8E0002; Fri, 28 Jun 2019 05:31:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f70.google.com (mail-yw1-f70.google.com [209.85.161.70]) by kanga.kvack.org (Postfix) with ESMTP id 940E26B0007 for ; Fri, 28 Jun 2019 05:31:43 -0400 (EDT) Received: by mail-yw1-f70.google.com with SMTP id 75so7558692ywb.3 for ; Fri, 28 Jun 2019 02:31:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=OTM/dBWKP5pXAZwQDJU1YbjuxxUPU+6Vr1IAcbjuDVo=; b=D7adkQMDIOWoGFpSf13amIuN916SWPzgrsw936N5rq96KBxXRLJt22IXAHrm220cP7 yjxM9DO2jmEk/CwrbCixe0Ol8PlrlWIGJN7sUX5BM204S/UxBdgmoA6049ChPF6RC1IF TGpuE9t+/0PeS1kWBW0yi3wRXqp1B57r/yFoS6EB/KhaaF3TUFmYyu20g6maGqU6mD46 4cSrVUwKpx7Vc8O0pfBdVjuhK8T24N2xqt6eHdvjhHymwDdqWsGhs70NrDXTsF+7/8du k6/J5pWNe3DConsZcFsagz5NGlW7iOQvKsPtDZTDYSV5FfjhPwpdKV50o9RJCAOwNEZv IOKA== X-Gm-Message-State: APjAAAU+m8g+bTpFWYRXHdjQC/2UT8VRiaTVjro2vk52d0q5vwjx/Oyw UXI+52l1W+q3GWX7pjtPAkQAvqwFUYC9JrwOnPj/Zkuoe9H4qDTyTNP803SlZ8jN3XzkwjF/+8A C2YWjL4z1PAwodVkCwB1yeXhxeMxHJGu0SSVNPF0uVVNTlBCKvsnZZhpLFMqNJGhVcA== X-Received: by 2002:a25:2e0b:: with SMTP id u11mr5759650ybu.69.1561714303341; Fri, 28 Jun 2019 02:31:43 -0700 (PDT) X-Received: by 2002:a25:2e0b:: with SMTP id u11mr5759618ybu.69.1561714302604; Fri, 28 Jun 2019 02:31:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561714302; cv=none; d=google.com; s=arc-20160816; b=g66W3AJqSxKDNh7Ro1YIUqPU0QDltHASmpBmkGo8UgVLCYYGVyY3Dpe5dVggHaXh/2 N0h3as0YRQzVcIVUvvZpCsAHlYRdXVzMPabUJphLHXxy0JJU3CEsAnfxw7TNmMdc7g7x fZ4wd8Hgm2yUiNq8E38ypqIfsz+ur+mch4RHkRRM1k9MCR46whc6l8kDmujz3lR7cELg /DmM1nbEiCsZxw9vsiqcmnXvakad6mFwNMKhl8Pt5FpYyWAnS80FmrXoXLf1qp/dzDlt dN7Dnz0RalVQ43aW3oOuZX2LU2fbEpHfKPgaK1aJsh+cYbkZZcrpV4oQIZzi8pUtThYw vo2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:dkim-signature; bh=OTM/dBWKP5pXAZwQDJU1YbjuxxUPU+6Vr1IAcbjuDVo=; b=kebMqPbpZlExzZm9ioWVzAanAeOMUy0e7UMM6zHoAYUWCW7Gn69kQTRqKNJLuODA1f yG/aQx7QFcq7soAdkieBy8fSjX4B/0ULUM9f7yIuGd1BrGXfjo6yi3OQlf8vksYt+QL/ w4sEDFZVH/CjauWkFlnOpfzslNZ0AnNXkRLWARF1+qIXrHbH732iz8MOUcAtsYFARVmh y4SpllhAw7gGmb6skyrGHakIciWxIo7q4b/qlAHpk5KBeSBbZN4fkBTKxGIRR3fj6V7M 6Z19lCEug69VbYO+usNYDDa93LwRTaiWjnY/tFrSL4Z+Ambs34BC6qpI17JVq/O4PG7o gRlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=REUUVS8v; spf=pass (google.com: domain of 3ft4vxqykcielqnijwlttlqj.htrqnsz2-rrp0fhp.twl@flex--glider.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3ft4VXQYKCIElqnijwlttlqj.htrqnsz2-rrp0fhp.twl@flex--glider.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f73.google.com (mail-sor-f73.google.com. [209.85.220.73]) by mx.google.com with SMTPS id d81sor786660ywd.29.2019.06.28.02.31.42 for (Google Transport Security); Fri, 28 Jun 2019 02:31:42 -0700 (PDT) Received-SPF: pass (google.com: domain of 3ft4vxqykcielqnijwlttlqj.htrqnsz2-rrp0fhp.twl@flex--glider.bounces.google.com designates 209.85.220.73 as permitted sender) client-ip=209.85.220.73; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=REUUVS8v; spf=pass (google.com: domain of 3ft4vxqykcielqnijwlttlqj.htrqnsz2-rrp0fhp.twl@flex--glider.bounces.google.com designates 209.85.220.73 as permitted sender) smtp.mailfrom=3ft4VXQYKCIElqnijwlttlqj.htrqnsz2-rrp0fhp.twl@flex--glider.bounces.google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=OTM/dBWKP5pXAZwQDJU1YbjuxxUPU+6Vr1IAcbjuDVo=; b=REUUVS8vBg2H/z0it6JTEUWGi30pyMFfd+dKyOdmlmrXJN/54g0uufubMFDdrjvKUa F9o3+Wl5P+yqkzUwpw6n5n1lRb6ky1dG0xGQJSeHl69UacCM/ZwGgiKRY+c7SZ0lXxVR r6e/3EnVwWqPAP8HsP7CAJ7fKxDsW7QfAVRge2yBewN1zUFdRKkZgYVTfUEXFKHbmEJc 1hSW+MYzLNa4/oJRkmtPl+30i1H7Rv5Ew3Nyh9J23uj5uiYi6ijS1kvynOgLS1YIeBaW mFXfuvVBCdyR4XyJRBDleQRNiCFwtYwyvUJiwsWtBGifRcag5OM5wSKHgqCLWMjKRRl0 j9Yw== X-Google-Smtp-Source: APXvYqxr82FEZUsZl41QBUdwTE83MyFZYWHcMSxK71KVoFLH9afR/pRchCaM1jtaNI2n7dM1odx28qfXL8c= X-Received: by 2002:a81:4c3:: with SMTP id 186mr5372311ywe.462.1561714302128; Fri, 28 Jun 2019 02:31:42 -0700 (PDT) Date: Fri, 28 Jun 2019 11:31:31 +0200 In-Reply-To: <20190628093131.199499-1-glider@google.com> Message-Id: <20190628093131.199499-3-glider@google.com> Mime-Version: 1.0 References: <20190628093131.199499-1-glider@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [PATCH v10 2/2] mm: init: report memory auto-initialization features at boot time From: Alexander Potapenko To: Andrew Morton , Christoph Lameter Cc: Alexander Potapenko , Kees Cook , Dmitry Vyukov , James Morris , Jann Horn , Kostya Serebryany , Laura Abbott , Mark Rutland , Masahiro Yamada , Matthew Wilcox , Nick Desaulniers , Randy Dunlap , Sandeep Patil , "Serge E. Hallyn" , Souptick Joarder , Marco Elver , Kaiwan N Billimoria , kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-security-module@vger.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: X-Virus-Scanned: ClamAV using ClamSMTP Print the currently enabled stack and heap initialization modes. Stack initialization is enabled by a config flag, while heap initialization is configured at boot time with defaults being set in the config. It's more convenient for the user to have all information about these hardening measures in one place at boot, so the user can reason about the expected behavior of the running system. The possible options for stack are: - "all" for CONFIG_INIT_STACK_ALL; - "byref_all" for CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL; - "byref" for CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF; - "__user" for CONFIG_GCC_PLUGIN_STRUCTLEAK_USER; - "off" otherwise. Depending on the values of init_on_alloc and init_on_free boottime options we also report "heap alloc" and "heap free" as "on"/"off". In the init_on_free mode initializing pages at boot time may take a while, so print a notice about that as well. This depends on how much memory is installed, the memory bandwidth, etc. On a relatively modern x86 system, it takes about 0.75s/GB to wipe all memory: [ 0.418722] mem auto-init: stack:byref_all, heap alloc:off, heap free:on [ 0.419765] mem auto-init: clearing system memory may take some time... [ 12.376605] Memory: 16408564K/16776672K available (14339K kernel code, 1397K rwdata, 3756K rodata, 1636K init, 11460K bss, 368108K reserved, 0K cma-reserved) Signed-off-by: Alexander Potapenko Suggested-by: Kees Cook Acked-by: Kees Cook To: Andrew Morton To: Christoph Lameter Cc: Dmitry Vyukov Cc: James Morris Cc: Jann Horn Cc: Kostya Serebryany Cc: Laura Abbott Cc: Mark Rutland Cc: Masahiro Yamada Cc: Matthew Wilcox Cc: Nick Desaulniers Cc: Randy Dunlap Cc: Sandeep Patil Cc: "Serge E. Hallyn" Cc: Souptick Joarder Cc: Marco Elver Cc: Kaiwan N Billimoria Cc: kernel-hardening@lists.openwall.com Cc: linux-mm@kvack.org Cc: linux-security-module@vger.kernel.org Signed-off-by: Andrew Morton --- v6: - update patch description, fixed message about clearing memory v7: - rebase the patch, add the Acked-by: tag; - more description updates as suggested by Kees; - make report_meminit() static. v8: - added the Signed-off-by: tag --- init/main.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/init/main.c b/init/main.c index 66a196c5e4c3..ff5803b0841c 100644 --- a/init/main.c +++ b/init/main.c @@ -520,6 +520,29 @@ static inline void initcall_debug_enable(void) } #endif +/* Report memory auto-initialization states for this boot. */ +static void __init report_meminit(void) +{ + const char *stack; + + if (IS_ENABLED(CONFIG_INIT_STACK_ALL)) + stack = "all"; + else if (IS_ENABLED(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF_ALL)) + stack = "byref_all"; + else if (IS_ENABLED(CONFIG_GCC_PLUGIN_STRUCTLEAK_BYREF)) + stack = "byref"; + else if (IS_ENABLED(CONFIG_GCC_PLUGIN_STRUCTLEAK_USER)) + stack = "__user"; + else + stack = "off"; + + pr_info("mem auto-init: stack:%s, heap alloc:%s, heap free:%s\n", + stack, want_init_on_alloc(GFP_KERNEL) ? "on" : "off", + want_init_on_free() ? "on" : "off"); + if (want_init_on_free()) + pr_info("mem auto-init: clearing system memory may take some time...\n"); +} + /* * Set up kernel memory allocators */ @@ -530,6 +553,7 @@ static void __init mm_init(void) * bigger than MAX_ORDER unless SPARSEMEM. */ page_ext_init_flatmem(); + report_meminit(); mem_init(); kmem_cache_init(); pgtable_init();