From patchwork Mon Nov 2 16:03:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11874329 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.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,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 D7868C55179 for ; Mon, 2 Nov 2020 16:05:55 +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 263BD22258 for ; Mon, 2 Nov 2020 16:05:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="uWObgQko"; 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 263BD22258 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:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=PPWCm1tX3+4ebO8Tac/wBwmwWaPWMCmLSoyJIT6HzbE=; b=uWObgQkojB4UxdXqsyfKc+7rj Wca+nU6P11/6LFHZGAMGSc74Fq/kjIvaCTwir2eimAn8CI7g3va13rsGgF4RWcYTmlKkYi4U3AdWa /2EmIafk1PFKO7e8Z8h5d+9TzpiYkUVBQh+TYwyzBIg0N6wd5Y6MTDFaH+JW4oXF6OYaP+nHUxRi2 SUgfkEf8KKYSUvikTU6Buna3W/D126eOqQ9gggqnkBxET8q9gTF9t/mEMswVDD07oL0IsPI7LC8Qb c6RdNPdMu0qzl0mxYHobBRAME67cqzyLHvPMLc4AXZ00CxmmssHCXhDKgBfl4aPDkzgSk2ZWUf8Sh 63BDoFVMQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kZcKO-0006aP-9p; Mon, 02 Nov 2020 16:05:04 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kZcJx-0006Oj-8M for linux-arm-kernel@lists.infradead.org; Mon, 02 Nov 2020 16:04:40 +0000 Received: by mail-wm1-x34a.google.com with SMTP id o81so951897wma.0 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=fTcFIyuzNn4bsCtegv1yMucyBsbKUmW44e4dkZAVwKbDCD2fpb4grsgKIlp/E4Q7hn ALhcuq1NPfXFvuj2814Njrf9Ofe3KkpwLttK1/bH8ilRFjEI4KwGgrpUMEOtFXuTX6VH oCGt+S7dFSnfkxvMTmpljgA3DSO581q7EWmQitGHO30kgA/IRU/iPqSFn0Cb+fMg97FA yLBjeVo0gAaN9YT6SF3Trs8Z4f3Lo/8TdPGLFyKTbVRKvBc7C9dlvS4JPp4fClrNEU06 V1m9K7UqTBGDqp7BXNqD0zAHCzjuKbNR/btntYQHa9H7ncQbt2HWtsLvmOyGUHNoBfbp Oq9A== X-Gm-Message-State: AOAM5326l0MdCrW7wNC/yELfTlX6u6arjUz2L4G2M64aq0FBlGHsQlAv FztAsqkOlEnfzg8SvOtfNZiheRqOp8PTJ4UX 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201102_110437_366025_099A6697 X-CRM114-Status: GOOD ( 16.78 ) 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 , Elena Petrova , Andrey Konovalov , Kevin Brodsky , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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;