From nobody Thu Apr 2 01:50:52 2026 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) (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 266B12F1FD0 for ; Mon, 30 Mar 2026 14:34:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774881261; cv=none; b=ZA5OLMvrBAPQa0IJoG7pA6JreHoJPsGx3+C/1sVP0IDbxx8H6HEr3+x6scpEOThhl81zyNn0c2h+3WKlpo94ZeyJkOVGxUyX1KIDQTUPEbH8ljEr5bw9/pRWVMZyQhzKnyf6udj/tf82ptaeNXtivjHrqAVDo6o4OJTj5OmOLRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774881261; c=relaxed/simple; bh=HEk3URbZ/6THzIJGq7fLcDOYJTGoprphT19QGX3qyP0=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rL3O8zgkevGy/EKOw/QDcQmm+miPnjp6ZrbuwTB6qEHXick9auzmRQwlfM/ivXJ0RwAqWc+jWn+ciyXS7vRN7E3HyiAu+dZdrrYVG7I2dwJtA3jKuiu1PlTcpOrIn0V6lYd/66Tclyie/bzlfDxDvaWqWXCOZtBsiZulllI2OJI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me; spf=pass smtp.mailfrom=pm.me; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b=EErd8ZGb; arc=none smtp.client-ip=185.70.43.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pm.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b="EErd8ZGb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1774881252; x=1775140452; bh=dJUPQVhZMRfdzveegBvIFV3TwRa6qj795ujvLrKLhXQ=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=EErd8ZGbRocHn2SG5ZCZ4M3EQ24YhiS4SycR9Z5VbL1l82+q+1z4q87kOKNowst4y wIRvtLtko3X5UOhVhDyImehgjobhtKIZzvJzmWOuLf7M5BGZxfdioi/NdTA4Seccs+ luhx7121/vJc9Y8kISXvYTT9gzg9xKNfFJXvHs2/U5XOPCEare4mS/vLPelNkMOBWp jDaHjpL/WCTvzp+ScFOarbARYorLXSZSw9ddZ16u7mye3kWPMqP1Aum2tMSfX7rnDx 3Rq0Y4K0O3zllRahntE9Ml+2NSt62zYHOBAM5HRs3v/mvf/uKRuLixnR86OPvT2tbG iIPpeiANLDPMg== Date: Mon, 30 Mar 2026 14:34:07 +0000 To: Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" From: Maciej Wieczor-Retman Cc: m.wieczorretman@pm.me, Maciej Wieczor-Retman , linux-kernel@vger.kernel.org Subject: [PATCH v12 10/15] x86/mm: Reset tags in a canonical address helper call Message-ID: <3611e30bb2776a951a68791b7668ff0ebd903aa1.1774872838.git.m.wieczorretman@pm.me> In-Reply-To: References: Feedback-ID: 164464600:user:proton X-Pm-Message-ID: 40ba4e4f63436a9f3eb1dcb4a2f57b5f44b1ede3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Maciej Wieczor-Retman With KASAN software tag-based mode arbitrary kernel pointers can be tagged. __is_canonical_address() helper can cause issues when met with tagged pointers that expect the loosened canonicality checks. The function itself shouldn't be made LAM-aware since for example in KVM, where it's used extensively - it's not practical to deal with differences between host and guest which might want a different LAM state. Also by the time __is_canonical_address() is invoked KVM has already done any necessary LAM unmasking. Reset the address' tag early in copy_from_kernel_nofault_allowed() so pointer arithmetic checks before a __is_canonical_address() call can work properly. Signed-off-by: Maciej Wieczor-Retman --- Changelog v11: - Reset tag earlier in copy_from_kernel_nofault_allowed() so the is_vsyscall_vaddr() can properly check tagged pointers. - Redo the patch message. Changelog v9: - Redo the patch to not break KVM. - Remove Alexander's acked-by tag. Changelog v7: - Add Alexander's acked-by tag. - Add parentheses around vaddr_bits as suggested by checkpatch. - Apply the bitmasks to the __canonical_address() function which is used in kvm code. Changelog v6: - Use bitmasks to check both kernel and userspace addresses in the __is_canonical_address() (Dave Hansen and Samuel Holland). Changelog v4: - Add patch to the series. arch/x86/mm/maccess.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/mm/maccess.c b/arch/x86/mm/maccess.c index 42115ac079cf..7d8fa58b61b8 100644 --- a/arch/x86/mm/maccess.c +++ b/arch/x86/mm/maccess.c @@ -9,6 +9,7 @@ bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size) { unsigned long vaddr =3D (unsigned long)unsafe_src; + vaddr =3D __tag_reset(vaddr); =20 /* * Do not allow userspace addresses. This disallows --=20 2.53.0