[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <1563366019-31200-1-git-send-email-yuzenghui@huawei.com>
Date: Wed, 17 Jul 2019 12:20:19 +0000
From: Zenghui Yu <yuzenghui@...wei.com>
To: <maz@...nel.org>, <kvmarm@...ts.cs.columbia.edu>,
<linux-arm-kernel@...ts.infradead.org>
CC: <marc.zyngier@....com>, <james.morse@....com>,
<julien.thierry@....com>, <suzuki.poulose@....com>,
<julien.thierry.kdev@...il.com>, <linux-kernel@...r.kernel.org>,
<wanghaibin.wang@...wei.com>, <andrew.murray@....com>,
Zenghui Yu <yuzenghui@...wei.com>
Subject: [PATCH] KVM: arm/arm64: Assign pmc->idx before kvm_pmu_stop_counter()
We use "pmc->idx" and the "chained" bitmap to determine if the pmc is
chained, in kvm_pmu_pmc_is_chained(). But idx might be uninitialized
(and random) when we doing this decision, through a KVM_ARM_VCPU_INIT
ioctl -> kvm_pmu_vcpu_reset(). And the test_bit() against this random
idx will potentially hit a KASAN BUG [1].
Fix it by moving the assignment of idx before kvm_pmu_stop_counter().
[1] https://www.spinics.net/lists/kvm-arm/msg36700.html
Fixes: 80f393a23be6 ("KVM: arm/arm64: Support chained PMU counters")
Suggested-by: Andrew Murray <andrew.murray@....com>
Cc: Marc Zyngier <maz@...nel.org>
Signed-off-by: Zenghui Yu <yuzenghui@...wei.com>
---
virt/kvm/arm/pmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/virt/kvm/arm/pmu.c b/virt/kvm/arm/pmu.c
index 3dd8238..521bfdd 100644
--- a/virt/kvm/arm/pmu.c
+++ b/virt/kvm/arm/pmu.c
@@ -225,8 +225,8 @@ void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu)
struct kvm_pmu *pmu = &vcpu->arch.pmu;
for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++) {
- kvm_pmu_stop_counter(vcpu, &pmu->pmc[i]);
pmu->pmc[i].idx = i;
+ kvm_pmu_stop_counter(vcpu, &pmu->pmc[i]);
}
bitmap_zero(vcpu->arch.pmu.chained, ARMV8_PMU_MAX_COUNTER_PAIRS);
--
1.8.3.1
Powered by blists - more mailing lists