Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp81661imm; Thu, 21 Jun 2018 14:19:47 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJdZamsLXKTfUug7LXwXdRY4OpCkL3sI0VfS9jefr66EmZCKTP4e2JZ43rluWBDPkPZQPhg X-Received: by 2002:a63:ac11:: with SMTP id v17-v6mr24143946pge.274.1529615987710; Thu, 21 Jun 2018 14:19:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529615987; cv=none; d=google.com; s=arc-20160816; b=uuoo35xMUjAxG2f8twRu4XM7jumF1jsqTnB+eT2TfpMsnq1n/9h31SxJHcOniYElGu xZoY/my7jngtJNWP2efdGbAQffooPs5/K3DXUA8WdvbvV4tjM0NMu8iI+vBm3LrLo/7c AwXUHmHJM+sVo03QVKwHO3x/2nO3FSrBf/s0ONCLDQ3Jx8XCfVF/FI4XOswtNimP+HE9 D7d3azOWq8b/9NNfC07j0ZFZ1nQkJVS4UAVrSWaZ+12jaICo7IdsA4JM/+ieNPMMshlp IRwrgofmcYPhSn+HzRsMYo0hAc390u7NYabqZJaCiHsba80afkU0C9651yFBLYEFGoUs 6tiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=nw+JfWBjzM37cpG6IJLmfPHh6kTl7jpBbbfjUw7dTJM=; b=QEsIfv4eO4+d+QTkJfVzwA6M1eBakUyu1UNq9EJS/O39b+zUaSrvapbzTV+u/EkeLU aRR4MxGUKTeisnpWONvIvx8JFs1Iq8O2hNq19gyGnIoHuiYv/oMJdjaKUUIrAtdChoRI yL4VyiI+DVosloVD0bPRJUP58tp/5Jx3Ka11MXWMPZPuM/M8kD8Eh8gaGpU8UmyjXci1 Ug13N9AQqnQV488Oh24ImDjp1M0vZ36tkP5Em/7s+J6PrauJgfj89GMnbUIb24USgDOj 2C+zCnxbrzfdZQ3NuaLFMto1HLvKG8BgXao9xImrfDpt8bQFae2M8WOMY3K70eZqRCrR tU9g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u1-v6si5847743plj.386.2018.06.21.14.19.33; Thu, 21 Jun 2018 14:19:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754295AbeFUVSe (ORCPT + 99 others); Thu, 21 Jun 2018 17:18:34 -0400 Received: from mga14.intel.com ([192.55.52.115]:27244 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754240AbeFUVSD (ORCPT ); Thu, 21 Jun 2018 17:18:03 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Jun 2018 14:18:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,253,1526367600"; d="scan'208";a="48912119" Received: from hanvin-mobl2.amr.corp.intel.com ([10.254.42.214]) by fmsmga007.fm.intel.com with ESMTP; 21 Jun 2018 14:18:02 -0700 From: "H. Peter Anvin, Intel" To: Linux Kernel Mailing List Cc: "H. Peter Anvin" , "H . Peter Anvin" , Ingo Molnar , Thomas Gleixner , Andy Lutomirski , "Chang S . Bae" , "Markus T . Metzger" Subject: [PATCH v3 3/7] x86: move fill_user_desc() from tls.c to desc.h and add validity check Date: Thu, 21 Jun 2018 14:17:50 -0700 Message-Id: <20180621211754.12757-4-h.peter.anvin@intel.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180621211754.12757-1-h.peter.anvin@intel.com> References: <20180621211754.12757-1-h.peter.anvin@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "H. Peter Anvin" This is generic code which is potentially useful in other contexts. Unfortunately modify_ldt() is kind of stupid in that it returns a descriptor in CPU format but takes a different format, but regsets *have* to operate differently. Signed-off-by: H. Peter Anvin (Intel) Cc: Ingo Molnar Cc: Thomas Gleixner Cc: Andy Lutomirski Cc: Chang S. Bae Cc: Markus T. Metzger --- arch/x86/include/asm/desc.h | 22 ++++++++++++++++++++++ arch/x86/kernel/tls.c | 19 ------------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h index 13c5ee878a47..5e69f993c9ff 100644 --- a/arch/x86/include/asm/desc.h +++ b/arch/x86/include/asm/desc.h @@ -386,6 +386,28 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit) desc->limit1 = (limit >> 16) & 0xf; } + +static inline void fill_user_desc(struct user_desc *info, int idx, + const struct desc_struct *desc) + +{ + memset(info, 0, sizeof(*info)); + info->entry_number = idx; + if (desc->s && desc->dpl == 3) { + info->base_addr = get_desc_base(desc); + info->limit = get_desc_limit(desc); + info->seg_32bit = desc->d; + info->contents = desc->type >> 2; + info->read_exec_only = !(desc->type & 2); + info->limit_in_pages = desc->g; + info->seg_not_present = !desc->p; + info->useable = desc->avl; +#ifdef CONFIG_X86_64 + info->lm = desc->l; +#endif + } +} + void update_intr_gate(unsigned int n, const void *addr); void alloc_intr_gate(unsigned int n, const void *addr); diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c index a5b802a12212..7b8ecb760707 100644 --- a/arch/x86/kernel/tls.c +++ b/arch/x86/kernel/tls.c @@ -197,25 +197,6 @@ SYSCALL_DEFINE1(set_thread_area, struct user_desc __user *, u_info) * Get the current Thread-Local Storage area: */ -static void fill_user_desc(struct user_desc *info, int idx, - const struct desc_struct *desc) - -{ - memset(info, 0, sizeof(*info)); - info->entry_number = idx; - info->base_addr = get_desc_base(desc); - info->limit = get_desc_limit(desc); - info->seg_32bit = desc->d; - info->contents = desc->type >> 2; - info->read_exec_only = !(desc->type & 2); - info->limit_in_pages = desc->g; - info->seg_not_present = !desc->p; - info->useable = desc->avl; -#ifdef CONFIG_X86_64 - info->lm = desc->l; -#endif -} - int do_get_thread_area(struct task_struct *p, int idx, struct user_desc __user *u_info) { -- 2.14.4