Commit 6e8c83d2 authored by Borislav Petkov's avatar Borislav Petkov

x86/insn-eval: Handle return values from the decoder

Now that the different instruction-inspecting functions return a value,
test that and return early from callers if error has been encountered.

While at it, do not call insn_get_modrm() when calling
insn_get_displacement() because latter will make sure to call
insn_get_modrm() if ModRM hasn't been parsed yet.
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20210304174237.31945-6-bp@alien8.de
parent 93281c4a
...@@ -924,10 +924,11 @@ static int get_seg_base_limit(struct insn *insn, struct pt_regs *regs, ...@@ -924,10 +924,11 @@ static int get_seg_base_limit(struct insn *insn, struct pt_regs *regs,
static int get_eff_addr_reg(struct insn *insn, struct pt_regs *regs, static int get_eff_addr_reg(struct insn *insn, struct pt_regs *regs,
int *regoff, long *eff_addr) int *regoff, long *eff_addr)
{ {
insn_get_modrm(insn); int ret;
if (!insn->modrm.nbytes) ret = insn_get_modrm(insn);
return -EINVAL; if (ret)
return ret;
if (X86_MODRM_MOD(insn->modrm.value) != 3) if (X86_MODRM_MOD(insn->modrm.value) != 3)
return -EINVAL; return -EINVAL;
...@@ -973,14 +974,14 @@ static int get_eff_addr_modrm(struct insn *insn, struct pt_regs *regs, ...@@ -973,14 +974,14 @@ static int get_eff_addr_modrm(struct insn *insn, struct pt_regs *regs,
int *regoff, long *eff_addr) int *regoff, long *eff_addr)
{ {
long tmp; long tmp;
int ret;
if (insn->addr_bytes != 8 && insn->addr_bytes != 4) if (insn->addr_bytes != 8 && insn->addr_bytes != 4)
return -EINVAL; return -EINVAL;
insn_get_modrm(insn); ret = insn_get_modrm(insn);
if (ret)
if (!insn->modrm.nbytes) return ret;
return -EINVAL;
if (X86_MODRM_MOD(insn->modrm.value) > 2) if (X86_MODRM_MOD(insn->modrm.value) > 2)
return -EINVAL; return -EINVAL;
...@@ -1102,18 +1103,21 @@ static int get_eff_addr_modrm_16(struct insn *insn, struct pt_regs *regs, ...@@ -1102,18 +1103,21 @@ static int get_eff_addr_modrm_16(struct insn *insn, struct pt_regs *regs,
* @base_offset will have a register, as an offset from the base of pt_regs, * @base_offset will have a register, as an offset from the base of pt_regs,
* that can be used to resolve the associated segment. * that can be used to resolve the associated segment.
* *
* -EINVAL on error. * Negative value on error.
*/ */
static int get_eff_addr_sib(struct insn *insn, struct pt_regs *regs, static int get_eff_addr_sib(struct insn *insn, struct pt_regs *regs,
int *base_offset, long *eff_addr) int *base_offset, long *eff_addr)
{ {
long base, indx; long base, indx;
int indx_offset; int indx_offset;
int ret;
if (insn->addr_bytes != 8 && insn->addr_bytes != 4) if (insn->addr_bytes != 8 && insn->addr_bytes != 4)
return -EINVAL; return -EINVAL;
insn_get_modrm(insn); ret = insn_get_modrm(insn);
if (ret)
return ret;
if (!insn->modrm.nbytes) if (!insn->modrm.nbytes)
return -EINVAL; return -EINVAL;
...@@ -1121,7 +1125,9 @@ static int get_eff_addr_sib(struct insn *insn, struct pt_regs *regs, ...@@ -1121,7 +1125,9 @@ static int get_eff_addr_sib(struct insn *insn, struct pt_regs *regs,
if (X86_MODRM_MOD(insn->modrm.value) > 2) if (X86_MODRM_MOD(insn->modrm.value) > 2)
return -EINVAL; return -EINVAL;
insn_get_sib(insn); ret = insn_get_sib(insn);
if (ret)
return ret;
if (!insn->sib.nbytes) if (!insn->sib.nbytes)
return -EINVAL; return -EINVAL;
...@@ -1190,8 +1196,8 @@ static void __user *get_addr_ref_16(struct insn *insn, struct pt_regs *regs) ...@@ -1190,8 +1196,8 @@ static void __user *get_addr_ref_16(struct insn *insn, struct pt_regs *regs)
short eff_addr; short eff_addr;
long tmp; long tmp;
insn_get_modrm(insn); if (insn_get_displacement(insn))
insn_get_displacement(insn); goto out;
if (insn->addr_bytes != 2) if (insn->addr_bytes != 2)
goto out; goto out;
...@@ -1525,7 +1531,9 @@ bool insn_decode_from_regs(struct insn *insn, struct pt_regs *regs, ...@@ -1525,7 +1531,9 @@ bool insn_decode_from_regs(struct insn *insn, struct pt_regs *regs,
insn->addr_bytes = INSN_CODE_SEG_ADDR_SZ(seg_defs); insn->addr_bytes = INSN_CODE_SEG_ADDR_SZ(seg_defs);
insn->opnd_bytes = INSN_CODE_SEG_OPND_SZ(seg_defs); insn->opnd_bytes = INSN_CODE_SEG_OPND_SZ(seg_defs);
insn_get_length(insn); if (insn_get_length(insn))
return false;
if (buf_size < insn->length) if (buf_size < insn->length)
return false; return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment