From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752101AbdJKO5j (ORCPT ); Wed, 11 Oct 2017 10:57:39 -0400 Received: from mx2.suse.de ([195.135.220.15]:53436 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750705AbdJKO5h (ORCPT ); Wed, 11 Oct 2017 10:57:37 -0400 Date: Wed, 11 Oct 2017 16:57:29 +0200 From: Borislav Petkov To: Ricardo Neri Cc: Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Andrew Morton , Brian Gerst , Chris Metcalf , Dave Hansen , Paolo Bonzini , Masami Hiramatsu , Huang Rui , Jiri Slaby , Jonathan Corbet , "Michael S. Tsirkin" , Paul Gortmaker , Vlastimil Babka , Chen Yucong , "Ravi V. Shankar" , Shuah Khan , linux-kernel@vger.kernel.org, x86@kernel.org, ricardo.neri@intel.com, Adam Buchbinder , Colin Ian King , Lorenzo Stoakes , Qiaowei Ren , Arnaldo Carvalho de Melo , Adrian Hunter , Kees Cook , Thomas Garnier , Dmitry Vyukov Subject: Re: [PATCH v9 14/29] x86/insn-eval: Add utility function to get segment descriptor Message-ID: <20171011145729.j7rm3jduvczdhbek@pd.tnic> References: <1507089272-32733-1-git-send-email-ricardo.neri-calderon@linux.intel.com> <1507089272-32733-15-git-send-email-ricardo.neri-calderon@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1507089272-32733-15-git-send-email-ricardo.neri-calderon@linux.intel.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 03, 2017 at 08:54:17PM -0700, Ricardo Neri wrote: > The segment descriptor contains information that is relevant to how linear > addresses need to be computed. It contains the default size of addresses > as well as the base address of the segment. Thus, given a segment > selector, we ought to look at segment descriptor to correctly calculate > the linear address. > > In protected mode, the segment selector might indicate a segment > descriptor from either the global descriptor table or a local descriptor > table. Both cases are considered in this function. ... > +static struct desc_struct *get_desc(unsigned short sel) > +{ > + struct desc_ptr gdt_desc = {0, 0}; > + unsigned long desc_base; > + > +#ifdef CONFIG_MODIFY_LDT_SYSCALL > + struct desc_struct *desc = NULL; > + struct ldt_struct *ldt; You moved those out of the if-statement even though they're needed only in that scope. Why? Here's a diff that moves them back there and improves the function comment. --- diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c index 62975f825556..c4e82bb4c4d3 100644 --- a/arch/x86/lib/insn-eval.c +++ b/arch/x86/lib/insn-eval.c @@ -456,11 +456,11 @@ static int get_reg_offset(struct insn *insn, struct pt_regs *regs, } /** - * get_desc() - Obtain address of segment descriptor + * get_desc() - Obtain pointer to a segment descriptor * @sel: Segment selector * - * Given a segment selector, obtain a pointer to the segment descriptor. - * Both global and local descriptor tables are supported. + * Given a segment selector, obtain a pointer to the corresponding segment + * descriptor. Both global and local descriptor tables are supported. * * Returns: * @@ -474,10 +474,10 @@ static struct desc_struct *get_desc(unsigned short sel) unsigned long desc_base; #ifdef CONFIG_MODIFY_LDT_SYSCALL - struct desc_struct *desc = NULL; - struct ldt_struct *ldt; - if ((sel & SEGMENT_TI_MASK) == SEGMENT_LDT) { + struct desc_struct *desc = NULL; + struct ldt_struct *ldt; + /* Bits [15:3] contain the index of the desired entry. */ sel >>= 3; -- Regards/Gruss, Boris. SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg) --