[PW_SID:1062392] RISC-V: KVM: Fix array out-of-bounds in firmware counter reads#1565
[PW_SID:1062392] RISC-V: KVM: Fix array out-of-bounds in firmware counter reads#1565linux-riscv-bot wants to merge 2 commits into
Conversation
When a guest invokes SBI_EXT_PMU_COUNTER_FW_READ on a firmware counter that has not been configured via SBI_EXT_PMU_COUNTER_CFG_MATCH, the pmc->event_idx remains SBI_PMU_EVENT_IDX_INVALID (0xFFFFFFFF). get_event_code() extracts the lower 16 bits, yielding 0xFFFF (65535), which is then used to index into kvpmu->fw_event[]. Since fw_event is only RISCV_KVM_MAX_FW_CTRS (32) entries, this triggers an array-index-out-of-bounds: UBSAN: array-index-out-of-bounds in arch/riscv/kvm/vcpu_pmu.c:255:37 index 65535 is out of range for type 'kvm_fw_event [32]' Add a bounds check on fevent_code before accessing the fw_event array, returning -EINVAL for invalid event codes. Fixes: badc386 ("RISC-V: KVM: Support firmware events") Signed-off-by: Jiakai Xu <xujiakai2025@iscas.ac.cn> Signed-off-by: Jiakai Xu <jiakaiPeanut@gmail.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
pmu_fw_ctr_read_hi() has the same issue as pmu_ctr_read(): when a guest reads a firmware counter that has not been configured, pmc->event_idx is SBI_PMU_EVENT_IDX_INVALID and get_event_code() returns 0xFFFF, causing an out-of-bounds access on kvpmu->fw_event[]. Add the same bounds check on fevent_code before accessing the fw_event array. Fixes: 08fb07d ("RISC-V: KVM: Support 64 bit firmware counters on RV32") Signed-off-by: Jiakai Xu <xujiakai2025@iscas.ac.cn> Signed-off-by: Jiakai Xu <jiakaiPeanut@gmail.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "[1/2] RISC-V: KVM: Fix array out-of-bounds in pmu_ctr_read()" |
|
Patch 1: "[1/2] RISC-V: KVM: Fix array out-of-bounds in pmu_ctr_read()" |
|
Patch 1: "[1/2] RISC-V: KVM: Fix array out-of-bounds in pmu_ctr_read()" |
|
Patch 1: "[1/2] RISC-V: KVM: Fix array out-of-bounds in pmu_ctr_read()" |
|
Patch 1: "[1/2] RISC-V: KVM: Fix array out-of-bounds in pmu_ctr_read()" |
|
Patch 1: "[1/2] RISC-V: KVM: Fix array out-of-bounds in pmu_ctr_read()" |
|
Patch 1: "[1/2] RISC-V: KVM: Fix array out-of-bounds in pmu_ctr_read()" |
|
Patch 1: "[1/2] RISC-V: KVM: Fix array out-of-bounds in pmu_ctr_read()" |
|
Patch 1: "[1/2] RISC-V: KVM: Fix array out-of-bounds in pmu_ctr_read()" |
|
Patch 1: "[1/2] RISC-V: KVM: Fix array out-of-bounds in pmu_ctr_read()" |
|
Patch 1: "[1/2] RISC-V: KVM: Fix array out-of-bounds in pmu_ctr_read()" |
|
Patch 1: "[1/2] RISC-V: KVM: Fix array out-of-bounds in pmu_ctr_read()" |
|
Patch 2: "[2/2] RISC-V: KVM: Fix array out-of-bounds in pmu_fw_ctr_read_hi()" |
|
Patch 2: "[2/2] RISC-V: KVM: Fix array out-of-bounds in pmu_fw_ctr_read_hi()" |
|
Patch 2: "[2/2] RISC-V: KVM: Fix array out-of-bounds in pmu_fw_ctr_read_hi()" |
|
Patch 2: "[2/2] RISC-V: KVM: Fix array out-of-bounds in pmu_fw_ctr_read_hi()" |
|
Patch 2: "[2/2] RISC-V: KVM: Fix array out-of-bounds in pmu_fw_ctr_read_hi()" |
|
Patch 2: "[2/2] RISC-V: KVM: Fix array out-of-bounds in pmu_fw_ctr_read_hi()" |
|
Patch 2: "[2/2] RISC-V: KVM: Fix array out-of-bounds in pmu_fw_ctr_read_hi()" |
|
Patch 2: "[2/2] RISC-V: KVM: Fix array out-of-bounds in pmu_fw_ctr_read_hi()" |
|
Patch 2: "[2/2] RISC-V: KVM: Fix array out-of-bounds in pmu_fw_ctr_read_hi()" |
|
Patch 2: "[2/2] RISC-V: KVM: Fix array out-of-bounds in pmu_fw_ctr_read_hi()" |
|
Patch 2: "[2/2] RISC-V: KVM: Fix array out-of-bounds in pmu_fw_ctr_read_hi()" |
|
Patch 2: "[2/2] RISC-V: KVM: Fix array out-of-bounds in pmu_fw_ctr_read_hi()" |
PR for series 1062392 applied to workflow__riscv__fixes
Name: RISC-V: KVM: Fix array out-of-bounds in firmware counter reads
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1062392
Version: 1