[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20171011151518.i2euii23o7vmdiuo@pd.tnic>
Date: Wed, 11 Oct 2017 17:15:18 +0200
From: Borislav Petkov <bp@...e.de>
To: Ricardo Neri <ricardo.neri-calderon@...ux.intel.com>
Cc: Ingo Molnar <mingo@...hat.com>,
Thomas Gleixner <tglx@...utronix.de>,
"H. Peter Anvin" <hpa@...or.com>,
Andy Lutomirski <luto@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Brian Gerst <brgerst@...il.com>,
Chris Metcalf <cmetcalf@...lanox.com>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Paolo Bonzini <pbonzini@...hat.com>,
Masami Hiramatsu <mhiramat@...nel.org>,
Huang Rui <ray.huang@....com>, Jiri Slaby <jslaby@...e.cz>,
Jonathan Corbet <corbet@....net>,
"Michael S. Tsirkin" <mst@...hat.com>,
Paul Gortmaker <paul.gortmaker@...driver.com>,
Vlastimil Babka <vbabka@...e.cz>,
Chen Yucong <slaoub@...il.com>,
"Ravi V. Shankar" <ravi.v.shankar@...el.com>,
Shuah Khan <shuah@...nel.org>, linux-kernel@...r.kernel.org,
x86@...nel.org, ricardo.neri@...el.com,
Adam Buchbinder <adam.buchbinder@...il.com>,
Colin Ian King <colin.king@...onical.com>,
Lorenzo Stoakes <lstoakes@...il.com>,
Qiaowei Ren <qiaowei.ren@...el.com>,
Arnaldo Carvalho de Melo <acme@...hat.com>,
Adrian Hunter <adrian.hunter@...el.com>,
Kees Cook <keescook@...omium.org>,
Thomas Garnier <thgarnie@...gle.com>,
Dmitry Vyukov <dvyukov@...gle.com>
Subject: Re: [PATCH v9 15/29] x86/insn-eval: Add utility functions to get
segment descriptor base address and limit
On Tue, Oct 03, 2017 at 08:54:18PM -0700, Ricardo Neri wrote:
> With segmentation, the base address of the segment is needed to compute a
> linear address. This base address is obtained from the applicable segment
> descriptor. Such segment descriptor is referenced from a segment selector.
...
> +unsigned long insn_get_seg_base(struct pt_regs *regs, int seg_reg_idx)
> +{
> + struct desc_struct *desc;
> + short sel;
> +
> + sel = get_segment_selector(regs, seg_reg_idx);
> + if (sel < 0)
> + return -1L;
> +
> + if (v8086_mode(regs))
> + /*
> + * Base is simply the segment selector shifted 4
> + * positions to the right.
> + */
> + return (unsigned long)(sel << 4);
> +
> + if (user_64bit_mode(regs)) {
> + /*
> + * Only FS or GS will have a base address, the rest of
> + * the segments' bases are forced to 0.
> + */
> + unsigned long base;
> +
> + if (seg_reg_idx == INAT_SEG_REG_FS)
> + rdmsrl(MSR_FS_BASE, base);
> + else if (seg_reg_idx == INAT_SEG_REG_GS)
> + /*
> + * swapgs was called at the kernel entry point. Thus,
> + * MSR_KERNEL_GS_BASE will have the user-space GS base.
> + */
> + rdmsrl(MSR_KERNEL_GS_BASE, base);
> + else if (seg_reg_idx != INAT_SEG_REG_IGNORE)
> + /* We should ignore the rest of segment registers. */
> + base = -1L;
When is that case ever possible in long mode? You either have GS/FS
bases or 0. What's the meaning of -1L in that case?
Otherwise just minor things:
---
diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c
index 7ba5379a2923..e7e82b343bd0 100644
--- a/arch/x86/lib/insn-eval.c
+++ b/arch/x86/lib/insn-eval.c
@@ -515,13 +515,13 @@ static struct desc_struct *get_desc(unsigned short sel)
*
* Obtain the base address of the segment as indicated by the segment descriptor
* pointed by the segment selector. The segment selector is obtained from the
- * input segment register index seg_reg_idx.
+ * input segment register index @seg_reg_idx.
*
* Returns:
*
* In protected mode, base address of the segment. Zero in long mode,
* except when FS or GS are used. In virtual-8086 mode, the segment
- * selector shifted 4 positions to the right.
+ * selector shifted 4 bits to the right.
*
* -1L in case of error.
*/
@@ -537,7 +537,7 @@ unsigned long insn_get_seg_base(struct pt_regs *regs, int seg_reg_idx)
if (v8086_mode(regs))
/*
* Base is simply the segment selector shifted 4
- * positions to the right.
+ * bits to the right.
*/
return (unsigned long)(sel << 4);
--
Regards/Gruss,
Boris.
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
--
Powered by blists - more mailing lists