Skip to content

Commit 00d5101

Browse files
Alexandru EliseiMarc Zyngier
authored andcommitted
KVM: arm64: Return early from read_id_reg() if register is RAZ
If read_id_reg() is called for an ID register which is Read-As-Zero (RAZ), it initializes the return value to zero, then goes through a list of registers which require special handling before returning the final value. By not returning as soon as it checks that the register should be RAZ, the function creates the opportunity for bugs, if, for example, a patch changes a register to RAZ (like has happened with PMSWINC_EL0 in commit 1166311), but doesn't remove the special handling from read_id_reg(); or if a register is RAZ in certain situations, but readable in others. Return early to make it impossible for a RAZ register to be anything other than zero. Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Alexandru Elisei <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9e1ff30 commit 00d5101

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

arch/arm64/kvm/sys_regs.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,12 @@ static u64 read_id_reg(const struct kvm_vcpu *vcpu,
10641064
struct sys_reg_desc const *r, bool raz)
10651065
{
10661066
u32 id = reg_to_encoding(r);
1067-
u64 val = raz ? 0 : read_sanitised_ftr_reg(id);
1067+
u64 val;
1068+
1069+
if (raz)
1070+
return 0;
1071+
1072+
val = read_sanitised_ftr_reg(id);
10681073

10691074
switch (id) {
10701075
case SYS_ID_AA64PFR0_EL1:

0 commit comments

Comments
 (0)