mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-08-07 11:14:53 +00:00
HV: instr_emul: Return -EINVAL if inst_len equals 0
inst_len with 0 length should be treated as invaild value. This patch move 0 length check to the begainning of the function and return -EINVAL if inst_len == 0. Tracked-On: ccm0001001-247210 Signed-off-by: Kaige Fu <kaige.fu@intel.com>
This commit is contained in:
parent
a0fbb2da8c
commit
688b0cdb9c
@ -1682,9 +1682,13 @@ vie_calculate_gla(enum vm_cpu_mode cpu_mode, enum cpu_reg_name seg,
|
|||||||
int
|
int
|
||||||
vie_init(struct vie *vie, struct vcpu *vcpu)
|
vie_init(struct vie *vie, struct vcpu *vcpu)
|
||||||
{
|
{
|
||||||
|
uint64_t guest_rip_gva =
|
||||||
|
vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context].rip;
|
||||||
uint32_t inst_len = vcpu->arch_vcpu.inst_len;
|
uint32_t inst_len = vcpu->arch_vcpu.inst_len;
|
||||||
|
uint32_t err_code;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (inst_len > VIE_INST_SIZE) {
|
if (inst_len > VIE_INST_SIZE || inst_len == 0U) {
|
||||||
pr_err("%s: invalid instruction length (%d)",
|
pr_err("%s: invalid instruction length (%d)",
|
||||||
__func__, inst_len);
|
__func__, inst_len);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -1696,22 +1700,16 @@ vie_init(struct vie *vie, struct vcpu *vcpu)
|
|||||||
vie->index_register = CPU_REG_LAST;
|
vie->index_register = CPU_REG_LAST;
|
||||||
vie->segment_register = CPU_REG_LAST;
|
vie->segment_register = CPU_REG_LAST;
|
||||||
|
|
||||||
if (inst_len != 0U) {
|
err_code = PAGE_FAULT_ID_FLAG;
|
||||||
int ret;
|
ret = copy_from_gva(vcpu, vie->inst, guest_rip_gva,
|
||||||
uint64_t guest_rip_gva =
|
inst_len, &err_code);
|
||||||
vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context].rip;
|
if (ret == -EFAULT) {
|
||||||
uint32_t err_code;
|
vcpu_inject_pf(vcpu, guest_rip_gva, err_code);
|
||||||
|
return ret;
|
||||||
|
} else if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
err_code = PAGE_FAULT_ID_FLAG;
|
vie->num_valid = (uint8_t)inst_len;
|
||||||
ret = copy_from_gva(vcpu, vie->inst, guest_rip_gva,
|
|
||||||
inst_len, &err_code);
|
|
||||||
if (ret == -EFAULT) {
|
|
||||||
vcpu_inject_pf(vcpu, guest_rip_gva, err_code);
|
|
||||||
return ret;
|
|
||||||
} else if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
vie->num_valid = (uint8_t)inst_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user