From patchwork Thu Oct 29 19:25:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11867177 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7C1A56A2 for ; Thu, 29 Oct 2020 19:26:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 133D120825 for ; Thu, 29 Oct 2020 19:26:18 +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="NVC+Ua+z" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 133D120825 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 70BAD6B0071; Thu, 29 Oct 2020 15:26:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 694E36B0072; Thu, 29 Oct 2020 15:26:16 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BCD46B0073; Thu, 29 Oct 2020 15:26:16 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0235.hostedemail.com [216.40.44.235]) by kanga.kvack.org (Postfix) with ESMTP id 115B96B0071 for ; Thu, 29 Oct 2020 15:26:16 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id ACDEA181AEF15 for ; Thu, 29 Oct 2020 19:26:15 +0000 (UTC) X-FDA: 77425943910.08.gun73_23010e12728f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 8C98B1819E764 for ; Thu, 29 Oct 2020 19:26:15 +0000 (UTC) X-Spam-Summary: 1,0,0,dd2583038b9d1f6a,d41d8cd98f00b204,3vhebxwokcpmviymztfiqgbjjbgz.xjhgdips-hhfqvxf.jmb@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2901:3138:3139:3140:3141:3142:3152:3353:3865:3867:3868:3870:3871:3872:3874:4250:4321:5007:6261:6653:6742:7576:7903:9969:10004:10400:11026:11232:11658:11914:12043:12296:12297:12438:12555:12679:12895:12986:13161:13180:13229:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:21795:21990:30051:30054:30055:30070,0,RBL:209.85.222.201:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yf7ay4fu59nebbocemoyhy3hpd7ocyq46ywx7id4wyqmheu1i6zjmhdqzdmk6.k5bygc7hshkrqn4tan959apgfdcqnmws66xshhah6ihu11c1ap5q8wkp7subyjc.k-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL :neutral X-HE-Tag: gun73_23010e12728f X-Filterd-Recvd-Size: 5667 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Thu, 29 Oct 2020 19:26:14 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id j20so2440453qkl.7 for ; Thu, 29 Oct 2020 12:26:14 -0700 (PDT) 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=NVC+Ua+zzy1sTczx96Us29xL21ARG+7hM7eY2liHVfFGBrqaXA72FLBZEk1wBBN7s5 Jwquu2B89uWELg7MQ+5R/qw7kLeZyJoWsNXgcUrdP7aXd3f42d3xCKnmkx2+qzwHnR2j Tfkg0Na4YzIfgOrcUlvAP2fQ13a2g6WybuyRyZ4PUSWOPNB0zqIixVI5O3rmWHJ5plF5 2IcrhXCm6nzj9w02Z7r33LNm0AIrqHLQv8pzLBlVKxwF0ZW1QAlXW00GyNqW4tyFJ+VC 3n+xc6DCv/OXPQBNwB2wKgW/NOIxysTFap0GcIB5DcQ2uqo4Li8vMsy1HKWQsbtbOXob ZMwA== 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=DqwUjtbvCDokNj1xTC+jWZ67HLGG6MPu4pkRNaikrkP2U5WllxWKbpqPy24JHEQEFR xBJU+uMDK+ALakRlcbFmESoEdS5j8dMKx7yjI7TYnpmUTF4cmOy6pvLb/B8ZmYTzDf8z Ts6ml4tUcst2LjnzoidA1HwMWOrXCLwWH6f2/j3pxuqzRqmXeDbvVMOU2cecWO+2TQx7 G9uoJFRlY4NoqCCACxW1fwJuH0R83+xCpqhLBIzordGGcEGQvB6gftR61JGRi1wkecsT +bWWMQ+un6pIOqZ4W635xY/GvBiOY/S37QRNcwiYzKOGpC7+oAlRS2xh0H1pzmxCyYoM 5LBQ== X-Gm-Message-State: AOAM531wj0QlZADfaYg0p5yvZG6bm6edANpBoLQqFm2kDTuKb46ec/hA P7BKpy3h6hmEt1eiBdgqeT6E9NkMewZ5G526 X-Google-Smtp-Source: ABdhPJylIhqkabBCZpdBX+3Tvu7RqR/RhkOnUcvT5jdQ/wBFwf9mnbqA3VqFJMk9ziXNlsJRusckxQ25xsTjimTC X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:e308:: with SMTP id s8mr6182701qvl.10.1603999574230; Thu, 29 Oct 2020 12:26:14 -0700 (PDT) Date: Thu, 29 Oct 2020 20:25:24 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v6 03/40] 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 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;