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=-12.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 05028C00A89 for ; Mon, 2 Nov 2020 16:06:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A656E22258 for ; Mon, 2 Nov 2020 16:06:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="bIDVeRsj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A656E22258 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 4A7F56B00B7; Mon, 2 Nov 2020 11:05:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4303D6B00B8; Mon, 2 Nov 2020 11:05:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25CF46B00B9; Mon, 2 Nov 2020 11:05:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E03C56B00B7 for ; Mon, 2 Nov 2020 11:05:54 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 882F5181AEF09 for ; Mon, 2 Nov 2020 16:05:54 +0000 (UTC) X-FDA: 77439954228.18.chain25_5113670272b1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id F02E310042B76 for ; Mon, 2 Nov 2020 16:04:35 +0000 (UTC) X-HE-Tag: chain25_5113670272b1 X-Filterd-Recvd-Size: 5671 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Mon, 2 Nov 2020 16:04:35 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id t21so2014798wmt.8 for ; Mon, 02 Nov 2020 08:04:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=k0rwmvWkh3wc2lbCLJgzaa11WuGN21taMrm4zUJORUQ=; b=bIDVeRsji4tBcSziaWmd3p8Yom+Rz5Zbrz5Yqz14PpIs5s5KmlgJzz8X15ZWTZdsFQ 5Q2lmUEKPMg9u+bmW/E0w/GBlrnJeD7xVNx0WbfKgCOVvhoQkBH/kTXwhz5FdPJfKygJ uzjY6CjqFdyqwfpUMj2T4QGYES4YY3Nyl786lmwKjtkymBWJHQjZ0syRB8Q8UXpImsUs run3bc/c/+IHUk5HNoX4yEGFwIgbwB5gotPzKnfbO+zYpPJkQzFrhfv9fiYCm2Cz4iI9 mJIQ8LogebzOMVH/8OvnfLoA5Sum2PoDekgIcZU01aJcNQ0fVBfqVsNxGIJZ/JCZTbFg Pa+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:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=k0rwmvWkh3wc2lbCLJgzaa11WuGN21taMrm4zUJORUQ=; b=PJ/6rRwfUCbQlxoGIyCw2Vgx5bVtO8q46k//GIzYNtlCLIsrv1kLUjXYZRRGDk/YjP 6oiIzwbnnH6IH4ZQG34OZiN8vU0sNyCpoKH7vZnAhZaOWXcJs3B86pYYHqwxmMztLrii 99IdSqtxB8HJW38FPyvZ8/ipLCWY1wScQZK2AE3GX6G2pefx1WRwUy6/XKleUAeb0Bfq Qc0HEm0twRocLKJ/1kN6LyGlJi9sZQ56ezId8meMYfXSXCk9jp7Yjl/fMI+Bn5QRJCbK jNZozPH5txQQJWnoqkqhlk782mbvmTa4PnxNC3Erh/xLQ9a2qKrkCSymY4TDlxea5sYa Fg0w== X-Gm-Message-State: AOAM533TAxaS8I4q7fACsY+OVCB7+LWcNF+VvCEpSmWOg4Ad4uYg4HEE pbxLqYyIYB2Ly9wWbhfSRj3HR387cDdjGcPA X-Google-Smtp-Source: ABdhPJyZIJTcwnQm65tgUQlzGPuO+nIq44DxEt+DE7AwfFdTHqXm3mrrutL6CaLDLnbfZYj420Vs2HWNKZogn9w+ X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:600c:414b:: with SMTP id h11mr17902427wmm.157.1604333074095; Mon, 02 Nov 2020 08:04:34 -0800 (PST) Date: Mon, 2 Nov 2020 17:03:43 +0100 In-Reply-To: Message-Id: <88290ed7a2bafc5e1eb4872ec0eebac5060d0b64.1604333009.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v7 03/41] arm64: mte: Reset the page tag in page->flags From: Andrey Konovalov To: Catalin Marinas , Will Deacon Cc: Vincenzo Frascino , kasan-dev@googlegroups.com, Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Content-Type: text/plain; charset="UTF-8" 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: From: Vincenzo Frascino The hardware tag-based KASAN for compatibility with the other modes stores the tag associated to a page in page->flags. Due to this the kernel faults on access when it allocates a page with an initial tag and the user changes the tags. Reset the tag associated by the kernel to a page in all the meaningful places to prevent kernel faults on access. Note: An alternative to this approach could be to modify page_to_virt(). This though could end up being racy, in fact if a CPU checks the PG_mte_tagged bit and decides that the page is not tagged but another CPU maps the same with PROT_MTE and becomes tagged the subsequent kernel access would fail. Signed-off-by: Vincenzo Frascino Signed-off-by: Andrey Konovalov --- Change-Id: I8451d438bb63364de2a3e68041e3a27866921d4e --- arch/arm64/kernel/mte.c | 1 + arch/arm64/mm/copypage.c | 1 + arch/arm64/mm/mteswap.c | 1 + 3 files changed, 3 insertions(+) diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index 8f99c65837fd..06ba6c923ab7 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -34,6 +34,7 @@ static void mte_sync_page_tags(struct page *page, pte_t *ptep, bool check_swap) return; } + page_kasan_tag_reset(page); mte_clear_page_tags(page_address(page)); } diff --git a/arch/arm64/mm/copypage.c b/arch/arm64/mm/copypage.c index 70a71f38b6a9..348f4627da08 100644 --- a/arch/arm64/mm/copypage.c +++ b/arch/arm64/mm/copypage.c @@ -22,6 +22,7 @@ void copy_highpage(struct page *to, struct page *from) copy_page(kto, kfrom); if (system_supports_mte() && test_bit(PG_mte_tagged, &from->flags)) { + page_kasan_tag_reset(to); set_bit(PG_mte_tagged, &to->flags); mte_copy_page_tags(kto, kfrom); } diff --git a/arch/arm64/mm/mteswap.c b/arch/arm64/mm/mteswap.c index c52c1847079c..0e7eccbe598a 100644 --- a/arch/arm64/mm/mteswap.c +++ b/arch/arm64/mm/mteswap.c @@ -53,6 +53,7 @@ bool mte_restore_tags(swp_entry_t entry, struct page *page) if (!tags) return false; + page_kasan_tag_reset(page); mte_restore_page_tags(page_address(page), tags); return true; -- 2.29.1.341.ge80a0c044ae-goog