Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7509157pxb; Thu, 18 Feb 2021 11:59:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJzmOC7zgtsr5iWfdC4zFO2LrsvGji49wcX7i0ouZpDfe1hHk+egT2TPPN9IZr+jyq3K+FFV X-Received: by 2002:a17:906:9bcd:: with SMTP id de13mr5477838ejc.245.1613678345244; Thu, 18 Feb 2021 11:59:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613678345; cv=none; d=google.com; s=arc-20160816; b=fcXcCeToN1i7AaX8vAgJL4+GPsIK+6K9XAoTcxY1vYTfRRJB2XHluLYnowUG2INXa0 8sjvBVDJWznl4p+OjC/O1V7RXx99c9fUhZAguyZsrKc3AVeUC1XYINwGSJ0JeG/k26zx CV39K8cAWxcJwRaJBj+BC1P9XlZ+pizULgny3XbBNwVyGRpW6yDTTWjJ4PqXUBQPkq6K GOluoPkLeAre4YgC1bgvHg5zR303ILjI7BKBBbJepZr9TLtSyxm9jjch/qGsjOD36i0E UTiI6Nc/+Ndf+43mcvtiEdcAkdhjuiIW5OIOb2tOCFBTzJHpaEnvhqYMfEgtm2zLYXld 7DZw== 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=Wz58CA+xdym2cUyo64XiGmMsVDmP1Ip6ib85/PA+8zo=; b=dCpLbj2WidPz+WrUpfOhRHmobcVqfV7ax9wTqwJgaiGr1suQp5xGtDWE7Curd5xs5Z NQMOFkxKoSmijYaoV0fO947e6mJBPRY23xhYI44pCzxa++iqT01hzDJrK5uSNXSXwz0T lrkxC1FUgFQ60LvEZ501A5VpB8/k+PpAPBvsqYOvTJGH0Ldj6nz7U6GxUm3aF7rLGGhN AcIT2frG4VHVGUa38SQhYlKxEC8ljdIG40p8QBMfruV3oEiT5qs2knZPfl3T1ppfVaC+ IVd5GKCL19u4ZmLTKt5Bn28H1a+C6U0ozWyzXtLuLl12sTv+ODs3/r1LPVBt1rw1DJYZ fTBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=W4TbLg8q; 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 ay22si2776238ejb.326.2021.02.18.11.58.41; Thu, 18 Feb 2021 11:59:05 -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=W4TbLg8q; 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 S232149AbhBRT55 (ORCPT + 99 others); Thu, 18 Feb 2021 14:57:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231805AbhBRTlf (ORCPT ); Thu, 18 Feb 2021 14:41:35 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 702F9C061756 for ; Thu, 18 Feb 2021 11:40:54 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id cl8so1969181pjb.0 for ; Thu, 18 Feb 2021 11:40:54 -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=Wz58CA+xdym2cUyo64XiGmMsVDmP1Ip6ib85/PA+8zo=; b=W4TbLg8qMWfsuB1AB1fMJ0DQTaFAcUQPoq+MCDUEp7V6Ciiq+emO4o0yMc0LUcQVGk S40PUiaXN2LyLfo1ylNkspdEEFpE0/hgXez5mBHFrPqWj49PStiPKrJWCNlddVIR4S4y JJAZA3udWx4+/ZhZg4XxsRnz+APo8EZEu+2ay55Dr1HLzkYwmnbeRNgFPUZiLLlDOayP fuYr65h6/T/GhF3hcPGcmyns/NTU7L6GS+bD1W4r5YYwUDff5ENC7jCx5iDLSLfEf8jm 6JWIu9r+O/an6lGfFBSinzW5B1JyjGz9cFZnSwPTT5dSUDpCNH3qYYubCax/srCVhYYO 7NUg== 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=Wz58CA+xdym2cUyo64XiGmMsVDmP1Ip6ib85/PA+8zo=; b=eEYYCjAdvZE2UNalWrRPjWIffl5te5XNCmHKVS0wP7KGwIdF7m+QiKMCbwL/BrG3KH NlxDHBedEeBd1M8W6gIMLIXX1vUM7GSobTuxsnmxBwlwjlLz10gdiQ4g6O9l1FpT57T5 Kh331n13XS+ySeEWRPl1oc0pHLOcn+1pATdMicE89irOuGK+xeY3/dfBRR2u9zAFxaKr dlZT8X7T/YrcKTlLTDTDvVWlPP8rXB84BRwKPTDlFCahllr+3tT1Fk3Tk7LO11X4mcM4 uucd8WNXTIp2Qz/Yea1DNmnWyrp05K1UH2EUjG32izfvRq0rHyG1cXVEhToI9HRGLVe8 d8pA== X-Gm-Message-State: AOAM532Y4ASXztD+3DdtqFKdPLkvkNq67yrYxFUz5OHlpFwthLeFEUfA 5LP9k5zmRm1qZw2h/HoXKbs6PqFHXfH8FS5GWbjtbw== X-Received: by 2002:a17:90a:64cc:: with SMTP id i12mr6170pjm.41.1613677253685; Thu, 18 Feb 2021 11:40:53 -0800 (PST) MIME-Version: 1.0 References: <487751e1ccec8fcd32e25a06ce000617e96d7ae1.1613595269.git.andreyknvl@google.com> In-Reply-To: From: Andrey Konovalov Date: Thu, 18 Feb 2021 20:40:42 +0100 Message-ID: Subject: Re: [PATCH] mm, kasan: don't poison boot memory To: David Hildenbrand Cc: Andrew Morton , Catalin Marinas , Vincenzo Frascino , Dmitry Vyukov , George Kennedy , 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 18, 2021 at 9: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 :) This looks like a good example. Ok, what we can do is: 1. For KASAN_GENERIC: leave everything as is to be able to detect these boot-time bugs. 2. For KASAN_SW_TAGS: remove boot-time poisoning via kasan_free_pages(), but use the "invalid" tag as the default shadow value. The end result should be the same: bad accesses will be detected. For unallocated memory as it has the default "invalid" tag, and for allocated memory as it's poisoned properly when allocated/freed. 3. For KASAN_HW_TAGS: just remove boot-time poisoning via kasan_free_pages(). As the memory tags have a random unspecified value, we'll still have a 15/16 chance to detect a memory corruption. This also makes sense from the performance perspective: KASAN_GENERIC isn't meant to be running in production, so having a larger perf impact is acceptable. The other two modes will be faster.