[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <tip-71271269ef9a997fb4416b2f8ef3558dd846c7cb@git.kernel.org>
Date: Thu, 2 Nov 2017 02:37:44 -0700
From: tip-bot for Ricardo Neri <tipbot@...or.com>
To: linux-tip-commits@...r.kernel.org
Cc: adam.buchbinder@...il.com, adrian.hunter@...el.com,
linux-kernel@...r.kernel.org, bp@...e.de, qiaowei.ren@...el.com,
dave.hansen@...ux.intel.com, slaoub@...il.com,
colin.king@...onical.com, paul.gortmaker@...driver.com,
shuah@...nel.org, ricardo.neri-calderon@...ux.intel.com,
torvalds@...ux-foundation.org, dvyukov@...gle.com,
lstoakes@...il.com, keescook@...omium.org, acme@...hat.com,
tglx@...utronix.de, cmetcalf@...lanox.com, luto@...nel.org,
pbonzini@...hat.com, mhiramat@...nel.org,
akpm@...ux-foundation.org, mst@...hat.com, hpa@...or.com,
ravi.v.shankar@...el.com, peterz@...radead.org, mingo@...nel.org,
vbabka@...e.cz, jslaby@...e.cz, thgarnie@...gle.com,
corbet@....net, ray.huang@....com, brgerst@...il.com
Subject: [tip:x86/mpx] x86/insn-eval: Extend get_seg_base_addr() to also
obtain segment limit
Commit-ID: 71271269ef9a997fb4416b2f8ef3558dd846c7cb
Gitweb: https://git.kernel.org/tip/71271269ef9a997fb4416b2f8ef3558dd846c7cb
Author: Ricardo Neri <ricardo.neri-calderon@...ux.intel.com>
AuthorDate: Fri, 27 Oct 2017 16:51:38 -0700
Committer: Ingo Molnar <mingo@...nel.org>
CommitDate: Thu, 2 Nov 2017 09:55:14 +0100
x86/insn-eval: Extend get_seg_base_addr() to also obtain segment limit
In protected mode, it is common to want to obtain the limit of a segment
along with its base address. This is useful, for instance, to verify that
an effective address lies within a segment before computing a linear
address.
Up to this point, this library only computes linear addresses in long
mode. Subsequent patches will include support for protected mode. Support
to verify the segment limit will be needed.
Signed-off-by: Ricardo Neri <ricardo.neri-calderon@...ux.intel.com>
Cc: Adam Buchbinder <adam.buchbinder@...il.com>
Cc: Adrian Hunter <adrian.hunter@...el.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Andy Lutomirski <luto@...nel.org>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: Borislav Petkov <bp@...e.de>
Cc: Brian Gerst <brgerst@...il.com>
Cc: Chen Yucong <slaoub@...il.com>
Cc: Chris Metcalf <cmetcalf@...lanox.com>
Cc: Colin Ian King <colin.king@...onical.com>
Cc: Dave Hansen <dave.hansen@...ux.intel.com>
Cc: Dmitry Vyukov <dvyukov@...gle.com>
Cc: Huang Rui <ray.huang@....com>
Cc: Jiri Slaby <jslaby@...e.cz>
Cc: Jonathan Corbet <corbet@....net>
Cc: Kees Cook <keescook@...omium.org>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Lorenzo Stoakes <lstoakes@...il.com>
Cc: Masami Hiramatsu <mhiramat@...nel.org>
Cc: Michael S. Tsirkin <mst@...hat.com>
Cc: Paolo Bonzini <pbonzini@...hat.com>
Cc: Paul Gortmaker <paul.gortmaker@...driver.com>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Qiaowei Ren <qiaowei.ren@...el.com>
Cc: Ravi V. Shankar <ravi.v.shankar@...el.com>
Cc: Shuah Khan <shuah@...nel.org>
Cc: Thomas Garnier <thgarnie@...gle.com>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Vlastimil Babka <vbabka@...e.cz>
Cc: ricardo.neri@...el.com
Link: http://lkml.kernel.org/r/1509148310-30862-2-git-send-email-ricardo.neri-calderon@linux.intel.com
Signed-off-by: Ingo Molnar <mingo@...nel.org>
---
arch/x86/lib/insn-eval.c | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c
index 1c23ec0..91f08aa 100644
--- a/arch/x86/lib/insn-eval.c
+++ b/arch/x86/lib/insn-eval.c
@@ -729,25 +729,29 @@ int insn_get_modrm_rm_off(struct insn *insn, struct pt_regs *regs)
}
/**
- * get_seg_base_addr() - obtain base address of a segment
+ * get_seg_base_limit() - obtain base address and limit of a segment
* @insn: Instruction. Must be valid.
* @regs: Register values as seen when entering kernel mode
* @regoff: Operand offset, in pt_regs, used to resolve segment descriptor
* @base: Obtained segment base
+ * @limit: Obtained segment limit
*
- * Obtain the base address of the segment associated with the operand @regoff
- * and, if any or allowed, override prefixes in @insn. This function is
+ * Obtain the base address and limit of the segment associated with the operand
+ * @regoff and, if any or allowed, override prefixes in @insn. This function is
* different from insn_get_seg_base() as the latter does not resolve the segment
- * associated with the instruction operand.
+ * associated with the instruction operand. If a limit is not needed (e.g.,
+ * when running in long mode), @limit can be NULL.
*
* Returns:
*
- * 0 on success. @base will contain the base address of the resolved segment.
+ * 0 on success. @base and @limit will contain the base address and of the
+ * resolved segment, respectively.
*
* -EINVAL on error.
*/
-static int get_seg_base_addr(struct insn *insn, struct pt_regs *regs,
- int regoff, unsigned long *base)
+static int get_seg_base_limit(struct insn *insn, struct pt_regs *regs,
+ int regoff, unsigned long *base,
+ unsigned long *limit)
{
int seg_reg_idx;
@@ -762,6 +766,13 @@ static int get_seg_base_addr(struct insn *insn, struct pt_regs *regs,
if (*base == -1L)
return -EINVAL;
+ if (!limit)
+ return 0;
+
+ *limit = get_seg_limit(regs, seg_reg_idx);
+ if (!(*limit))
+ return -EINVAL;
+
return 0;
}
@@ -843,7 +854,7 @@ void __user *insn_get_addr_ref(struct insn *insn, struct pt_regs *regs)
eff_addr += insn->displacement.value;
}
- ret = get_seg_base_addr(insn, regs, addr_offset, &seg_base);
+ ret = get_seg_base_limit(insn, regs, addr_offset, &seg_base, NULL);
if (ret)
goto out;
Powered by blists - more mailing lists