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_PATCH,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 5EB4FC433E0 for ; Fri, 5 Mar 2021 23:54:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D10CA650A9 for ; Fri, 5 Mar 2021 23:54:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D10CA650A9 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 014076B0006; Fri, 5 Mar 2021 18:54:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EDF6E6B006C; Fri, 5 Mar 2021 18:54:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D32E66B006E; Fri, 5 Mar 2021 18:54:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0131.hostedemail.com [216.40.44.131]) by kanga.kvack.org (Postfix) with ESMTP id B385A6B0006 for ; Fri, 5 Mar 2021 18:54:45 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4A50B8249980 for ; Fri, 5 Mar 2021 23:54:45 +0000 (UTC) X-FDA: 77887478130.07.1AD012F Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by imf14.hostedemail.com (Postfix) with ESMTP id 40DB8C0007C9 for ; Fri, 5 Mar 2021 23:54:42 +0000 (UTC) Received: by mail-pj1-f41.google.com with SMTP id fu20so103561pjb.2 for ; Fri, 05 Mar 2021 15:54:44 -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=CNxGCp729OVTS5P6uQ6HNjJN45BugeibGn1RfeYppc4=; b=wOuK4AFFOQnE05XJqSetLQLZi5EwCXJ8MYXXz0KDuThxN+q9glQ/S+mGR55NmaH3BD xd9RGIGFImO+DqLtKHaqHCE9JHt/ny6mq2IzvpWiRs7QKX39AEdwOU13LIM4rCsjWmzK rxjbhSDzmiB8O4Xso24fXEXLmsacztDMLjCaziXu8xbPvaGlIz6RszVHxyc94VgyvA0D RLdhCFNbChqnCGNx/m5Qh3T5lAxc0qxAKndRcUULNvDiuZH9aYzHItbn/zFxjDXff4MF POH3we+QmiIe76xD0WrlD4t2U/ebUx6qO8PM3CJRVIJcPmyhtYxyBMq6IT4ZLaaVDIiz fztw== 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=CNxGCp729OVTS5P6uQ6HNjJN45BugeibGn1RfeYppc4=; b=DtiHPHDudGTyQv7sI8u1dbPIV1iGWnRIwTjxnbqeZxvgAdcA/YuwaogKRIi5zoQXgo 8Rw6eDwXR3ljnbd73QUdAtjEv8TNJaSTAXI3y5nPYcxKsXdtRuLaOCjSJzJxiL0GtyLG FAooTLfi3Agyxqfg7p0WbYMahcnWtGya9/5TDbfToBdmsua/LbRl+mOFoBYmJhZYtREX 26M6uLlHAvGegSLpoU1kqrmrHzNXE8EkSkj3LT9GLRsFvf7KTha0FMOrt+SK4c4wNOWH WRiSfxu4FwgX/y6C5eFhV0ziqCJJ3jlmLLubnuaGw4U/VUpXL/WkL8GZ8g1454+k75xH 29Bg== X-Gm-Message-State: AOAM531NBQa3E/yjOl2efq4ARrLTtpRjJ0O+C9J7fF/mG2qlKH/vbDJO mq2GKu8t1O+I3Dz6QTlCpMDZlIdOk0IrvZjXqvAKbA== X-Google-Smtp-Source: ABdhPJypgUPjzeO58PREZy1WSBz6aEuSQMeRIjsjpF1lfpSHzvzN6zb0fGOwDaKN1ZXxg5kD0/v/8UMO3nnDPYpFM2o= X-Received: by 2002:a17:90b:350b:: with SMTP id ls11mr12605611pjb.166.1614988483675; Fri, 05 Mar 2021 15:54:43 -0800 (PST) MIME-Version: 1.0 References: <24cd7db274090f0e5bc3adcdc7399243668e3171.1614987311.git.andreyknvl@google.com> <20210305154956.3bbfcedab3f549b708d5e2fa@linux-foundation.org> In-Reply-To: <20210305154956.3bbfcedab3f549b708d5e2fa@linux-foundation.org> From: Andrey Konovalov Date: Sat, 6 Mar 2021 00:54:32 +0100 Message-ID: Subject: Re: [PATCH v2] kasan, mm: fix crash with HW_TAGS and DEBUG_PAGEALLOC To: Andrew Morton Cc: Alexander Potapenko , Catalin Marinas , Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Andrey Ryabinin , Marco Elver , Peter Collingbourne , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev , Linux ARM , Linux Memory Management List , LKML , stable Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 40DB8C0007C9 X-Stat-Signature: c3n7acrytweytiwehw6di4atdecc8edk Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf14; identity=mailfrom; envelope-from=""; helo=mail-pj1-f41.google.com; client-ip=209.85.216.41 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614988482-951239 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 Sat, Mar 6, 2021 at 12:50 AM Andrew Morton wrote: > > On Sat, 6 Mar 2021 00:36:33 +0100 Andrey Konovalov wrote: > > > Currently, kasan_free_nondeferred_pages()->kasan_free_pages() is called > > after debug_pagealloc_unmap_pages(). This causes a crash when > > debug_pagealloc is enabled, as HW_TAGS KASAN can't set tags on an > > unmapped page. > > > > This patch puts kasan_free_nondeferred_pages() before > > debug_pagealloc_unmap_pages() and arch_free_page(), which can also make > > the page unavailable. > > > > ... > > > > --- a/mm/page_alloc.c > > +++ b/mm/page_alloc.c > > @@ -1304,6 +1304,12 @@ static __always_inline bool free_pages_prepare(struct page *page, > > > > kernel_poison_pages(page, 1 << order); > > > > + /* > > + * With hardware tag-based KASAN, memory tags must be set before the > > + * page becomes unavailable via debug_pagealloc or arch_free_page. > > + */ > > + kasan_free_nondeferred_pages(page, order, fpi_flags); > > + > > /* > > * arch_free_page() can make the page's contents inaccessible. s390 > > * does this. So nothing which can access the page's contents should > > @@ -1313,8 +1319,6 @@ static __always_inline bool free_pages_prepare(struct page *page, > > > > debug_pagealloc_unmap_pages(page, 1 << order); > > > > - kasan_free_nondeferred_pages(page, order, fpi_flags); > > - > > return true; > > } > > kasan_free_nondeferred_pages() has only two args in current mainline. Ah, yes, forgot to mention: this goes on top of: kasan: initialize shadow to TAG_INVALID for SW_TAGS mm, kasan: don't poison boot memory with tag-based modes > > I fixed that in the obvious manner... Thanks! If you changed this patch, you'll also need to change the other one though.