From patchwork Sat Mar 6 00:04:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12119599 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=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT 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 887AAC433DB for ; Sat, 6 Mar 2021 00:06:28 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 01D2B650AC for ; Sat, 6 Mar 2021 00:06:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 01D2B650AC Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc:To:From:Subject:Mime-Version:Message-Id:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=GixKN4JbTj5ZTRxPVJ4CnDyilPcDWKGQqPBdeqqEJac=; b=gCmPg5we2WzVfGaCVYelfdMcs/ P9QFrvU0va7l0wBykayLqq3mlI0cog8NV2S4W9ZkXfI1YvjnKTinjmRXrljQ67HvV0ysjFkf9XHVE vm1wVEBu/9esM/YLRIvKgGOOLQDDOr4LHCgQ+8p67IVw3Xk0QNmrYO4r2e0IM3NWh805NAuSH6Vl5 7N7WF+zl9kpOyvY8m/RkKiygTKsa+UeVvBioID+4C4CFX4ENcAmmxgIoLVeC97S2GpPQVwLyKNtOt K0ROyJmfpaY7Q9lsQkExuDzjltcrZFlorBvr1a3ApAvW2fKPhdOyQzwGyOjAN5WHiEDIQGUeTqYzi NuubKolQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lIKRG-00HGuB-NW; Sat, 06 Mar 2021 00:04:58 +0000 Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lIKRC-00HGs5-E8 for linux-arm-kernel@lists.infradead.org; Sat, 06 Mar 2021 00:04:56 +0000 Received: by mail-wr1-x449.google.com with SMTP id e7so1759325wrw.18 for ; Fri, 05 Mar 2021 16:04:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=EHP7VMOyCMZT7G8oJ44o5p67301sGJyRfDw3NYRjics=; b=syUBlHO1kOWFJOodIyb4YI4jlXgoEwyj8rfVCJ66iyJRSRQan1JHjGV5TtfCIvDilv 53aCs4VLDLghGgTGm1fWWVgudz4f58/2a2I409FcCZL1W2DlN5fL+0E9kz+ONZO3O2WX +JwMhkjc4whUPCGt8B2ntE5NLY/oiVaj2TslvXEwhDvJnPWJQYxXlegwU0+Vk6MlLgAl sioVT/9tShnXE+d/R11L0gthxG/OI+q9v98seYdn2W2D03Xwu03q0FYzhNwJPnEWZkjS mtlH6DOtJTVYt9LLNwj/LCNDgs621glZiXh/oldA95SAcV/IEDnfR/40AVbKJEGNbUtO y6mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=EHP7VMOyCMZT7G8oJ44o5p67301sGJyRfDw3NYRjics=; b=efe78D0cxUJdDOEK6qpLpSxKyvN1q1K1JfOQgM+xeENmaE8tGYuef3HxSMnXd0gNZq wyzLVNejg6qlruTqqIcnkunpRdjBPMvUERRqegEeBBpISl1T8kpLpTGGobFoyRjg+Wdm Ojf6mf2Y1HKgXenytIhntqXC+rESb98omqzsdnImKE2nEFWVxqtKzxyU7SbrOy0GK8nr rFVecykbatwt9v+LEJDWWAUQqRiHJAeSP5LYi2VKWCNkhq0IPCRlkzZIx2USLh3kwfMa GkcDZ9dt4XCEijxs2Ecv9MYRIZVSVbMvF5P6lHpy7N6HyWC1okJFLI6QzeUn2g1fCy4z h7oA== X-Gm-Message-State: AOAM531hUftS4Tl0URZkI+YgCYX4uDabx9+z0ACQp73ZIOYKJbGjoPPY LTMENvbuzVVYBZqGdOzVRU3Bxiwtd53zQJ8b X-Google-Smtp-Source: ABdhPJylKFVLWhT8oIe4NsKiK01/zxowgX06hrCCcstO7kGSRbQ/IustDFMRaegK6r+on3Lv24iapLiGLHiyX3Wi X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:953b:d7cf:2b01:f178]) (user=andreyknvl job=sendgmr) by 2002:a05:600c:4292:: with SMTP id v18mr10970532wmc.23.1614989092621; Fri, 05 Mar 2021 16:04:52 -0800 (PST) Date: Sat, 6 Mar 2021 01:04:49 +0100 Message-Id: <803741293885a20aa5fddb28172ce0a378b7d793.1614989073.git.andreyknvl@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH v3] kasan, mm: fix crash with HW_TAGS and DEBUG_PAGEALLOC From: Andrey Konovalov To: Andrew Morton , Alexander Potapenko Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Andrey Ryabinin , Marco Elver , Peter Collingbourne , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov , stable@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210306_000454_689271_678A56CB X-CRM114-Status: GOOD ( 11.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. Fixes: 94ab5b61ee16 ("kasan, arm64: enable CONFIG_KASAN_HW_TAGS") Cc: Signed-off-by: Andrey Konovalov --- Changes v2->v3: - Rebase onto mainline. --- mm/page_alloc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 3e4b29ee2b1e..c89ee1ba7034 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1281,6 +1281,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); + /* * arch_free_page() can make the page's contents inaccessible. s390 * does this. So nothing which can access the page's contents should @@ -1290,8 +1296,6 @@ static __always_inline bool free_pages_prepare(struct page *page, debug_pagealloc_unmap_pages(page, 1 << order); - kasan_free_nondeferred_pages(page, order); - return true; }