From patchwork Fri Feb 26 01:25:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12105585 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 CFC87C433E0 for ; Fri, 26 Feb 2021 01:26:58 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 60CF164DFF for ; Fri, 26 Feb 2021 01:26:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 60CF164DFF 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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id: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=cjpM86HuctzhXWNhWiD8s5rRoR4DvO2Msad6zsTWeCM=; b=HVmgTVcls1/sBurN/i2VqqnftK WmOqdADiC5C0QYFga4L8CXicU3NHH5Gv5unapd9L2in43s4WB9Wdu+GIf5Tp3mwh9PCbQr1J5YtB0 lulq+dklUZg39XKoLnmpr/uBPgdTciVvfWOlpBP0bKwEnmj/njwsit2nDhCkbxmqWMSSSLfeSUDO/ lG9tIZbfy+YJ8QNwMcz4APi57cZrTgVUTaINQF5AcMX5wa+pWIEDPPtvmsZUbYLqynrGtMdIlncNK zVn7enQteplsVhdWkiKC3pyBja9ZTyH1hRiTEl2jw2+MYt1eaVRn8+reZ+PZCIOApzDLzZU5HYcmj AOZt6rGA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lFRtD-0003PA-B9; Fri, 26 Feb 2021 01:25:55 +0000 Received: from mail-qt1-x84a.google.com ([2607:f8b0:4864:20::84a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lFRtA-0003Nc-N9 for linux-arm-kernel@lists.infradead.org; Fri, 26 Feb 2021 01:25:53 +0000 Received: by mail-qt1-x84a.google.com with SMTP id z3so5463274qtv.20 for ; Thu, 25 Feb 2021 17:25:49 -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=fGyKOr2NOKevbTthD2lHJMlPg4rW22LG13Q09TJ/Cwo=; b=uJ3kYZFMxLlqqaX2Rpd/bNsgXGp/tuRktWkUVuBsiZevS3FWcgeedNlg1NIP9RR05Q OiW5+84gPyysjLwJ8tA1/8rRWRei2XESjivD4O/4daEgXJgiPjvKT0VL1nqeB84Hh7yX BuK3Q8feeTPXniLZYAVwdHCAOIL8JVWc6NDK1SyFQXQrCXxf43qF+Xe4QRoOL7wA7Q88 wELUKvoBH4Sf9kgavRQ6xhikOYJpXlqip6C7sZqhsFreA5lTLNBUP56ebjqNH3XccEGg emX6/RAwlaw2MJ+mmOvc8i8Cz7fAnP4iZeIWP2aj+YEj+aWYEjoh9hR1FziZwUDwoIPw a6/g== 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=fGyKOr2NOKevbTthD2lHJMlPg4rW22LG13Q09TJ/Cwo=; b=c62zIfVvLWcOQQ3Biy5Xq7rK0pCSJ47z2e1v8saWprYrrLdxUIlQPA+xkL7ysonwcK kV7gHfbINg3IuOJcp0GrMWEsR/9vHmbSjkwJzhAslcQRWGuzBiDsqO/97TsYR3mWo5NJ RhNyixFTonrJu4c0dzw5NaImbi4G1hII3lYLheo1/7LTclkCg09uhh2scdNztIVZwMmu xzosdtsKgaIrjHiUQysLI/lzex/T6EpneN9+zrCqXt8yK5hjDBDirjyS/D/LxTe3KTOx oZ7RKrP280vzEmP0RgU8uEkSUrJcIoUgdU/D2Dks3ORIh4Ds7Rt8D33aq6V+coB49n2s EHGQ== X-Gm-Message-State: AOAM5309rgt9mM8dCsF+/wirh17A6wtGJ4h7ibYFylLk1Iul/bSEZfFr icZuxcsoVY0BlOEWhyVL4pkYTwg8wB+hr7WJ X-Google-Smtp-Source: ABdhPJwII1GzAbYJNaOMVsGMPtlc/00QWGiqENeLlq67efnXAPi4UcPrIte++d+RVfnvXx9+70ONFd2zGgWbbbPp X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:5c80:fb1e:3d1d:d709]) (user=andreyknvl job=sendgmr) by 2002:a0c:ec4e:: with SMTP id n14mr518858qvq.34.1614302748187; Thu, 25 Feb 2021 17:25:48 -0800 (PST) Date: Fri, 26 Feb 2021 02:25:37 +0100 Message-Id: <1aa83e48627978de8068d5e3314185f3a0d7a849.1614302398.git.andreyknvl@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH] kasan, mm: fix crash with HW_TAGS and DEBUG_PAGEALLOC From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210225_202552_765821_87BC9713 X-CRM114-Status: GOOD ( 13.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, Christoph Hellwig , linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Peter Collingbourne , Dmitry Vyukov 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(). Besides fixing the crash, this also makes the annotation order consistent with debug_pagealloc_map_pages() preceding kasan_alloc_pages(). Signed-off-by: Andrey Konovalov --- 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 c89e7b107514..54bc237fd319 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1311,10 +1311,14 @@ static __always_inline bool free_pages_prepare(struct page *page, */ arch_free_page(page, order); - debug_pagealloc_unmap_pages(page, 1 << order); - + /* + * With hardware tag-based KASAN, memory tags must be set + * before unmapping the page with debug_pagealloc. + */ kasan_free_nondeferred_pages(page, order, fpi_flags); + debug_pagealloc_unmap_pages(page, 1 << order); + return true; }