lkml.org 
[lkml]   [2020]   [Nov]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH v0 04/19] x86/insn-eval: Handle return values from the decoder
Date
From: Borislav Petkov <bp@suse.de>

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

Signed-off-by: Borislav Petkov <bp@suse.de>
---
arch/x86/lib/insn-eval.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c
index 99fafbaf8555..5825b4cf4386 100644
--- a/arch/x86/lib/insn-eval.c
+++ b/arch/x86/lib/insn-eval.c
@@ -1117,7 +1117,8 @@ static int get_eff_addr_sib(struct insn *insn, struct pt_regs *regs,
if (insn->addr_bytes != 8 && insn->addr_bytes != 4)
return -EINVAL;

- insn_get_modrm(insn);
+ if (insn_get_modrm(insn))
+ return -EINVAL;

if (!insn->modrm.nbytes)
return -EINVAL;
@@ -1125,7 +1126,8 @@ static int get_eff_addr_sib(struct insn *insn, struct pt_regs *regs,
if (X86_MODRM_MOD(insn->modrm.value) > 2)
return -EINVAL;

- insn_get_sib(insn);
+ if (insn_get_sib(insn))
+ return -EINVAL;

if (!insn->sib.nbytes)
return -EINVAL;
@@ -1194,8 +1196,8 @@ static void __user *get_addr_ref_16(struct insn *insn, struct pt_regs *regs)
short eff_addr;
long tmp;

- insn_get_modrm(insn);
- insn_get_displacement(insn);
+ if (insn_get_modrm(insn) || insn_get_displacement(insn))
+ goto out;

if (insn->addr_bytes != 2)
goto out;
@@ -1491,7 +1493,9 @@ bool insn_decode_regs(struct insn *insn, struct pt_regs *regs,
insn->addr_bytes = INSN_CODE_SEG_ADDR_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)
return false;

--
2.21.0
\
 
 \ /
  Last update: 2020-11-24 11:22    [W:0.249 / U:0.016 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site