Skip to contentSkip to conversation

arm64: mm: reset address tag set by kasan sw tagging

PATCH Applied Shyam Thombre 3 participants 4 messages Jun 10, 2020 – Jun 15, 2020 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: mm: reset address tag set by kasan sw tagging

KASAN sw tagging sets a random tag of 8 bits in the top byte of the pointer returned by the memory allocating functions. So for the functions unaware of this change, the top 8 bits of the address must be reset which is done by the function arch_kasan_reset_tag().

---
 arch/arm64/mm/mmu.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/mm/mmu.c +1 -0
index e7fbc62..eae7655 100644
@@ -723,6 +723,7 @@ int kern_addr_valid(unsigned long addr)
 	pmd_t *pmdp, pmd;
 	pte_t *ptep, pte;
 
+	addr = arch_kasan_reset_tag(addr);
 	if ((((long)addr) >> VA_BITS) != -1UL)
 		return 0;
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer
#1 lore raw
Quoted 15 lines · Shyam Thombre

KASAN sw tagging sets a random tag of 8 bits in the top byte of the pointer returned by the memory allocating functions. So for the functions unaware of this change, the top 8 bits of the address must be reset which is done by the function arch_kasan_reset_tag().

---
 arch/arm64/mm/mmu.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/mm/mmu.c +0 -0
index e7fbc62..eae7655 100644

arch/arm64/mm/mmu.c int kern_addr_valid(unsigned long addr) · line 728

Quoted 6 lines
arch/arm64/mm/mmu.c +1 -0
@@ -723,6 +723,7 @@ int kern_addr_valid(unsigned long addr)
 	pmd_t *pmdp, pmd;
 	pte_t *ptep, pte;
 
+	addr = arch_kasan_reset_tag(addr);
 	if ((((long)addr) >> VA_BITS) != -1UL)
 		return 0;

It would be interesting to know what fails without this patch. The only user seems to be read_kcore() and, at a quick look, I don't see how it can generate tagged addresses.

Signature · 6 lines
Catalin

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#2 lore raw

Hi Catalin,

Quoted 19 lines · Catalin Marinas
Quoted 18 lines · Shyam Thombre

KASAN sw tagging sets a random tag of 8 bits in the top byte of the pointer returned by the memory allocating functions. So for the functions unaware of this change, the top 8 bits of the address must be reset which is done by the function arch_kasan_reset_tag().

---
  arch/arm64/mm/mmu.c | 1 +
  1 file changed, 1 insertion(+)
arch/arm64/mm/mmu.c +0 -0
index e7fbc62..eae7655 100644
@@ -723,6 +723,7 @@ int kern_addr_valid(unsigned long addr)
  	pmd_t *pmdp, pmd;
  	pte_t *ptep, pte;
 
Quoted 8 lines

arch/arm64/mm/mmu.c int kern_addr_valid(unsigned long addr) · line 728

Quoted 3 lines
arch/arm64/mm/mmu.c +1 -0
+	addr = arch_kasan_reset_tag(addr);
  	if ((((long)addr) >> VA_BITS) != -1UL)
  		return 0;

It would be interesting to know what fails without this patch. The only user seems to be read_kcore() and, at a quick look, I don't see how it can generate tagged addresses.

This issue is seen in downstream GPU drivers. It currently doesn't look to impact any upstream users.

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer Applied
#3 lore raw
In reply to Shyam Thombre
Quoted 4 lines · Shyam Thombre

KASAN sw tagging sets a random tag of 8 bits in the top byte of the pointer returned by the memory allocating functions. So for the functions unaware of this change, the top 8 bits of the address must be reset which is done by the function arch_kasan_reset_tag().

Applied to arm64 (for-next/fixes), thanks!

[1/1] arm64: mm: reset address tag set by kasan sw tagging

      https://git.kernel.org/arm64/c/8dd4daa04278

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev