Skip to contentSkip to conversation

arm64: mm: Don't use %pK through printk

PATCH Applied Thomas Weißschuh 3 participants 5 messages Feb 17, 2025 – Mar 20, 2025 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: mm: Don't use %pK through printk

Restricted pointers ("%pK") are not meant to be used through printk(). It can unintentionally expose security sensitive, raw pointer values.

Use regular pointer formatting instead.

---
 arch/arm64/mm/physaddr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/physaddr.c +1 -1
index cde44c13dda1bc0924d2d50369ad87f544a0a802..7d94e09b01b35094e883875a46b979666549095c 100644
@@ -10,7 +10,7 @@
 phys_addr_t __virt_to_phys(unsigned long x)
 {
 	WARN(!__is_lm_address(__tag_reset(x)),
-	     "virt_to_phys used for non-linear address: %pK (%pS)\n",
+	     "virt_to_phys used for non-linear address: %p (%pS)\n",
 	      (void *)x,
 	      (void *)x);
 

---
base-commit: 0ad2507d5d93f39619fc42372c347d6006b64319
change-id: 20250217-restricted-pointers-arm64-74d54aef13f7

Best regards,

Signature · 1 line
Thomas Weißschuh <[email protected]>
maintainer
#1 lore raw
Quoted 16 lines · Thomas Weißschuh

Restricted pointers ("%pK") are not meant to be used through printk(). It can unintentionally expose security sensitive, raw pointer values.

Use regular pointer formatting instead.

---
 arch/arm64/mm/physaddr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/mm/physaddr.c +0 -0
index cde44c13dda1bc0924d2d50369ad87f544a0a802..7d94e09b01b35094e883875a46b979666549095c 100644

arch/arm64/mm/physaddr.c line 15

Quoted 7 lines
arch/arm64/mm/physaddr.c +1 -1
@@ -10,7 +10,7 @@
 phys_addr_t __virt_to_phys(unsigned long x)
 {
 	WARN(!__is_lm_address(__tag_reset(x)),
-	     "virt_to_phys used for non-linear address: %pK (%pS)\n",
+	     "virt_to_phys used for non-linear address: %p (%pS)\n",
 	      (void *)x,
 	      (void *)x);

This is part of a WARN() and knowing the actual address may well be useful in debugging. I suspect it also ends up being dumped as part of the register dump _anyway_.

Will

#2 lore raw
Quoted 12 lines · Will Deacon
Quoted 11 lines · Thomas Weißschuh

Restricted pointers ("%pK") are not meant to be used through printk(). It can unintentionally expose security sensitive, raw pointer values.

Use regular pointer formatting instead.

---
 arch/arm64/mm/physaddr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

arch/arm64/mm/physaddr.c line 15

Quoted 12 lines
arch/arm64/mm/physaddr.c +1 -1
index cde44c13dda1bc0924d2d50369ad87f544a0a802..7d94e09b01b35094e883875a46b979666549095c 100644
@@ -10,7 +10,7 @@
 phys_addr_t __virt_to_phys(unsigned long x)
 {
 	WARN(!__is_lm_address(__tag_reset(x)),
-	     "virt_to_phys used for non-linear address: %pK (%pS)\n",
+	     "virt_to_phys used for non-linear address: %p (%pS)\n",
 	      (void *)x,
 	      (void *)x);

This is part of a WARN() and knowing the actual address may well be useful in debugging. I suspect it also ends up being dumped as part of the register dump _anyway_.

That makes sense, especially the value being part of the register dump. OTOH in the default kernel configuration (kptr_restrict==0), %pK is an alias to %p and also hashing the pointers. And so far nobody seems to have cared.

If you prefer I can also change it to %px, to specifically show the value. My main goal is to remove %pK, as it's prone to misuse.

Thomas

maintainer
#3 lore raw
Quoted 30 lines · Thomas Weißschuh
Quoted 12 lines · Will Deacon
Quoted 11 lines · Thomas Weißschuh

Restricted pointers ("%pK") are not meant to be used through printk(). It can unintentionally expose security sensitive, raw pointer values.

Use regular pointer formatting instead.

---
 arch/arm64/mm/physaddr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

arch/arm64/mm/physaddr.c line 15

Quoted 12 lines
arch/arm64/mm/physaddr.c +1 -1
index cde44c13dda1bc0924d2d50369ad87f544a0a802..7d94e09b01b35094e883875a46b979666549095c 100644
@@ -10,7 +10,7 @@
 phys_addr_t __virt_to_phys(unsigned long x)
 {
 	WARN(!__is_lm_address(__tag_reset(x)),
-	     "virt_to_phys used for non-linear address: %pK (%pS)\n",
+	     "virt_to_phys used for non-linear address: %p (%pS)\n",
 	      (void *)x,
 	      (void *)x);

This is part of a WARN() and knowing the actual address may well be useful in debugging. I suspect it also ends up being dumped as part of the register dump _anyway_.

Quoted 6 lines

That makes sense, especially the value being part of the register dump. OTOH in the default kernel configuration (kptr_restrict==0), %pK is an alias to %p and also hashing the pointers. And so far nobody seems to have cared.

If you prefer I can also change it to %px, to specifically show the value. My main goal is to remove %pK, as it's prone to misuse.

Probably best to ignore me, then, and keep the existing behaviour with your change (as your patch is doing).

Thanks,

Will