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=-17.9 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,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable 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 91B3CC11F67 for ; Wed, 14 Jul 2021 07:55:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3C45461360 for ; Wed, 14 Jul 2021 07:55:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C45461360 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 58A0F6B0092; Wed, 14 Jul 2021 03:55:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 539A96B0095; Wed, 14 Jul 2021 03:55:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 38B7E6B0096; Wed, 14 Jul 2021 03:55:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0145.hostedemail.com [216.40.44.145]) by kanga.kvack.org (Postfix) with ESMTP id 0CDE96B0092 for ; Wed, 14 Jul 2021 03:55:47 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id EE24A18583350 for ; Wed, 14 Jul 2021 07:55:45 +0000 (UTC) X-FDA: 78360434250.38.7AF7829 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 90104F00020A for ; Wed, 14 Jul 2021 07:55:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626249345; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KKNSjjM802KvMrx63TD9dldCquu7NoZNgxi8GRD2Gak=; b=iZUYG61U9HVDEaZJNBsUI2QHZK5k85nSLoU0JSCJSzmdSQ+i7QhTBsLQk1/t62HwdPp6gP gos/NayR5pKaQUjE8oLstTM0uep5H97qdCoJImYXwn9U+Iz7apWzP3Njv5n0Nh5/1aR056 f9uu5KMcVD5+sFNP+kwrzZiqEdHsjX8= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-479-VKJFaQPxMaaiDiCqAgL4lA-1; Wed, 14 Jul 2021 03:55:43 -0400 X-MC-Unique: VKJFaQPxMaaiDiCqAgL4lA-1 Received: by mail-wm1-f72.google.com with SMTP id z127-20020a1c7e850000b02901e46e4d52c0so1100889wmc.6 for ; Wed, 14 Jul 2021 00:55: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:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=KKNSjjM802KvMrx63TD9dldCquu7NoZNgxi8GRD2Gak=; b=Wtq2LtNM7xwVgr9hE2a/nc/EXFva1iHIyeddNhBqf31MNWcVr37TZto5uWOLc4Iw7f 1uwtpYgrfMkO49nf+0u7oFefxESUgxXS4SSe1LWitvd9Q7wogYVhwTWcD5GNGQKfpqnM wJmJjuo4/KGrlkWNWJcflov0s2UUFg0/QmH0eZZcAC/UebpmCjzWIhiQOO4fWh/i2zfc mwM1drB1etOM9AG7LHfUxnftur9dOulNJ3IgrIvWaID4jE5i8z4g2iW66FTN4U/qobNF EmLyMXqQjbkb9H4JVmNE6tmC5qJQY146wtY4xzlXBcWiShxBQXXkV55ks/NwC/Vueojj jzeQ== X-Gm-Message-State: AOAM533aYTU0ijOH6n2+BN804zVYWl9UtCyXHJ/CrBptf3YER2mwfsTQ XKeymkVp6Rbat50ObWgFwsgopwb2siODjZJGUB//W7wUduV55mvervg5oB2iaHtGjcniYkn0Bwh bAmeDUSc/7oY= X-Received: by 2002:a05:600c:414b:: with SMTP id h11mr2572653wmm.95.1626249342743; Wed, 14 Jul 2021 00:55:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPC0tGdcUFvZnpstDfAQ01JyPVMlLbBqvaeL7rYzx6wNBKXZDSnZOOsdONWObmqxHxUedaVw== X-Received: by 2002:a05:600c:414b:: with SMTP id h11mr2572632wmm.95.1626249342518; Wed, 14 Jul 2021 00:55:42 -0700 (PDT) Received: from [192.168.3.132] (p5b0c60d5.dip0.t-ipconnect.de. [91.12.96.213]) by smtp.gmail.com with ESMTPSA id o7sm1785450wrv.72.2021.07.14.00.55.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Jul 2021 00:55:42 -0700 (PDT) Subject: Re: [PATCH v2] mm: page_alloc: Fix page_poison=1 / INIT_ON_ALLOC_DEFAULT_ON interaction To: Kees Cook , Andrew Morton Cc: Sergei Trofimovich , Alexander Potapenko , Thomas Gleixner , Vlastimil Babka , linux-mm@kvack.org, bowsingbetee@pm.me, Mikhail Morfikov , stable@vger.kernelo.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20210714031935.4094114-1-keescook@chromium.org> From: David Hildenbrand Organization: Red Hat Message-ID: <3c3868ea-7dc6-6b00-83a8-d8ed131ff6e6@redhat.com> Date: Wed, 14 Jul 2021 09:55:41 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210714031935.4094114-1-keescook@chromium.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 90104F00020A X-Stat-Signature: 514x597mj3knz9eaotcu5hcq6kjrhqnx Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iZUYG61U; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf11.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=david@redhat.com X-HE-Tag: 1626249345-167153 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 14.07.21 05:19, Kees Cook wrote: > From: Sergei Trofimovich > > To reproduce the failure we need the following system: > - kernel command: page_poison=1 init_on_free=0 init_on_alloc=0 > - kernel config: > * CONFIG_INIT_ON_ALLOC_DEFAULT_ON=y > * CONFIG_INIT_ON_FREE_DEFAULT_ON=y > * CONFIG_PAGE_POISONING=y > > 0000000085629bdd: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > 0000000022861832: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > 00000000c597f5b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > CPU: 11 PID: 15195 Comm: bash Kdump: loaded Tainted: G U O 5.13.1-gentoo-x86_64 #1 > Hardware name: System manufacturer System Product Name/PRIME Z370-A, BIOS 2801 01/13/2021 > Call Trace: > dump_stack+0x64/0x7c > __kernel_unpoison_pages.cold+0x48/0x84 > post_alloc_hook+0x60/0xa0 > get_page_from_freelist+0xdb8/0x1000 > __alloc_pages+0x163/0x2b0 > __get_free_pages+0xc/0x30 > pgd_alloc+0x2e/0x1a0 > ? dup_mm+0x37/0x4f0 > mm_init+0x185/0x270 > dup_mm+0x6b/0x4f0 > ? __lock_task_sighand+0x35/0x70 > copy_process+0x190d/0x1b10 > kernel_clone+0xba/0x3b0 > __do_sys_clone+0x8f/0xb0 > do_syscall_64+0x68/0x80 > ? do_syscall_64+0x11/0x80 > entry_SYSCALL_64_after_hwframe+0x44/0xae > > Before the 51cba1eb ("init_on_alloc: Optimize static branches") > init_on_alloc never enabled static branch by default. It could > only be enabed explicitly by init_mem_debugging_and_hardening(). > > But after the 51cba1eb static branch could already be enabled > by default. There was no code to ever disable it. That caused > page_poison=1 / init_on_free=1 conflict. > > This change extends init_mem_debugging_and_hardening() to also > disable static branch disabling. > > CC: Alexander Potapenko > CC: Thomas Gleixner > CC: Vlastimil Babka > CC: linux-mm@kvack.org > Reported-by: bowsingbetee@pm.me > Reported-by: Mikhail Morfikov > Fixes: 51cba1ebc60d ("init_on_alloc: Optimize static branches") > Cc: stable@vger.kernelo.org > Signed-off-by: Sergei Trofimovich > Link: https://lore.kernel.org/r/20210712215816.1512739-1-slyfox@gentoo.org > Co-developed-by: Kees Cook > Signed-off-by: Kees Cook > --- > mm/page_alloc.c | 29 ++++++++++++++++------------- > 1 file changed, 16 insertions(+), 13 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 3b97e17806be..1f19365bc158 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -840,21 +840,24 @@ void init_mem_debugging_and_hardening(void) > } > #endif > > - if (_init_on_alloc_enabled_early) { > - if (page_poisoning_requested) > - pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, " > - "will take precedence over init_on_alloc\n"); > - else > - static_branch_enable(&init_on_alloc); > - } > - if (_init_on_free_enabled_early) { > - if (page_poisoning_requested) > - pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, " > - "will take precedence over init_on_free\n"); > - else > - static_branch_enable(&init_on_free); > + if ((_init_on_alloc_enabled_early || _init_on_free_enabled_early) && > + page_poisoning_requested) { > + pr_info("mem auto-init: CONFIG_PAGE_POISONING is on, " > + "will take precedence over init_on_alloc and init_on_free\n"); > + _init_on_alloc_enabled_early = false; > + _init_on_free_enabled_early = false; > } > > + if (_init_on_alloc_enabled_early) > + static_branch_enable(&init_on_alloc); > + else > + static_branch_disable(&init_on_alloc); > + > + if (_init_on_free_enabled_early) > + static_branch_enable(&init_on_free); > + else > + static_branch_disable(&init_on_free); > + > #ifdef CONFIG_DEBUG_PAGEALLOC > if (!debug_pagealloc_enabled()) > return; > LGTM Reviewed-by: David Hildenbrand -- Thanks, David / dhildenb