Skip to contentSkip to conversation

KVM: arm64: Ensure 'params' is initialised when looking up sys register

PATCH Applied Will Deacon 2 participants 2 messages Dec 12, 2019

Subsystems (3)
lore
Share & tools
lore

Will Deacon

author maintainer
#0 lore raw

PATCH 1/1 KVM: arm64: Ensure 'params' is initialised when looking up sys register

Commit 4b927b94d5df ("KVM: arm/arm64: vgic: Introduce find_reg_by_id()") introduced 'find_reg_by_id()', which looks up a system register only if the 'id' index parameter identifies a valid system register. As part of the patch, existing callers of 'find_reg()' were ported over to the new interface, but this breaks 'index_to_sys_reg_desc()' in the case that the initial lookup in the vCPU target table fails because we will then call into 'find_reg()' for the system register table with an uninitialised 'param' as the key to the lookup.

GCC 10 is bright enough to spot this (amongst a tonne of false positives, but hey!):

  | arch/arm64/kvm/sys_regs.c: In function ‘index_to_sys_reg_desc.part.0.isra’:
  | arch/arm64/kvm/sys_regs.c:983:33: warning: ‘params.Op2’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  |   983 |   (u32)(x)->CRn, (u32)(x)->CRm, (u32)(x)->Op2);
  | [...]

Revert the hunk of 4b927b94d5df which breaks 'index_to_sys_reg_desc()' so that the old behaviour of checking the index upfront is restored.

Cc Marc Zyngier <[email protected]>
Cc Vijaya Kumar K <[email protected]>
Fixes 4b927b94d5df ("KVM: arm/arm64: vgic: Introduce find_reg_by_id()")
---
 arch/arm64/kvm/sys_regs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm64/kvm/sys_regs.c +4 -1
index 46822afc57e0..01a515e0171e 100644
@@ -2360,8 +2360,11 @@ static const struct sys_reg_desc *index_to_sys_reg_desc(struct kvm_vcpu *vcpu,
 	if ((id & KVM_REG_ARM_COPROC_MASK) != KVM_REG_ARM64_SYSREG)
 		return NULL;
 
+	if (!index_to_params(id, &params))
+		return NULL;
+
 	table = get_target_table(vcpu->arch.target, true, &num);
-	r = find_reg_by_id(id, &params, table, num);
+	r = find_reg(&params, table, num);
 	if (!r)
 		r = find_reg(&params, sys_reg_descs, ARRAY_SIZE(sys_reg_descs));
 
Signature · 1 line
2.24.1.735.g03f4e72817-goog
maintainer Applied
#1 lore raw
Quoted 16 lines · Will Deacon

Commit 4b927b94d5df ("KVM: arm/arm64: vgic: Introduce find_reg_by_id()") introduced 'find_reg_by_id()', which looks up a system register only if the 'id' index parameter identifies a valid system register. As part of the patch, existing callers of 'find_reg()' were ported over to the new interface, but this breaks 'index_to_sys_reg_desc()' in the case that the initial lookup in the vCPU target table fails because we will then call into 'find_reg()' for the system register table with an uninitialised 'param' as the key to the lookup.

GCC 10 is bright enough to spot this (amongst a tonne of false positives, but hey!):

| arch/arm64/kvm/sys_regs.c: In function
‘index_to_sys_reg_desc.part.0.isra’:
| arch/arm64/kvm/sys_regs.c:983:33: warning: ‘params.Op2’ may be
used uninitialized in this function [-Wmaybe-uninitialized]

Quoted 5 lines
  |   983 |   (u32)(x)->CRn, (u32)(x)->CRm, (u32)(x)->Op2);
  | [...]

Revert the hunk of 4b927b94d5df which breaks 'index_to_sys_reg_desc()' so that the old behaviour of checking the index upfront is restored.

Huhuh... Well spotted GCC 10! And thanks Will for the fix.

Quoted 17 lines
Cc Marc Zyngier <[email protected]>
Cc Vijaya Kumar K <[email protected]>
Fixes 4b927b94d5df ("KVM: arm/arm64: vgic: Introduce find_reg_by_id()")
---
 arch/arm64/kvm/sys_regs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm64/kvm/sys_regs.c +0 -0
index 46822afc57e0..01a515e0171e 100644
@@ -2360,8 +2360,11 @@ static const struct sys_reg_desc
 *index_to_sys_reg_desc(struct kvm_vcpu *vcpu,
 	if ((id & KVM_REG_ARM_COPROC_MASK) != KVM_REG_ARM64_SYSREG)

arch/arm64/kvm/sys_regs.c static const struct sys_reg_desc · line 2370

Quoted 10 lines
arch/arm64/kvm/sys_regs.c +4 -1
 		return NULL;
 
+	if (!index_to_params(id, &params))
+		return NULL;
+
 	table = get_target_table(vcpu->arch.target, true, &num);
-	r = find_reg_by_id(id, &params, table, num);
+	r = find_reg(&params, table, num);
 	if (!r)
 		r = find_reg(&params, sys_reg_descs, ARRAY_SIZE(sys_reg_descs));

Applied, thanks.

        M.
Signature · 5 lines
Jazz is not dead. It just smells funny...
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm