Skip to contentSkip to conversation

KVM: s390: Don't use %pK through debug printing or tracepoints

PATCH In review Thomas Weißschuh 4 participants 8 messages Feb 17, 2025 – Nov 23

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover KVM: s390: Don't use %pK through debug printing or tracepoints

Restricted pointers ("%pK") are only meant to be used when directly printing to a file from task context.
Otherwise it can unintentionally expose security sensitive, raw pointer values.

Use regular pointer formatting instead.

---
Thomas Weißschuh (2):
KVM: s390: Don't use %pK through tracepoints
KVM: s390: Don't use %pK through debug printing

 arch/s390/kvm/intercept.c  |  2 +-
 arch/s390/kvm/interrupt.c  |  8 ++++----
 arch/s390/kvm/kvm-s390.c   | 10 +++++-----
 arch/s390/kvm/trace-s390.h |  4 ++--
 4 files changed, 12 insertions(+), 12 deletions(-)

---
base-commit: 0ad2507d5d93f39619fc42372c347d6006b64319
change-id: 20250217-restricted-pointers-s390-3e93b67a9996

Best regards,

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

PATCH 1/2 KVM: s390: Don't use %pK through tracepoints

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

Use regular pointer formatting instead.

---
 arch/s390/kvm/trace-s390.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/s390/kvm/trace-s390.h +2 -2
index 9ac92dbf680dbbe7703dd63945968b1cda46cf13..9e28f165c114caab99857ed3b53edc6ed5045dfa 100644
@@ -56,7 +56,7 @@ TRACE_EVENT(kvm_s390_create_vcpu,
 		    __entry->sie_block = sie_block;
 		    ),
 
-	    TP_printk("create cpu %d at 0x%pK, sie block at 0x%pK",
+	    TP_printk("create cpu %d at 0x%p, sie block at 0x%p",
 		      __entry->id, __entry->vcpu, __entry->sie_block)
 	);
 
@@ -255,7 +255,7 @@ TRACE_EVENT(kvm_s390_enable_css,
 		    __entry->kvm = kvm;
 		    ),
 
-	    TP_printk("enabling channel I/O support (kvm @ %pK)\n",
+	    TP_printk("enabling channel I/O support (kvm @ %p)\n",
 		      __entry->kvm)
 	);
 
Signature · 1 line
2.48.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] KVM: s390: Don't use %pK through tracepoints

Quoted 7 lines · Thomas Weißschuh

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

Use regular pointer formatting instead.

Quoted 27 lines
---
  arch/s390/kvm/trace-s390.h | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/s390/kvm/trace-s390.h +2 -2
index 9ac92dbf680dbbe7703dd63945968b1cda46cf13..9e28f165c114caab99857ed3b53edc6ed5045dfa 100644
@@ -56,7 +56,7 @@ TRACE_EVENT(kvm_s390_create_vcpu,
  		    __entry->sie_block = sie_block;
  		    ),
 
-	    TP_printk("create cpu %d at 0x%pK, sie block at 0x%pK",
+	    TP_printk("create cpu %d at 0x%p, sie block at 0x%p",
  		      __entry->id, __entry->vcpu, __entry->sie_block)
  	);
 
@@ -255,7 +255,7 @@ TRACE_EVENT(kvm_s390_enable_css,
  		    __entry->kvm = kvm;
  		    ),
 
-	    TP_printk("enabling channel I/O support (kvm @ %pK)\n",
+	    TP_printk("enabling channel I/O support (kvm @ %p)\n",
  		      __entry->kvm)
  	);
 
#3 lore raw

PATCH 2/2 KVM: s390: Don't use %pK through debug printing

In reply to Thomas Weißschuh

Restricted pointers ("%pK") are only meant to be used when directly printing to a file from task context.
Otherwise it can unintentionally expose security sensitive, raw pointer values.

Use regular pointer formatting instead.

---
 arch/s390/kvm/intercept.c |  2 +-
 arch/s390/kvm/interrupt.c |  8 ++++----
 arch/s390/kvm/kvm-s390.c  | 10 +++++-----
 3 files changed, 10 insertions(+), 10 deletions(-)
arch/s390/kvm/intercept.c +1 -1
index 610dd44a948b22945b0a35b760ded64bd44ef7cb..a06a000f196ce0066bfd21b0d914492a1796819a 100644
@@ -95,7 +95,7 @@ static int handle_validity(struct kvm_vcpu *vcpu)
 
 	vcpu->stat.exit_validity++;
 	trace_kvm_s390_intercept_validity(vcpu, viwhy);
-	KVM_EVENT(3, "validity intercept 0x%x for pid %u (kvm 0x%pK)", viwhy,
+	KVM_EVENT(3, "validity intercept 0x%x for pid %u (kvm 0x%p)", viwhy,
 		  current->pid, vcpu->kvm);
 
 	/* do not warn on invalid runtime instrumentation mode */
arch/s390/kvm/interrupt.c +4 -4
index 07ff0e10cb7f5c0294bf85f1d65d1eb124698705..c0558f05400732b2fe6911c1ef58f86b62364770 100644
@@ -3161,7 +3161,7 @@ void kvm_s390_gisa_clear(struct kvm *kvm)
 	if (!gi->origin)
 		return;
 	gisa_clear_ipm(gi->origin);
-	VM_EVENT(kvm, 3, "gisa 0x%pK cleared", gi->origin);
+	VM_EVENT(kvm, 3, "gisa 0x%p cleared", gi->origin);
 }
 
 void kvm_s390_gisa_init(struct kvm *kvm)
@@ -3178,7 +3178,7 @@ void kvm_s390_gisa_init(struct kvm *kvm)
 	gi->timer.function = gisa_vcpu_kicker;
 	memset(gi->origin, 0, sizeof(struct kvm_s390_gisa));
 	gi->origin->next_alert = (u32)virt_to_phys(gi->origin);
-	VM_EVENT(kvm, 3, "gisa 0x%pK initialized", gi->origin);
+	VM_EVENT(kvm, 3, "gisa 0x%p initialized", gi->origin);
 }
 
 void kvm_s390_gisa_enable(struct kvm *kvm)
@@ -3219,7 +3219,7 @@ void kvm_s390_gisa_destroy(struct kvm *kvm)
 		process_gib_alert_list();
 	hrtimer_cancel(&gi->timer);
 	gi->origin = NULL;
-	VM_EVENT(kvm, 3, "gisa 0x%pK destroyed", gisa);
+	VM_EVENT(kvm, 3, "gisa 0x%p destroyed", gisa);
 }
 
 void kvm_s390_gisa_disable(struct kvm *kvm)
@@ -3468,7 +3468,7 @@ int __init kvm_s390_gib_init(u8 nisc)
 		}
 	}
 
-	KVM_EVENT(3, "gib 0x%pK (nisc=%d) initialized", gib, gib->nisc);
+	KVM_EVENT(3, "gib 0x%p (nisc=%d) initialized", gib, gib->nisc);
 	goto out;
 
 out_unreg_gal:
arch/s390/kvm/kvm-s390.c +5 -5
index ebecb96bacce7d75563bd3a130a7cc31869dc254..9e427ba3aed42edf617d6625b5bcaba8f43dc464 100644
@@ -1020,7 +1020,7 @@ static int kvm_s390_set_mem_control(struct kvm *kvm, struct kvm_device_attr *att
 		}
 		mutex_unlock(&kvm->lock);
 		VM_EVENT(kvm, 3, "SET: max guest address: %lu", new_limit);
-		VM_EVENT(kvm, 3, "New guest asce: 0x%pK",
+		VM_EVENT(kvm, 3, "New guest asce: 0x%p",
 			 (void *) kvm->arch.gmap->asce);
 		break;
 	}
@@ -3464,7 +3464,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
 		kvm_s390_gisa_init(kvm);
 	INIT_LIST_HEAD(&kvm->arch.pv.need_cleanup);
 	kvm->arch.pv.set_aside = NULL;
-	KVM_EVENT(3, "vm 0x%pK created by pid %u", kvm, current->pid);
+	KVM_EVENT(3, "vm 0x%p created by pid %u", kvm, current->pid);
 
 	return 0;
 out_err:
@@ -3527,7 +3527,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
 	kvm_s390_destroy_adapters(kvm);
 	kvm_s390_clear_float_irqs(kvm);
 	kvm_s390_vsie_destroy(kvm);
-	KVM_EVENT(3, "vm 0x%pK destroyed", kvm);
+	KVM_EVENT(3, "vm 0x%p destroyed", kvm);
 }
 
 /* Section: vcpu related */
@@ -3648,7 +3648,7 @@ static int sca_switch_to_extended(struct kvm *kvm)
 
 	free_page((unsigned long)old_sca);
 
-	VM_EVENT(kvm, 2, "Switched to ESCA (0x%pK -> 0x%pK)",
+	VM_EVENT(kvm, 2, "Switched to ESCA (0x%p -> 0x%p)",
 		 old_sca, kvm->arch.sca);
 	return 0;
 }
@@ -4025,7 +4025,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
 			goto out_free_sie_block;
 	}
 
-	VM_EVENT(vcpu->kvm, 3, "create cpu %d at 0x%pK, sie block at 0x%pK",
+	VM_EVENT(vcpu->kvm, 3, "create cpu %d at 0x%p, sie block at 0x%p",
 		 vcpu->vcpu_id, vcpu, vcpu->arch.sie_block);
 	trace_kvm_s390_create_vcpu(vcpu->vcpu_id, vcpu, vcpu->arch.sie_block);
 
Signature · 1 line
2.48.1
Reviewed-by Tested-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] KVM: s390: Don't use %pK through debug printing

Quoted 9 lines · Thomas Weißschuh

Restricted pointers ("%pK") are only meant to be used when directly printing to a file from task context.
Otherwise it can unintentionally expose security sensitive, raw pointer values.

Use regular pointer formatting instead.

I sucessfully ran our test suite after applying this patch.

Quoted 109 lines
---
  arch/s390/kvm/intercept.c |  2 +-
  arch/s390/kvm/interrupt.c |  8 ++++----
  arch/s390/kvm/kvm-s390.c  | 10 +++++-----
  3 files changed, 10 insertions(+), 10 deletions(-)
arch/s390/kvm/intercept.c +1 -1
index 610dd44a948b22945b0a35b760ded64bd44ef7cb..a06a000f196ce0066bfd21b0d914492a1796819a 100644
@@ -95,7 +95,7 @@ static int handle_validity(struct kvm_vcpu *vcpu)
 
  	vcpu->stat.exit_validity++;
  	trace_kvm_s390_intercept_validity(vcpu, viwhy);
-	KVM_EVENT(3, "validity intercept 0x%x for pid %u (kvm 0x%pK)", viwhy,
+	KVM_EVENT(3, "validity intercept 0x%x for pid %u (kvm 0x%p)", viwhy,
  		  current->pid, vcpu->kvm);
 
  	/* do not warn on invalid runtime instrumentation mode */
arch/s390/kvm/interrupt.c +4 -4
index 07ff0e10cb7f5c0294bf85f1d65d1eb124698705..c0558f05400732b2fe6911c1ef58f86b62364770 100644
@@ -3161,7 +3161,7 @@ void kvm_s390_gisa_clear(struct kvm *kvm)
  	if (!gi->origin)
  		return;
  	gisa_clear_ipm(gi->origin);
-	VM_EVENT(kvm, 3, "gisa 0x%pK cleared", gi->origin);
+	VM_EVENT(kvm, 3, "gisa 0x%p cleared", gi->origin);
  }
 
  void kvm_s390_gisa_init(struct kvm *kvm)
@@ -3178,7 +3178,7 @@ void kvm_s390_gisa_init(struct kvm *kvm)
  	gi->timer.function = gisa_vcpu_kicker;
  	memset(gi->origin, 0, sizeof(struct kvm_s390_gisa));
  	gi->origin->next_alert = (u32)virt_to_phys(gi->origin);
-	VM_EVENT(kvm, 3, "gisa 0x%pK initialized", gi->origin);
+	VM_EVENT(kvm, 3, "gisa 0x%p initialized", gi->origin);
  }
 
  void kvm_s390_gisa_enable(struct kvm *kvm)
@@ -3219,7 +3219,7 @@ void kvm_s390_gisa_destroy(struct kvm *kvm)
  		process_gib_alert_list();
  	hrtimer_cancel(&gi->timer);
  	gi->origin = NULL;
-	VM_EVENT(kvm, 3, "gisa 0x%pK destroyed", gisa);
+	VM_EVENT(kvm, 3, "gisa 0x%p destroyed", gisa);
  }
 
  void kvm_s390_gisa_disable(struct kvm *kvm)
@@ -3468,7 +3468,7 @@ int __init kvm_s390_gib_init(u8 nisc)
  		}
  	}
 
-	KVM_EVENT(3, "gib 0x%pK (nisc=%d) initialized", gib, gib->nisc);
+	KVM_EVENT(3, "gib 0x%p (nisc=%d) initialized", gib, gib->nisc);
  	goto out;
 
  out_unreg_gal:
arch/s390/kvm/kvm-s390.c +5 -5
index ebecb96bacce7d75563bd3a130a7cc31869dc254..9e427ba3aed42edf617d6625b5bcaba8f43dc464 100644
@@ -1020,7 +1020,7 @@ static int kvm_s390_set_mem_control(struct kvm *kvm, struct kvm_device_attr *att
  		}
  		mutex_unlock(&kvm->lock);
  		VM_EVENT(kvm, 3, "SET: max guest address: %lu", new_limit);
-		VM_EVENT(kvm, 3, "New guest asce: 0x%pK",
+		VM_EVENT(kvm, 3, "New guest asce: 0x%p",
  			 (void *) kvm->arch.gmap->asce);
  		break;
  	}
@@ -3464,7 +3464,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
  		kvm_s390_gisa_init(kvm);
  	INIT_LIST_HEAD(&kvm->arch.pv.need_cleanup);
  	kvm->arch.pv.set_aside = NULL;
-	KVM_EVENT(3, "vm 0x%pK created by pid %u", kvm, current->pid);
+	KVM_EVENT(3, "vm 0x%p created by pid %u", kvm, current->pid);
 
  	return 0;
  out_err:
@@ -3527,7 +3527,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
  	kvm_s390_destroy_adapters(kvm);
  	kvm_s390_clear_float_irqs(kvm);
  	kvm_s390_vsie_destroy(kvm);
-	KVM_EVENT(3, "vm 0x%pK destroyed", kvm);
+	KVM_EVENT(3, "vm 0x%p destroyed", kvm);
  }
 
  /* Section: vcpu related */
@@ -3648,7 +3648,7 @@ static int sca_switch_to_extended(struct kvm *kvm)
 
  	free_page((unsigned long)old_sca);
 
-	VM_EVENT(kvm, 2, "Switched to ESCA (0x%pK -> 0x%pK)",
+	VM_EVENT(kvm, 2, "Switched to ESCA (0x%p -> 0x%p)",
  		 old_sca, kvm->arch.sca);
  	return 0;
  }
@@ -4025,7 +4025,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
  			goto out_free_sie_block;
  	}
 
-	VM_EVENT(vcpu->kvm, 3, "create cpu %d at 0x%pK, sie block at 0x%pK",
+	VM_EVENT(vcpu->kvm, 3, "create cpu %d at 0x%p, sie block at 0x%p",
  		 vcpu->vcpu_id, vcpu, vcpu->arch.sie_block);
  	trace_kvm_s390_create_vcpu(vcpu->vcpu_id, vcpu, vcpu->arch.sie_block);
 
#5 lore raw

Re: [PATCH 2/2] KVM: s390: Don't use %pK through debug printing

In reply to Thomas Weißschuh

Am 17.02.25 um 14:13 schrieb Thomas Weißschuh:

Quoted 9 lines

Restricted pointers ("%pK") are only meant to be used when directly printing to a file from task context.
Otherwise it can unintentionally expose security sensitive, raw pointer values.

Use regular pointer formatting instead.

Just realized that will debugging something, but this change was wrong. The VM_EVENT, KVM_EVENT are not printks, it will rather populate output in debugfs files and this output is populated at read time as the debug feature stores the format string and the value. So %pK was actually the right thing - I think.

Quoted 109 lines
---
  arch/s390/kvm/intercept.c |  2 +-
  arch/s390/kvm/interrupt.c |  8 ++++----
  arch/s390/kvm/kvm-s390.c  | 10 +++++-----
  3 files changed, 10 insertions(+), 10 deletions(-)
arch/s390/kvm/intercept.c +1 -1
index 610dd44a948b22945b0a35b760ded64bd44ef7cb..a06a000f196ce0066bfd21b0d914492a1796819a 100644
@@ -95,7 +95,7 @@ static int handle_validity(struct kvm_vcpu *vcpu)
 
  	vcpu->stat.exit_validity++;
  	trace_kvm_s390_intercept_validity(vcpu, viwhy);
-	KVM_EVENT(3, "validity intercept 0x%x for pid %u (kvm 0x%pK)", viwhy,
+	KVM_EVENT(3, "validity intercept 0x%x for pid %u (kvm 0x%p)", viwhy,
  		  current->pid, vcpu->kvm);
 
  	/* do not warn on invalid runtime instrumentation mode */
arch/s390/kvm/interrupt.c +4 -4
index 07ff0e10cb7f5c0294bf85f1d65d1eb124698705..c0558f05400732b2fe6911c1ef58f86b62364770 100644
@@ -3161,7 +3161,7 @@ void kvm_s390_gisa_clear(struct kvm *kvm)
  	if (!gi->origin)
  		return;
  	gisa_clear_ipm(gi->origin);
-	VM_EVENT(kvm, 3, "gisa 0x%pK cleared", gi->origin);
+	VM_EVENT(kvm, 3, "gisa 0x%p cleared", gi->origin);
  }
 
  void kvm_s390_gisa_init(struct kvm *kvm)
@@ -3178,7 +3178,7 @@ void kvm_s390_gisa_init(struct kvm *kvm)
  	gi->timer.function = gisa_vcpu_kicker;
  	memset(gi->origin, 0, sizeof(struct kvm_s390_gisa));
  	gi->origin->next_alert = (u32)virt_to_phys(gi->origin);
-	VM_EVENT(kvm, 3, "gisa 0x%pK initialized", gi->origin);
+	VM_EVENT(kvm, 3, "gisa 0x%p initialized", gi->origin);
  }
 
  void kvm_s390_gisa_enable(struct kvm *kvm)
@@ -3219,7 +3219,7 @@ void kvm_s390_gisa_destroy(struct kvm *kvm)
  		process_gib_alert_list();
  	hrtimer_cancel(&gi->timer);
  	gi->origin = NULL;
-	VM_EVENT(kvm, 3, "gisa 0x%pK destroyed", gisa);
+	VM_EVENT(kvm, 3, "gisa 0x%p destroyed", gisa);
  }
 
  void kvm_s390_gisa_disable(struct kvm *kvm)
@@ -3468,7 +3468,7 @@ int __init kvm_s390_gib_init(u8 nisc)
  		}
  	}
 
-	KVM_EVENT(3, "gib 0x%pK (nisc=%d) initialized", gib, gib->nisc);
+	KVM_EVENT(3, "gib 0x%p (nisc=%d) initialized", gib, gib->nisc);
  	goto out;
 
  out_unreg_gal:
arch/s390/kvm/kvm-s390.c +5 -5
index ebecb96bacce7d75563bd3a130a7cc31869dc254..9e427ba3aed42edf617d6625b5bcaba8f43dc464 100644
@@ -1020,7 +1020,7 @@ static int kvm_s390_set_mem_control(struct kvm *kvm, struct kvm_device_attr *att
  		}
  		mutex_unlock(&kvm->lock);
  		VM_EVENT(kvm, 3, "SET: max guest address: %lu", new_limit);
-		VM_EVENT(kvm, 3, "New guest asce: 0x%pK",
+		VM_EVENT(kvm, 3, "New guest asce: 0x%p",
  			 (void *) kvm->arch.gmap->asce);
  		break;
  	}
@@ -3464,7 +3464,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
  		kvm_s390_gisa_init(kvm);
  	INIT_LIST_HEAD(&kvm->arch.pv.need_cleanup);
  	kvm->arch.pv.set_aside = NULL;
-	KVM_EVENT(3, "vm 0x%pK created by pid %u", kvm, current->pid);
+	KVM_EVENT(3, "vm 0x%p created by pid %u", kvm, current->pid);
 
  	return 0;
  out_err:
@@ -3527,7 +3527,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
  	kvm_s390_destroy_adapters(kvm);
  	kvm_s390_clear_float_irqs(kvm);
  	kvm_s390_vsie_destroy(kvm);
-	KVM_EVENT(3, "vm 0x%pK destroyed", kvm);
+	KVM_EVENT(3, "vm 0x%p destroyed", kvm);
  }
 
  /* Section: vcpu related */
@@ -3648,7 +3648,7 @@ static int sca_switch_to_extended(struct kvm *kvm)
 
  	free_page((unsigned long)old_sca);
 
-	VM_EVENT(kvm, 2, "Switched to ESCA (0x%pK -> 0x%pK)",
+	VM_EVENT(kvm, 2, "Switched to ESCA (0x%p -> 0x%p)",
  		 old_sca, kvm->arch.sca);
  	return 0;
  }
@@ -4025,7 +4025,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
  			goto out_free_sie_block;
  	}
 
-	VM_EVENT(vcpu->kvm, 3, "create cpu %d at 0x%pK, sie block at 0x%pK",
+	VM_EVENT(vcpu->kvm, 3, "create cpu %d at 0x%p, sie block at 0x%p",
  		 vcpu->vcpu_id, vcpu, vcpu->arch.sie_block);
  	trace_kvm_s390_create_vcpu(vcpu->vcpu_id, vcpu, vcpu->arch.sie_block);
 
#6 lore raw

Re: [PATCH 2/2] KVM: s390: Don't use %pK through debug printing

Quoted 8 lines · Christian Borntraeger

Am 17.02.25 um 14:13 schrieb Thomas Weißschuh:

Quoted 7 lines

Restricted pointers ("%pK") are only meant to be used when directly printing to a file from task context.
Otherwise it can unintentionally expose security sensitive, raw pointer values.

Use regular pointer formatting instead.

Quoted 8 lines
Quoted 2 lines

Just realized that will debugging something, but this change was wrong. The VM_EVENT, KVM_EVENT are not printks, it will rather populate output in debugfs files and this output is populated at read time as the debug feature stores the format string and the value. So %pK was actually the right thing - I think.

Indeed. OTOH %pK is going away completely anyways. So the change should stay.

(...)

maintainer
#7 lore raw
In reply to Thomas Weißschuh
Quoted 5 lines · Thomas Weißschuh

Restricted pointers ("%pK") are only meant to be used when directly printing to a file from task context.
Otherwise it can unintentionally expose security sensitive, raw pointer values.

Use regular pointer formatting instead.

Thanks, picked!