Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FB3538DD8 for ; Fri, 17 Oct 2025 01:14:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760663658; cv=none; b=o65nduOzUeyVJr6BZcnh1ERsFX6t4BuWuLr5AEtww33/2GIiALotCVB4Zxi8Wfvz9jYV4y5QDJYVLcSCHcqhlXyUgFiO9BU0KPabLBlvyxl0VBiXQNZ0NTEKIA9ldGNfjeIWmRznXBck7H2LAzpA0gsvqRHT/nYN5P33lqdeWAM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760663658; c=relaxed/simple; bh=T7NlNelf79fpZKSZqrQ9nDiGHT5HRR1YtgWpkPNbiOU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I7RXXmVTjboOW1GA44IcFTueG9XQhQq/S554NmrzD+DwU3/1JN7NzSkqW1FB3Y+Ouyco9HoATuQe+2TMSnjavUx16+Js1eH9wQxT4JAM/GATgcn5EVzsbFeEmH0XykDmxKbBmc3N3phvTSjViHrXyapPx+YuPAbkrCWHRr5iL30= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GKcE7uPh; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GKcE7uPh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41E94C4CEF1; Fri, 17 Oct 2025 01:14:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1760663658; bh=T7NlNelf79fpZKSZqrQ9nDiGHT5HRR1YtgWpkPNbiOU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GKcE7uPhhYdUWOXz93MRknymE3zepKx973e8Hup58Q4yrEv3wvo/3JaCPxN5+hfk0 guIM8ma/CtZPBhQPXhamCA7D5/OmVk0TsFV+oZ7GGNENI9E/0P9EOuLTr4NnriqDKI HrvvVy7Uz9qPqBckd1HSMEchpW2hie3CyWIGq7bU839LhJKsKmX+IYSE28wr6Uxe8B r7ZJdRQTOH2A20Iq345wKAJx5wnVvwhUuOd4J47J8Fa8Xv9O0bzZFwSa4DxmYy2vl/ wyj3tqSeh2luEMWVMO7UG+c/SIBQb+mMy6ho4B45ezGqwP1ih2Oc6eWNj1+Qg027zH tsWSuntm2FWIA== From: Sasha Levin To: stable@vger.kernel.org Cc: Catalin Marinas , Gergely Kovacs , Will Deacon , David Hildenbrand , Lance Yang , Sasha Levin Subject: [PATCH 6.12.y] arm64: mte: Do not flag the zero page as PG_mte_tagged Date: Thu, 16 Oct 2025 21:14:15 -0400 Message-ID: <20251017011415.3502373-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2025101645-blissful-snagged-feca@gregkh> References: <2025101645-blissful-snagged-feca@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Catalin Marinas [ Upstream commit f620d66af3165838bfa845dcf9f5f9b4089bf508 ] Commit 68d54ceeec0e ("arm64: mte: Allow PTRACE_PEEKMTETAGS access to the zero page") attempted to fix ptrace() reading of tags from the zero page by marking it as PG_mte_tagged during cpu_enable_mte(). The same commit also changed the ptrace() tag access permission check to the VM_MTE vma flag while turning the page flag test into a WARN_ON_ONCE(). Attempting to set the PG_mte_tagged flag early with CONFIG_DEFERRED_STRUCT_PAGE_INIT enabled may either hang (after commit d77e59a8fccd "arm64: mte: Lock a page for MTE tag initialisation") or have the flags cleared later during page_alloc_init_late(). In addition, pages_identical() -> memcmp_pages() will reject any comparison with the zero page as it is marked as tagged. Partially revert the above commit to avoid setting PG_mte_tagged on the zero page. Update the __access_remote_tags() warning on untagged pages to ignore the zero page since it is known to have the tags initialised. Note that all user mapping of the zero page are marked as pte_special(). The arm64 set_pte_at() will not call mte_sync_tags() on such pages, so PG_mte_tagged will remain cleared. Signed-off-by: Catalin Marinas Fixes: 68d54ceeec0e ("arm64: mte: Allow PTRACE_PEEKMTETAGS access to the zero page") Reported-by: Gergely Kovacs Cc: stable@vger.kernel.org # 5.10.x Cc: Will Deacon Cc: David Hildenbrand Cc: Lance Yang Acked-by: Lance Yang Reviewed-by: David Hildenbrand Tested-by: Lance Yang Signed-off-by: Will Deacon [ Adjust context ] Signed-off-by: Sasha Levin --- arch/arm64/kernel/cpufeature.c | 10 +++++++--- arch/arm64/kernel/mte.c | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index 9ca5ffd8d817f..5e68d65e675e5 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -2279,17 +2279,21 @@ static void bti_enable(const struct arm64_cpu_capabilities *__unused) #ifdef CONFIG_ARM64_MTE static void cpu_enable_mte(struct arm64_cpu_capabilities const *cap) { + static bool cleared_zero_page = false; + sysreg_clear_set(sctlr_el1, 0, SCTLR_ELx_ATA | SCTLR_EL1_ATA0); mte_cpu_setup(); /* * Clear the tags in the zero page. This needs to be done via the - * linear map which has the Tagged attribute. + * linear map which has the Tagged attribute. Since this page is + * always mapped as pte_special(), set_pte_at() will not attempt to + * clear the tags or set PG_mte_tagged. */ - if (try_page_mte_tagging(ZERO_PAGE(0))) { + if (!cleared_zero_page) { + cleared_zero_page = true; mte_clear_page_tags(lm_alias(empty_zero_page)); - set_page_mte_tagged(ZERO_PAGE(0)); } kasan_init_hw_tags_cpu(); diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index 6174671be7c18..5d63ca9667370 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -428,7 +428,8 @@ static int __access_remote_tags(struct mm_struct *mm, unsigned long addr, put_page(page); break; } - WARN_ON_ONCE(!page_mte_tagged(page)); + + WARN_ON_ONCE(!page_mte_tagged(page) && !is_zero_page(page)); /* limit access to the end of the page */ offset = offset_in_page(addr); -- 2.51.0