lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <462dc78d4d986007e82c12ad57bb6b11f85b19a1.1756151769.git.maciej.wieczor-retman@intel.com>
Date: Mon, 25 Aug 2025 22:24:31 +0200
From: Maciej Wieczor-Retman <maciej.wieczor-retman@...el.com>
To: sohil.mehta@...el.com,
	baohua@...nel.org,
	david@...hat.com,
	kbingham@...nel.org,
	weixugc@...gle.com,
	Liam.Howlett@...cle.com,
	alexandre.chartre@...cle.com,
	kas@...nel.org,
	mark.rutland@....com,
	trintaeoitogc@...il.com,
	axelrasmussen@...gle.com,
	yuanchu@...gle.com,
	joey.gouly@....com,
	samitolvanen@...gle.com,
	joel.granados@...nel.org,
	graf@...zon.com,
	vincenzo.frascino@....com,
	kees@...nel.org,
	ardb@...nel.org,
	thiago.bauermann@...aro.org,
	glider@...gle.com,
	thuth@...hat.com,
	kuan-ying.lee@...onical.com,
	pasha.tatashin@...een.com,
	nick.desaulniers+lkml@...il.com,
	vbabka@...e.cz,
	kaleshsingh@...gle.com,
	justinstitt@...gle.com,
	catalin.marinas@....com,
	alexander.shishkin@...ux.intel.com,
	samuel.holland@...ive.com,
	dave.hansen@...ux.intel.com,
	corbet@....net,
	xin@...or.com,
	dvyukov@...gle.com,
	tglx@...utronix.de,
	scott@...amperecomputing.com,
	jason.andryuk@....com,
	morbo@...gle.com,
	nathan@...nel.org,
	lorenzo.stoakes@...cle.com,
	mingo@...hat.com,
	brgerst@...il.com,
	kristina.martsenko@....com,
	bigeasy@...utronix.de,
	luto@...nel.org,
	jgross@...e.com,
	jpoimboe@...nel.org,
	urezki@...il.com,
	mhocko@...e.com,
	ada.coupriediaz@....com,
	hpa@...or.com,
	maciej.wieczor-retman@...el.com,
	leitao@...ian.org,
	peterz@...radead.org,
	wangkefeng.wang@...wei.com,
	surenb@...gle.com,
	ziy@...dia.com,
	smostafa@...gle.com,
	ryabinin.a.a@...il.com,
	ubizjak@...il.com,
	jbohac@...e.cz,
	broonie@...nel.org,
	akpm@...ux-foundation.org,
	guoweikang.kernel@...il.com,
	rppt@...nel.org,
	pcc@...gle.com,
	jan.kiszka@...mens.com,
	nicolas.schier@...ux.dev,
	will@...nel.org,
	andreyknvl@...il.com,
	jhubbard@...dia.com,
	bp@...en8.de
Cc: x86@...nel.org,
	linux-doc@...r.kernel.org,
	linux-mm@...ck.org,
	llvm@...ts.linux.dev,
	linux-kbuild@...r.kernel.org,
	kasan-dev@...glegroups.com,
	linux-kernel@...r.kernel.org,
	linux-arm-kernel@...ts.infradead.org
Subject: [PATCH v5 06/19] x86: Reset tag for virtual to physical address conversions

Any place where pointer arithmetic is used to convert a virtual address
into a physical one can raise errors if the virtual address is tagged.

Reset the pointer's tag by sign extending the tag bits in macros that do
pointer arithmetic in address conversions. There will be no change in
compiled code with KASAN disabled since the compiler will optimize the
__tag_reset() out.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@...el.com>
---
Changelog v5:
- Move __tag_reset() calls into __phys_addr_nodebug() and
  __virt_addr_valid() instead of calling it on the arguments of higher
  level functions.

Changelog v4:
- Simplify page_to_virt() by removing pointless casts.
- Remove change in __is_canonical_address() because it's taken care of
  in a later patch due to a LAM compatible definition of canonical.

 arch/x86/include/asm/page.h    | 8 ++++++++
 arch/x86/include/asm/page_64.h | 1 +
 arch/x86/mm/physaddr.c         | 2 ++
 3 files changed, 11 insertions(+)

diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
index 9265f2fca99a..bcf5cad3da36 100644
--- a/arch/x86/include/asm/page.h
+++ b/arch/x86/include/asm/page.h
@@ -7,6 +7,7 @@
 #ifdef __KERNEL__
 
 #include <asm/page_types.h>
+#include <asm/kasan.h>
 
 #ifdef CONFIG_X86_64
 #include <asm/page_64.h>
@@ -65,6 +66,13 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
  * virt_to_page(kaddr) returns a valid pointer if and only if
  * virt_addr_valid(kaddr) returns true.
  */
+
+#ifdef CONFIG_KASAN_SW_TAGS
+#define page_to_virt(x) ({							\
+	void *__addr = __va(page_to_pfn((struct page *)x) << PAGE_SHIFT);	\
+	__tag_set(__addr, page_kasan_tag(x));					\
+})
+#endif
 #define virt_to_page(kaddr)	pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
 extern bool __virt_addr_valid(unsigned long kaddr);
 #define virt_addr_valid(kaddr)	__virt_addr_valid((unsigned long) (kaddr))
diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
index 015d23f3e01f..b18fef43dd34 100644
--- a/arch/x86/include/asm/page_64.h
+++ b/arch/x86/include/asm/page_64.h
@@ -21,6 +21,7 @@ extern unsigned long direct_map_physmem_end;
 
 static __always_inline unsigned long __phys_addr_nodebug(unsigned long x)
 {
+	x = __tag_reset(x);
 	unsigned long y = x - __START_KERNEL_map;
 
 	/* use the carry flag to determine if x was < __START_KERNEL_map */
diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
index fc3f3d3e2ef2..d6aa3589c798 100644
--- a/arch/x86/mm/physaddr.c
+++ b/arch/x86/mm/physaddr.c
@@ -14,6 +14,7 @@
 #ifdef CONFIG_DEBUG_VIRTUAL
 unsigned long __phys_addr(unsigned long x)
 {
+	x = __tag_reset(x);
 	unsigned long y = x - __START_KERNEL_map;
 
 	/* use the carry flag to determine if x was < __START_KERNEL_map */
@@ -46,6 +47,7 @@ EXPORT_SYMBOL(__phys_addr_symbol);
 
 bool __virt_addr_valid(unsigned long x)
 {
+	x = __tag_reset(x);
 	unsigned long y = x - __START_KERNEL_map;
 
 	/* use the carry flag to determine if x was < __START_KERNEL_map */
-- 
2.50.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ