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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0142FC636D4 for ; Mon, 13 Feb 2023 18:48:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 628906B0072; Mon, 13 Feb 2023 13:48:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D8106B0074; Mon, 13 Feb 2023 13:48:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C69D6B0075; Mon, 13 Feb 2023 13:48:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3C38D6B0072 for ; Mon, 13 Feb 2023 13:48:04 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E83F1C0569 for ; Mon, 13 Feb 2023 18:48:03 +0000 (UTC) X-FDA: 80463153246.05.8CC778B Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf12.hostedemail.com (Postfix) with ESMTP id 1D32440016 for ; Mon, 13 Feb 2023 18:48:00 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf12.hostedemail.com: domain of cmarinas@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676314081; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jJDmGVRHisD7Zk5+MGHj8DbE5N9qhAi9JCHTlG6fNc4=; b=l6x3Uw0cJbyvIUSBsJyWtFwu1B0ZvNd9xRO/3zpExEagRpNBBZTU0Y2Bjmb0TiQPAOOlze YZs/W3kCnhddvwbqxT+o4F3UZXd6Z20QL0pUoeb7G1vsINNnl9ROlO+8I1PKCYEPcG1yxB B/fqgFMHnK6SUXav2bZUlR86SEqpM2Y= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf12.hostedemail.com: domain of cmarinas@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676314081; a=rsa-sha256; cv=none; b=ZZ16x5xG2eq37jW38ZRd64UWIP6BpbFM/wVRdzzYulLC30SQp+7EGAvXgp0/GTG3V2kE6+ kzffiTqxslOQG6cY/Y2En4QFOsZi9AE90fqsli4VooFXlk9aQ+B++Pzmwxa0rSUy1Ss68P 4CUt1P58nmxOaPoXQyyKPD9TOrlCY7M= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 27989B816D4; Mon, 13 Feb 2023 18:47:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7B06C433D2; Mon, 13 Feb 2023 18:47:54 +0000 (UTC) Date: Mon, 13 Feb 2023 18:47:51 +0000 From: Catalin Marinas To: Peter Collingbourne Cc: Qun-wei Lin =?utf-8?B?KOael+e+pOW0tCk=?= , "andreyknvl@gmail.com" , Kuan-Ying Lee =?utf-8?B?KOadjuWGoOepjik=?= , Guangye Yang =?utf-8?B?KOadqOWFieS4mik=?= , "linux-mm@kvack.org" , Chinwen Chang =?utf-8?B?KOW8temMpuaWhyk=?= , "kasan-dev@googlegroups.com" , "ryabinin.a.a@gmail.com" , "linux-arm-kernel@lists.infradead.org" , "vincenzo.frascino@arm.com" , "will@kernel.org" Subject: Re: [PATCH v2 0/4] kasan: Fix ordering between MTE tag colouring and page->flags Message-ID: References: <20220610152141.2148929-1-catalin.marinas@arm.com> <66cc7277b0e9778ba33e8b22a4a51c19a50fe6f0.camel@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 1D32440016 X-Stat-Signature: kmjzc593rotuyzy8ut9nk6gkdup1hjj9 X-Rspam-User: X-HE-Tag: 1676314080-965058 X-HE-Meta: U2FsdGVkX1+Z0aLgK9OE/OFnDQHG2sQ2QAr+xIu0GdKKDFyBF9CD6P1Zj8MN4CiEu3eQSgmr3z/Gm+sFzBrA2mhZYszvrkeWSr28bo17bvOvCsD2tymgrKcrkI5Fe4drQ2CseYp+01oBrnzxTiA/2qBCJBAbp//PMBNr6cEoYUy2kfBWDeQiY4OogZqPoRsGKxXD9EMDLEpOVN1fNX31tdq5yNOdPxozaFDNw7AQeXoGVgDYY5zG3Cnl0raqw2nEVWvywnoNjXlyteJ+LxIsoP9sBXJiah+fywcGI1zaTwnYzIpt0b1NfDuwavCqaVqSCLZraNStDfubiGf7arF19DZLzlr3Kw1GhB+ukkJgpGhxsFSRcD5nSPR3H0LCAc4wITC1XymM4t732FKbzPOCrA5OvNHYrmjx44/hplb/raKpkPQwxQhYiofljZUCitQyQACqLH0Db9qLPECZ3ohouOaAfT7/vNY42ILoSTPcIQ3KMMW+C3XhpUSN/rY74e6G0u4+kXz1YpysSZNdZa46wBq7YszUiOJTfcwrkiXHVctzZWJYPKTcwhm6gwD3AKKgQ13DaiwSPQmJ5jQ1PE0tc/68MiJmhcx8SOOjhNmAYTpNFAJdLgeb7ufaFX45YHBisABCbhrYoar3w7YntNo9oyWhBF2iJPL3hulAfb8jWjAP0Pxm3Z9q+4f2gmd7ZZIpEQ0RbhNZu+UOmYYJVx37yXlzrtQPhEn08EIJe4scs7cZUQTOYhAM606cj5uTbCnYTEimI0+3agvZw1zIcWpqn9eQbdfGP5fzNOYEoy/tFUwNTj6AI7yHKMUb8idfMyhIjriQl7lIaHBAbzSlrx9Syn9FClOSxKR4tol+CnInGBFXmOhRXs8Klqln1tPc0ZftNIskB/qxNZLEuhdOTEv6MSOU2YpJafhpnrlkdfEp319VXAZjIHjneUQfogmws/eadWDSsy6Gc1Tz5a59WI3 DfCP59aE pkM9zNcN2Sl29l2TgNI2BPRfZxrlUiwqkwt2TvN8MeyDX0XYQpWg6fQZra3qoyNaq70ZSBg75RtM7mzpW+WIbr2dVV5dRiy6mlCnfqAW478B9KQT4xNox05o99R4mpbL5OJ/Z62YthSkAmrSqDqD1Q3fIaFFg0dLbpXU+4vK0Emoxu3n2THMA02Td7e80w9WBLTeFCfSph1Dr6V0Xl0wyxzEiBuTrI/QYWRDd+EpKCN6xhGtSE8XW5t0yURy1x6IA6U4olONul7BqzCnyo5YaQFAZwXWoIuoksWHI/kPQ2MInw55qcgYNj2tPlWqCAkU39mxOXjt5eeQU0+B/x4ol7QY3+RIA8t7EM+lrjATX5AV16HJHKCUI7mA9U3/aJh+pJ4DQIMVk3mQq7qoa+9pQOxV8W9hUBgWHq1wsNChPq0xpJ8F8uJEU4xALtN5qQnsZblGQr3vuUPszETKbOFBp1yy58I3YiimT2efgxpl46LoD8NnRGHhAvUb+fuSgRotNTez+cvAuq1zl0Sl/9ecYHecK6pN+32dB5z8Adt9er+8GNkWWIVvlzRlbFXEptd9e9DpdUrzmG12OqccmJw68l7o+zKn9kXGYsNWx 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: On Fri, Feb 10, 2023 at 11:03:45AM -0800, Peter Collingbourne wrote: > On Fri, Feb 10, 2023 at 10:28 AM Catalin Marinas > wrote: > > On Thu, Feb 09, 2023 at 10:19:20PM -0800, Peter Collingbourne wrote: > > > Thanks for the information. We encountered a similar issue internally > > > with the Android 5.15 common kernel. We tracked it down to an issue > > > with page migration, where the source page was a userspace page with > > > MTE tags, and the target page was allocated using KASAN (i.e. having > > > a non-zero KASAN tag). This caused tag check faults when the page was > > > subsequently accessed by the kernel as a result of the mismatching tags > > > from userspace. Given the number of different ways that page migration > > > target pages can be allocated, the simplest fix that we could think of > > > was to synchronize the KASAN tag in copy_highpage(). > > > > > > Can you try the patch below and let us know whether it fixes the issue? > > > > > > diff --git a/arch/arm64/mm/copypage.c b/arch/arm64/mm/copypage.c > > > index 24913271e898c..87ed38e9747bd 100644 > > > --- a/arch/arm64/mm/copypage.c > > > +++ b/arch/arm64/mm/copypage.c > > > @@ -23,6 +23,8 @@ void copy_highpage(struct page *to, struct page *from) > > > > > > if (system_supports_mte() && test_bit(PG_mte_tagged, &from->flags)) { > > > set_bit(PG_mte_tagged, &to->flags); > > > + if (kasan_hw_tags_enabled()) > > > + page_kasan_tag_set(to, page_kasan_tag(from)); > > > mte_copy_page_tags(kto, kfrom); > > > > Why not just page_kasan_tag_reset(to)? If PG_mte_tagged is set on the > > 'from' page, the tags are random anyway and page_kasan_tag(from) should > > already be 0xff. It makes more sense to do the same for the 'to' page > > rather than copying the tag from the 'from' page. IOW, we are copying > > user-controlled tags into a page, the kernel should have a match-all tag > > in page->flags. > > That would also work, but I was thinking that if copy_highpage() were > being used to copy a KASAN page we should keep the original tag in > order to maintain tag checks for page accesses. If PG_mte_tagged is set on the source, it means that the tags are no longer trusted and we should reset to match-all. Otherwise if copy_highpage() is called on a page that was never mapped as PROT_MTE in user space, PG_mte_tagged would not be set on the source and no tags copied. In such case, we should keep the original KASAN tag in the destination. Unless I misunderstood what you meant. -- Catalin