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.
@@ -1682,9 +1682,13 @@ vie_calculate_gla(enum vm_cpu_mode cpu_mode, enum cpu_reg_name seg,
int
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 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)",
__func__, inst_len);
return -EINVAL;
@@ -1696,12 +1700,6 @@ vie_init(struct vie *vie, struct vcpu *vcpu)
vie->index_register = CPU_REG_LAST;
vie->segment_register = CPU_REG_LAST;
- if (inst_len != 0U) {
- int ret;
- uint64_t guest_rip_gva =
- vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context].rip;
- uint32_t err_code;
-
err_code = PAGE_FAULT_ID_FLAG;
ret = copy_from_gva(vcpu, vie->inst, guest_rip_gva,
inst_len, &err_code);
@@ -1710,8 +1708,8 @@ vie_init(struct vie *vie, struct vcpu *vcpu)
return ret;
} else if (ret < 0)
return ret;
+
vie->num_valid = (uint8_t)inst_len;
- }
return 0;
}
