From: tip-bot for Ricardo Neri <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: adam.buchbinder@gmail.com, adrian.hunter@intel.com,
linux-kernel@vger.kernel.org, bp@suse.de, qiaowei.ren@intel.com,
dave.hansen@linux.intel.com, slaoub@gmail.com,
colin.king@canonical.com, paul.gortmaker@windriver.com,
shuah@kernel.org, ricardo.neri-calderon@linux.intel.com,
torvalds@linux-foundation.org, dvyukov@google.com,
lstoakes@gmail.com, keescook@chromium.org, acme@redhat.com,
tglx@linutronix.de, cmetcalf@mellanox.com, luto@kernel.org,
pbonzini@redhat.com, mhiramat@kernel.org,
akpm@linux-foundation.org, mst@redhat.com, hpa@zytor.com,
ravi.v.shankar@intel.com, peterz@infradead.org, mingo@kernel.org,
vbabka@suse.cz, jslaby@suse.cz, thgarnie@google.com,
corbet@lwn.net, ray.huang@amd.com, brgerst@gmail.com
Subject: [tip:x86/mpx] x86/insn-eval: Extend get_seg_base_addr() to also obtain segment limit
Date: Thu, 2 Nov 2017 02:37:44 -0700 [thread overview]
Message-ID: <tip-71271269ef9a997fb4416b2f8ef3558dd846c7cb@git.kernel.org> (raw)
In-Reply-To: <1509148310-30862-2-git-send-email-ricardo.neri-calderon@linux.intel.com>
Commit-ID: 71271269ef9a997fb4416b2f8ef3558dd846c7cb
Gitweb: https://git.kernel.org/tip/71271269ef9a997fb4416b2f8ef3558dd846c7cb
Author: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
AuthorDate: Fri, 27 Oct 2017 16:51:38 -0700
Committer: Ingo Molnar <mingo@kernel.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@linux.intel.com>
Cc: Adam Buchbinder <adam.buchbinder@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Chen Yucong <slaoub@gmail.com>
Cc: Chris Metcalf <cmetcalf@mellanox.com>
Cc: Colin Ian King <colin.king@canonical.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Huang Rui <ray.huang@amd.com>
Cc: Jiri Slaby <jslaby@suse.cz>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Paul Gortmaker <paul.gortmaker@windriver.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Qiaowei Ren <qiaowei.ren@intel.com>
Cc: Ravi V. Shankar <ravi.v.shankar@intel.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Thomas Garnier <thgarnie@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: ricardo.neri@intel.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@kernel.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;
next prev parent reply other threads:[~2017-11-02 9:45 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-27 23:51 [PATCH v10 00/13] x86: Enable User-Mode Instruction Prevention Ricardo Neri
2017-10-27 23:51 ` [PATCH v10 01/13] x86/insn-eval: Extend get_seg_base_addr() to also obtain segment limit Ricardo Neri
2017-11-02 9:37 ` tip-bot for Ricardo Neri [this message]
2017-10-27 23:51 ` [PATCH v10 02/13] x86/insn-eval: Compute linear address in several utility functions Ricardo Neri
2017-11-02 8:51 ` Ingo Molnar
2017-11-02 11:07 ` Thomas Gleixner
2017-11-03 2:46 ` Ricardo Neri
2017-11-03 2:44 ` Ricardo Neri
2017-11-03 10:17 ` Ingo Molnar
2017-11-04 0:40 ` Ricardo Neri
2017-11-04 8:26 ` Ingo Molnar
2017-10-27 23:51 ` [PATCH v10 03/13] x86/insn-eval: Add support to resolve 32-bit address encodings Ricardo Neri
2017-10-27 23:51 ` [PATCH v10 04/13] x86/insn-eval: Add wrapper function for 32 and 64-bit addresses Ricardo Neri
2017-10-27 23:51 ` [PATCH v10 05/13] x86/insn-eval: Handle 32-bit address encodings in virtual-8086 mode Ricardo Neri
2017-10-27 23:51 ` [PATCH v10 06/13] x86/insn-eval: Add support to resolve 16-bit address encodings Ricardo Neri
2017-10-27 23:51 ` [PATCH v10 07/13] x86/cpufeature: Add User-Mode Instruction Prevention definitions Ricardo Neri
2017-10-27 23:51 ` [PATCH v10 08/13] x86: Add emulation code for UMIP instructions Ricardo Neri
2017-10-27 23:51 ` [PATCH v10 09/13] x86/umip: Force a page fault when unable to copy emulated result to user Ricardo Neri
2017-10-27 23:51 ` [PATCH v10 10/13] x86: Enable User-Mode Instruction Prevention Ricardo Neri
2017-10-27 23:51 ` [PATCH v10 11/13] x86/traps: Fixup general protection faults caused by UMIP Ricardo Neri
2017-10-27 23:51 ` [PATCH v10 12/13] selftests/x86: Add tests for User-Mode Instruction Prevention Ricardo Neri
2017-10-27 23:51 ` [PATCH v10 13/13] selftests/x86: Add tests for instruction str and sldt Ricardo Neri
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tip-71271269ef9a997fb4416b2f8ef3558dd846c7cb@git.kernel.org \
--to=tipbot@zytor.com \
--cc=acme@redhat.com \
--cc=adam.buchbinder@gmail.com \
--cc=adrian.hunter@intel.com \
--cc=akpm@linux-foundation.org \
--cc=bp@suse.de \
--cc=brgerst@gmail.com \
--cc=cmetcalf@mellanox.com \
--cc=colin.king@canonical.com \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=dvyukov@google.com \
--cc=hpa@zytor.com \
--cc=jslaby@suse.cz \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=lstoakes@gmail.com \
--cc=luto@kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@kernel.org \
--cc=mst@redhat.com \
--cc=paul.gortmaker@windriver.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=qiaowei.ren@intel.com \
--cc=ravi.v.shankar@intel.com \
--cc=ray.huang@amd.com \
--cc=ricardo.neri-calderon@linux.intel.com \
--cc=shuah@kernel.org \
--cc=slaoub@gmail.com \
--cc=tglx@linutronix.de \
--cc=thgarnie@google.com \
--cc=torvalds@linux-foundation.org \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).