[PATCH v3 3/7] x86: move fill_user_desc() from tls.c to desc.h and add validity check
From: H. Peter Anvin, Intel
Date: Thu Jun 21 2018 - 17:18:36 EST
From: "H. Peter Anvin" <hpa@xxxxxxxxxxxxxxx>
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) <hpa@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Andy Lutomirski <luto@xxxxxxxxxx>
Cc: Chang S. Bae <chang.seok.bae@xxxxxxxxx>
Cc: Markus T. Metzger <markus.t.metzger@xxxxxxxxx>
---
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