From nobody Sun Apr 5 04:43:31 2026 Received: from mail-10631.protonmail.ch (mail-10631.protonmail.ch [79.135.106.31]) (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 51E503C9434 for ; Tue, 10 Mar 2026 17:54:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.135.106.31 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773165278; cv=none; b=BhXdLRAjy1Zx7CjJGLnn14UQvMtzNn5H1RTl6ftXACE9Mgl2sZMGV3uAVo/y2zAmhGFTKmxBEi0EhfXfBmt65VoOuSgymKLUDhWNFMvjDTu5kb+Kcd8HYS3YGgvLG9esOc6tD6NlcwSQOUFqMZ+gPY0pUCmGiOjE4MWdwtOAkro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773165278; c=relaxed/simple; bh=HEk3URbZ/6THzIJGq7fLcDOYJTGoprphT19QGX3qyP0=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V94PU735yAezjcWVa4gM4k4k3+avIrK3luV5uMluGk+zlGZRrI/tU0WGx1cBimiAjG57kI8zC+sNe2X+AzVajNJjzP+ZozZJOzL9UDOtNxYGnpg0i/5FbuwfeMMRvfQYO3Hk33MhNUOiHh+oklxoLf1JKPAhNOwsdTkvAPkRfUg= 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=XMswb6H/; arc=none smtp.client-ip=79.135.106.31 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="XMswb6H/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1773165275; x=1773424475; 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=XMswb6H/xTsm2H7K6hvQfCbWwL7EgpBZ+/8GskZ9viHDLdz7cq36jJpgj9mfxjzz6 0uugYLxoT1T8psI53aMt7JjfrXB7yKukq3cWdRoyE2rd4xKUHwsIkFyNk+MHS3SF5j sJSVRNxNWt0gip0FqBNJ7Qhg4QOAXm/p3buKYmahm2X95QU0ciVENWziXG+4mmkE7a yFG94KmjYVxwNw54INZXLQLJ/AdxVQIVZrgwwQH5eHCdfs6zNvkmw4h51eN8ClHOF+ WYrqUflMBcEX/wXPW3W9v3wl5fCQxfzU2+0b0Rvb965B6reC71aVG//hfu2Vb1xf0z W0sIDI6Eo8RnQ== Date: Tue, 10 Mar 2026 17:54:31 +0000 To: akpm@linux-foundation.org, 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 v11 10/15] x86/mm: Reset tags in a canonical address helper call Message-ID: In-Reply-To: References: Feedback-ID: 164464600:user:proton X-Pm-Message-ID: ef56dda76c5004d38bc6843ff4498539a79960e1 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