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=-18.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL 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 BA865C433E0 for ; Fri, 19 Feb 2021 00:10:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 442E464EC7 for ; Fri, 19 Feb 2021 00:10:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 442E464EC7 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BEE646B0005; Thu, 18 Feb 2021 19:10:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B9CA76B006C; Thu, 18 Feb 2021 19:10:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8B5E6B006E; Thu, 18 Feb 2021 19:10:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0239.hostedemail.com [216.40.44.239]) by kanga.kvack.org (Postfix) with ESMTP id 881746B0005 for ; Thu, 18 Feb 2021 19:10:02 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 39A8B1F06 for ; Fri, 19 Feb 2021 00:10:02 +0000 (UTC) X-FDA: 77833084644.16.D5B2352 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf11.hostedemail.com (Postfix) with ESMTP id A1A2A2000DA5 for ; Fri, 19 Feb 2021 00:09:55 +0000 (UTC) Received: by mail-pf1-f180.google.com with SMTP id w18so2617964pfu.9 for ; Thu, 18 Feb 2021 16:10:01 -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=7mNeKDWUCPWRjksxHsm0Sl4Ar+FMbcH9wO3bpUG9+dU=; b=BC6tuzv20jq0nQ0piEbqyLgRX7rhaCxUkZrHw37Vmfz/7XgquLlxAHC/1EohAiv3Rb fcb9rMYbpw48pogIU8JjxT55d1pYGBnmAnG7gQxNn/iMBEPtPCmTje74BGwi1zKsRzg9 KpIkMLTiypUKUGiP+kFemDmsIhQPV/cv1vkfKC5otpQ9WG646Y6RnI7vok74axJFpJuD CY4yJXp9tVBiUZHmuTBt9v6tHNhKTqSSm1KXcDWbUSRtkvSv4ygeYzD4jaaf4NorfdD7 jowW5zj0AzpS1zbka09mozIdiyO7yP1MUfgSIutoXIUCSEqrkXrI2WzWRAV+F41StTg+ mL8A== 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=7mNeKDWUCPWRjksxHsm0Sl4Ar+FMbcH9wO3bpUG9+dU=; b=qF7x3yCgnhlxAx48GT4xmN4Es/B+mv7w48u5kYIHNCT58cOVOGarbYgwuyVLOh6MXP wVxrmfPRnGaZ6kY27e9y1qRNJ4VHrQWyMmcoAnd2uc80egJQEHTW3jN9h5fg7aNFHXDA J4Cao3bU4mmIrBVjXpfIc02Eftts+nv7CazZ4nIhs/gyz89qp8+voAK6PKT/6k6x2rqA k+uAL3H46ZGPktUcmj0QpbwEjSXNc0yY+5YG5qDHDhZ7HgogQwitUy8j1lnUql7Oc1nz wmUN4rbAWR/8AV+B8iPGQMp+8Ic55Fk75neJmgdNccIz0lQlN2/5+7z9LwBduQa6UKeJ dOCg== X-Gm-Message-State: AOAM5305t7kKmpKwuPwaXNJgaD25D0cGMN01zKsmXpn4Tdg6WfO2xymn jA4/+K/zIh5K6rl646EJrmO2iICQhpT7aH2RAxdTrA== X-Google-Smtp-Source: ABdhPJx/0Kfxw/jydMgdKkoVJGQ9Mem1OgH2yeF1tAZyCD1927v/1Bq1MDPv64DdN//p27FkkBMA80WqL4Ci3Ou7p0I= X-Received: by 2002:a62:7c55:0:b029:1dd:8c65:1ed8 with SMTP id x82-20020a627c550000b02901dd8c651ed8mr6639950pfc.24.1613693400570; Thu, 18 Feb 2021 16:10:00 -0800 (PST) MIME-Version: 1.0 References: <487751e1ccec8fcd32e25a06ce000617e96d7ae1.1613595269.git.andreyknvl@google.com> In-Reply-To: From: Andrey Konovalov Date: Fri, 19 Feb 2021 01:09:49 +0100 Message-ID: Subject: Re: [PATCH] mm, kasan: don't poison boot memory To: George Kennedy Cc: David Hildenbrand , Andrew Morton , Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , Konrad Rzeszutek Wilk , Will Deacon , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Peter Collingbourne , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , Christoph Hellwig , kasan-dev , Linux ARM , Linux Memory Management List , LKML , Dhaval Giani Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: A1A2A2000DA5 X-Stat-Signature: kor3epfrfc81ifwo9idjhi4ni5znbggh Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf11; identity=mailfrom; envelope-from=""; helo=mail-pf1-f180.google.com; client-ip=209.85.210.180 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1613693395-744086 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 Fri, Feb 19, 2021 at 1:06 AM George Kennedy wrote: > > > > On 2/18/2021 3:55 AM, David Hildenbrand wrote: > > On 17.02.21 21:56, Andrey Konovalov wrote: > >> During boot, all non-reserved memblock memory is exposed to the buddy > >> allocator. Poisoning all that memory with KASAN lengthens boot time, > >> especially on systems with large amount of RAM. This patch makes > >> page_alloc to not call kasan_free_pages() on all new memory. > >> > >> __free_pages_core() is used when exposing fresh memory during system > >> boot and when onlining memory during hotplug. This patch adds a new > >> FPI_SKIP_KASAN_POISON flag and passes it to __free_pages_ok() through > >> free_pages_prepare() from __free_pages_core(). > >> > >> This has little impact on KASAN memory tracking. > >> > >> Assuming that there are no references to newly exposed pages before they > >> are ever allocated, there won't be any intended (but buggy) accesses to > >> that memory that KASAN would normally detect. > >> > >> However, with this patch, KASAN stops detecting wild and large > >> out-of-bounds accesses that happen to land on a fresh memory page that > >> was never allocated. This is taken as an acceptable trade-off. > >> > >> All memory allocated normally when the boot is over keeps getting > >> poisoned as usual. > >> > >> Signed-off-by: Andrey Konovalov > >> Change-Id: Iae6b1e4bb8216955ffc14af255a7eaaa6f35324d > > > > Not sure this is the right thing to do, see > > > > https://lkml.kernel.org/r/bcf8925d-0949-3fe1-baa8-cc536c529860@oracle.com > > > > Reversing the order in which memory gets allocated + used during boot > > (in a patch by me) might have revealed an invalid memory access during > > boot. > > > > I suspect that that issue would no longer get detected with your > > patch, as the invalid memory access would simply not get detected. > > Now, I cannot prove that :) > > Since David's patch we're having trouble with the iBFT ACPI table, which > is mapped in via kmap() - see acpi_map() in "drivers/acpi/osl.c". KASAN > detects that it is being used after free when ibft_init() accesses the > iBFT table, but as of yet we can't find where it get's freed (we've > instrumented calls to kunmap()). Maybe it doesn't get freed, but what you see is a wild or a large out-of-bounds access. Since KASAN marks all memory as freed during the memblock->page_alloc transition, such bugs can manifest as use-after-frees.