Skip to content

Commit 716d57c

Browse files
bibo-maogregkh
authored andcommitted
LoongArch: KVM: Add address alignment check in pch_pic register access
commit 538c06e upstream. With pch_pic device, its register is based on MMIO address space, different access size 1/2/4/8 is supported. And base address should be naturally aligned with its access size, here add alignment check in its register access emulation function. Cc: stable@vger.kernel.org Signed-off-by: Bibo Mao <maobibo@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b5b49d3 commit 716d57c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

arch/loongarch/kvm/intc/pch_pic.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ static int kvm_pch_pic_read(struct kvm_vcpu *vcpu,
195195
return -EINVAL;
196196
}
197197

198+
if (addr & (len - 1)) {
199+
kvm_err("%s: pch pic not aligned addr %llx len %d\n", __func__, addr, len);
200+
return -EINVAL;
201+
}
202+
198203
/* statistics of pch pic reading */
199204
vcpu->kvm->stat.pch_pic_read_exits++;
200205
ret = loongarch_pch_pic_read(s, addr, len, val);
@@ -302,6 +307,11 @@ static int kvm_pch_pic_write(struct kvm_vcpu *vcpu,
302307
return -EINVAL;
303308
}
304309

310+
if (addr & (len - 1)) {
311+
kvm_err("%s: pch pic not aligned addr %llx len %d\n", __func__, addr, len);
312+
return -EINVAL;
313+
}
314+
305315
/* statistics of pch pic writing */
306316
vcpu->kvm->stat.pch_pic_write_exits++;
307317
ret = loongarch_pch_pic_write(s, addr, len, val);

0 commit comments

Comments
 (0)