From patchwork Wed Nov 4 23:18: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: 11883289 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 72F16C00A89 for ; Thu, 5 Nov 2020 05:20:22 +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 D5EBF2083B for ; Thu, 5 Nov 2020 05:20:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="knOLFmWe"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="CcC0FhHr"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="uWjOaiCp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D5EBF2083B 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=knOLFmWeNVfF+t5mCceeUOqbv TPH/yDOotOSnZfS0HSxbKVuydyiiHMSpnEWsjgWLdYimHdAT420yexP/dn3BCYu+sD5miYw1E1gqB 3EJOUwIgZszgr9gh4rPjy0DHLGCtDNuMnBZQ+NEfePn3Yjvka4baQYZlYPxxaNqEMKjgk6k+yraaP +HCaITGSO8auUK0DZcCZQ9PDQunlazwVbmxhNN283uZrPd1YD8aZIlC3Jxx+hmbXKv2MOi/lcb6Jc r/ZXpCXCpFOchbgwECizsRmSpQ32Uvv7vmWNYyWSIw+GiWVsJeFydYfRhTGcknm1+rpw10rDLhY7T iu+J8X8Dg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXgP-0002fQ-LF; Thu, 05 Nov 2020 05:19:37 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5A-00016k-Iq for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=k0rwmvWkh3wc2lbCLJgzaa11WuGN21taMrm4zUJORUQ=; b=CcC0FhHrJm22j6E64n+RqsKczh DMc211VHQyU8xnuy8QdfDLxIAdA61I3e94f4PWtgSuA4P7xaVC+vJbD7WWI4YOqoHQ9DqHCWDqSIE XQfhiLoNjXfvlqH02rL5wSc0xVOctiuvcxU23nUzd3U+la2Yk2y3ZC9bggZeAct6/4RypTPD7XJLn QGPD+YZl51K0R8HNqpCFvttU+VjWbgDs0fk4Ij5Qh1WyKWRUEwwB00vl7l/fiTBoavhQW7iNUt8Z9 DaZF9iCO2jCjBltukagZqDPsKbzS0x4vEI3XKxyRpL6thmkdxlN/852DwYB2hSXKivLzZDRSSVYyo 5vxgrngg==; Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5c-00046Q-Qn for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:19 +0000 Received: by mail-wm1-x349.google.com with SMTP id y187so26404wmy.3 for ; Wed, 04 Nov 2020 15:21:16 -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=uWjOaiCp/aQ7tdjvxD3necJ9LlCN2dKAwKwizWGVIexVk50McV5ni5cQWGWku5ZCFK PKvJmCjMn+bQqYqk+j0XNar7WlUsjTEnoXIzxMF5JurlYjxWSpDdiCoPQBrInZe8TepD Leze21ogS5ZK1uctnGaKZEmhAXr44QJ8D4VwFFBrFBnij6FuL5XUR3100Wi8JTT00hTd wr4UClytKAaMQDTNT9WDH3Lz9D+2x2nhJHxJR5F72qz+WLYLlFdlzLOBgJsYDpREFTjZ nZjiqj+jk+NdXsQC57jljwC3G66hiELMb32lHeUy62pZctwzbq9bPvmKHtxO5hbJ15xX lH1A== 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=qJwMKh+ikZuPjndteD07TCKxi2AT7ITE98AMdDfK8H1dk1+61H6SHhEVLrUQhZKzTD SUHIf3hpR9zCmtw5phyyxd9vranalFXRBGnMpjOcYwnhoPFX4TG3O9gBIMC4SqZXuzy4 MDVctpy3OV6X9WBKNnYKIpJ3/XNfRstDY8DAti7M/0zF7ghdiquOyUzOyi4VCDZNS4rn A8hJ7tJYPUkYgu8oKVgpRedOHmdeB3byFhGLNYJYZlBacf4/2aX1l7jNlfImecMilfTg Rs34KEVHPh7dqT8bEXhC61gqSXxrhD1a2Whu/5RQFQdUUcljkBPnxso6arVOggoVt/tx qFzg== X-Gm-Message-State: AOAM5318OhdOWFRds3o6W001lITIQKIhU5Zs3lgN6dxvejowLzh7hGBj WahSiOtWt7EUT1YCQfNTacyUxw5ROyUBeWE9 X-Google-Smtp-Source: ABdhPJz0zucCZ65+O5+GurNj337OxWPm/l0D5EwqlzuEn6V6sXz3ts50YYxAk/os0lAiyx4hSptYSHMMX4k918L0 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:4d05:: with SMTP id o5mr87270wmh.94.1604532013713; Wed, 04 Nov 2020 15:20:13 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:43 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 28/43] arm64: mte: Reset the page tag in page->flags From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232117_037855_80C382A3 X-CRM114-Status: GOOD ( 15.61 ) 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 , Andrey Konovalov , Kevin Brodsky , Will Deacon , 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;