Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3528649pxf; Mon, 15 Mar 2021 11:34:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMDC7/iB4uFbbPRWbg77O5e44CzIQXSjoxuQnMguJnUvhq6huaRIcdHjPmiNR0Ejp9vH/W X-Received: by 2002:aa7:d445:: with SMTP id q5mr31054832edr.382.1615833259756; Mon, 15 Mar 2021 11:34:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833259; cv=none; d=google.com; s=arc-20160816; b=u+sf9mCwek/fz1CHnvwtUJpILTtXI1nLs45kMcb6vGlHmevMYcFSL9yjACamTdPx+z xgkHvJWJMLAyRtMWrB/EpQoJ7mvGAAuDRg8WT6mUEMc/EOOvGlXjOFusYIOHiywvmV8R Jb5PbFHpNlKgHvBIRIai8/OO3whQn1/EHPgvHh1QS3r1YPqoHTrsK0ATYr3xp5784sTn 5ZH9f9OePx8dBS9b5zskdclRQPE8mYnpJHcn9Prxpn16OuWG9P53ICERUvKO2Y/gHhgg 2etqvUUpdZrD8x/4gQuc0Dr1ODG8B+LpOE4UN2wW2+XdhSD1tNUtNPpeRoCdz8FPU3a2 /+gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qe5YvS5kkLMbHqSLrfrYQ0o5pB/cl8NmfVVl0bcGscM=; b=rSClkF53RasX8i51Fdjtda0r1qqaJZ7/pHI2qF0ER1K+GML7PwlO6XlQ4kfPDRwMaK QF5Zyt4sc4BmXWJLddDaAx7rW0JKKfaOn6ang0adXY11tUF+bQbk5mHGFQxAsQFMQbfH 3NLLxFj4IB/y6AW7fm5UCmpP/P28uj3OFgAKr8j8oNx/5Ga1FaycENvrNujm0XIXxy6Y mpssTtbppLhDs8G6IuOkZvzdS7Ym9Jge9ApMW4Zqc6rc2fx69bWSF9Axfuw7d+J+pNnr 1fyZTYLXUlWPbNseag/PP7xEbEYWkhT2HY16uj0gTtRTyZaWcPqZkubjK7bE6DjJEx39 D1kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YRcGAEiZ; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z15si3425934edd.187.2021.03.15.11.33.57; Mon, 15 Mar 2021 11:34:19 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=YRcGAEiZ; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239258AbhCOOqV (ORCPT + 99 others); Mon, 15 Mar 2021 10:46:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:52502 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234604AbhCOOE2 (ORCPT ); Mon, 15 Mar 2021 10:04:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AF61764F0E; Mon, 15 Mar 2021 14:04:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615817067; bh=IZW1XKzyU+1NUFFq5onwYShn7ydW9u5Gt6BHtU1JU0k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YRcGAEiZyagrj0j3fwvlATv3JAY8VzG4l4oaBvVj3zIYdU8TBMVQfTAfCh/tvPgN/ RqM2uVcqasuHYgmaMDngtyazhFIGdgcVbbmPZo697LdTKmKTLr3VZN/QRZCjuOMXTS 9BxEhTD43iawxIflboZbYc+cgwzHDiWp8lnUFFrA= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrey Konovalov , Catalin Marinas , Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Peter Collingbourne , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , Christoph Hellwig , Andrew Morton , Linus Torvalds Subject: [PATCH 5.11 284/306] kasan, mm: fix crash with HW_TAGS and DEBUG_PAGEALLOC Date: Mon, 15 Mar 2021 14:55:47 +0100 Message-Id: <20210315135517.283808562@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Andrey Konovalov commit f9d79e8dce4077d3c6ab739c808169dfa99af9ef upstream. 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. Link: https://lkml.kernel.org/r/24cd7db274090f0e5bc3adcdc7399243668e3171.1614987311.git.andreyknvl@google.com Fixes: 94ab5b61ee16 ("kasan, arm64: enable CONFIG_KASAN_HW_TAGS") Signed-off-by: Andrey Konovalov Cc: Catalin Marinas Cc: Will Deacon Cc: Vincenzo Frascino Cc: Dmitry Vyukov Cc: Andrey Ryabinin Cc: Alexander Potapenko Cc: Marco Elver Cc: Peter Collingbourne Cc: Evgenii Stepanov Cc: Branislav Rankov Cc: Kevin Brodsky Cc: Christoph Hellwig Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/page_alloc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1282,6 +1282,12 @@ static __always_inline bool free_pages_p 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 * happen after this. @@ -1290,8 +1296,6 @@ static __always_inline bool free_pages_p debug_pagealloc_unmap_pages(page, 1 << order); - kasan_free_nondeferred_pages(page, order); - return true; }