From patchwork Fri Mar 5 23:36:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12119557 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 6F1A3C433E0 for ; Fri, 5 Mar 2021 23:38:32 +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 B93F364D96 for ; Fri, 5 Mar 2021 23:38:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B93F364D96 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=BxXtNE9lmlnjHOJTya6ewB2qZg3IH7ohLD0PtgwuG60=; b=lPXO9s/NwnW6pa2aJg1gApH+sR PmHXFU83XsapqFhjuuiXwUnUxoc4JwGbhdpLom9r5fC98RliRECpcsCfwcRh+4uUKLle0eqq8rfs4 paghKX6zE08nT2t8MxgJTcN3aYBRChOswg6y24HU5KA9NcZzkJRrpGmfklIEpWGqcDh6fgJ//yp3Y RD2eb0cGFHIO0sTDdnKIcO4Pg52JrSKmwd421wFWgdGIFkvDZZ/cJ2/7EAXjnxcY+CqRJXV3rxsuX lvw/y3yQIumvsPZ6r4NOw36wZNRtYMETULtVlSQ0sSgfj39Suwy272moq+ofi8oZMPAbAygWFUcwu nYS+K47A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lIJzx-00H8z2-19; Fri, 05 Mar 2021 23:36:45 +0000 Received: from mail-qv1-xf4a.google.com ([2607:f8b0:4864:20::f4a]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lIJzr-00H8xi-RP for linux-arm-kernel@lists.infradead.org; Fri, 05 Mar 2021 23:36:41 +0000 Received: by mail-qv1-xf4a.google.com with SMTP id dz17so2720626qvb.14 for ; Fri, 05 Mar 2021 15:36:38 -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=MNZ6L1aoJDnvOEvMxOUk5KgG8S0E1lmCTxqkRycD2ZQ=; b=lRxvY4KKDvqZKuNX1Tl3icHmQWAvffTqQRCvTpt+3V7sZsi7tYKqVnmaIlrt3u5Vzr bolx5J0c1YpV/Zh8eyNR9f64jABwRyTE7d6NDn31U9pqDHdIuHHVFYQXtx2LN/+E+/NM 2ADrbneU1zRymqKO4sbeqpUDK3v6trsmMGr/L70Yo/IYR7CvJZS5kKVI2WmVp/uKSjO+ 4gDzyxUJgDjW5OR+/MDcECeY8Ss50TV3gMaGOyEkEADlwnzocPKzuaqT/gC0D/ugQbv8 akyryxoC3ihls/98DC11ASKNeQqe2+0VsMuXZeqiZoNRhzUgfSrXpDVU3xJMAngWT48f +yLg== 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=MNZ6L1aoJDnvOEvMxOUk5KgG8S0E1lmCTxqkRycD2ZQ=; b=bkVFcmJ3rIYpkbygrqGA7qMRanpJFU3ZcCTQT9IAI8pjc0UqA8aQwuv5xd0XUN513K OGiKBd1+zwjVXlcCSzNvqtRLRd9aJvFmsss1k6MiegFYA86AryC3UGTf2ZVfdbJy1nx8 x4lyLdtS6tWmZxVpWtdM3bPqcnttVUCLfvB9qLGvSCprTGkYlO4Uc0UdKvZOGWeTfHH1 DcV2sQ3TXwIjqcSaLG54GvMFSmPtWyF5RfkWZVJM9frYyesIcGgS0rQqnnpWqxPPWSiz p4vVhj5SsuXqOQuLFBvhizpN0SNRm4a4KdY7XhkQg1OtPfcFmPsWKOrR4M33lV04la2d RUkw== X-Gm-Message-State: AOAM531kjdi1+BQk/D61JlmDI4KzavbyNLJqGcw0YMAGMEuILlINFmLT k6jGXgSLLcx1EufhZiX/g0DhzlHsosRjygqp X-Google-Smtp-Source: ABdhPJzd20tLO23T5pXp0bHE5QJ4BYRPW1FhEx+WK2EYa8ywF7Fp5O6OObSx4vmYzyLM7fcw9UWAo7D2s7PyojO9 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:953b:d7cf:2b01:f178]) (user=andreyknvl job=sendgmr) by 2002:a05:6214:1144:: with SMTP id b4mr11326208qvt.12.1614987396545; Fri, 05 Mar 2021 15:36:36 -0800 (PST) Date: Sat, 6 Mar 2021 00:36:33 +0100 Message-Id: <24cd7db274090f0e5bc3adcdc7399243668e3171.1614987311.git.andreyknvl@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH v2] 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-20210305_233640_046205_15B5A948 X-CRM114-Status: GOOD ( 11.76 ) 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 v1->v2: - Move kasan_free_nondeferred_pages() before arch_free_page(). --- 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 969e7012fce0..0efb07b5907c 100644 --- 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; }