Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1201595 > unrolled thread

[Patch V2] x86/ldt: correct fpu emulation access to ldt

Started byJuergen Gross <jgross@suse.com>
First post2015-08-06 11:10 +0200
Last post2015-08-06 11:20 +0200
Articles 2 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [Patch V2] x86/ldt: correct fpu emulation access to ldt Juergen Gross <jgross@suse.com> - 2015-08-06 11:10 +0200
    Re: [Patch V2] x86/ldt: correct fpu emulation access to ldt Juergen Gross <jgross@suse.com> - 2015-08-06 11:20 +0200

#1201595 — [Patch V2] x86/ldt: correct fpu emulation access to ldt

FromJuergen Gross <jgross@suse.com>
Date2015-08-06 11:10 +0200
Subject[Patch V2] x86/ldt: correct fpu emulation access to ldt
Message-ID<pUplv-4re-9@gated-at.bofh.it>
Commit 37868fe113ff ("x86/ldt: Make modify_ldt synchronous") introduced
a new struct ldt_struct anchored at mm->context.ldt.

Adapt the x86 fpu emulation to use that new structure.

Cc: <stable@vger.kernel.org> # 37868fe113ff: x86/ldt: Make modify_ldt synchronous
Cc: <stable@vger.kernel.org> # a5b9e5a2f14f: x86/ldt: Make modify_ldt optional
Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/math-emu/fpu_entry.c   |  3 +--
 arch/x86/math-emu/fpu_system.h  | 18 +++++++++++++++---
 arch/x86/math-emu/get_address.c |  3 +--
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/arch/x86/math-emu/fpu_entry.c b/arch/x86/math-emu/fpu_entry.c
index f37e84a..203318a 100644
--- a/arch/x86/math-emu/fpu_entry.c
+++ b/arch/x86/math-emu/fpu_entry.c
@@ -29,7 +29,6 @@
 
 #include <asm/uaccess.h>
 #include <asm/traps.h>
-#include <asm/desc.h>
 #include <asm/user.h>
 #include <asm/fpu/internal.h>
 
@@ -181,7 +180,7 @@ void math_emulate(struct math_emu_info *info)
 			math_abort(FPU_info, SIGILL);
 		}
 
-		code_descriptor = LDT_DESCRIPTOR(FPU_CS);
+		code_descriptor = *FPU_get_ldt_descriptor(FPU_CS);
 		if (SEG_D_SIZE(code_descriptor)) {
 			/* The above test may be wrong, the book is not clear */
 			/* Segmented 32 bit protected mode */
diff --git a/arch/x86/math-emu/fpu_system.h b/arch/x86/math-emu/fpu_system.h
index 9ccecb6..9330583 100644
--- a/arch/x86/math-emu/fpu_system.h
+++ b/arch/x86/math-emu/fpu_system.h
@@ -16,9 +16,21 @@
 #include <linux/kernel.h>
 #include <linux/mm.h>
 
-/* s is always from a cpu register, and the cpu does bounds checking
- * during register load --> no further bounds checks needed */
-#define LDT_DESCRIPTOR(s)	(((struct desc_struct *)current->mm->context.ldt)[(s) >> 3])
+#include <asm/desc.h>
+#include <asm/mmu_context.h>
+
+static inline struct desc_struct *FPU_get_ldt_descriptor(unsigned seg)
+{
+	static struct desc_struct zero_desc;
+
+#ifdef CONFIG_MODIFY_LDT_SYSCALL
+	seg >>= 3;
+	if (seg < current->mm->context.ldt->size)
+		return current->mm->context.ldt->entries + seg;
+#endif
+	return &zero_desc;
+}
+
 #define SEG_D_SIZE(x)		((x).b & (3 << 21))
 #define SEG_G_BIT(x)		((x).b & (1 << 23))
 #define SEG_GRANULARITY(x)	(((x).b & (1 << 23)) ? 4096 : 1)
diff --git a/arch/x86/math-emu/get_address.c b/arch/x86/math-emu/get_address.c
index 6ef5e99..f912edd 100644
--- a/arch/x86/math-emu/get_address.c
+++ b/arch/x86/math-emu/get_address.c
@@ -20,7 +20,6 @@
 #include <linux/stddef.h>
 
 #include <asm/uaccess.h>
-#include <asm/desc.h>
 
 #include "fpu_system.h"
 #include "exception.h"
@@ -158,7 +157,7 @@ static long pm_address(u_char FPU_modrm, u_char segment,
 		addr->selector = PM_REG_(segment);
 	}
 
-	descriptor = LDT_DESCRIPTOR(PM_REG_(segment));
+	descriptor = *FPU_get_ldt_descriptor(segment);
 	base_address = SEG_BASE_ADDR(descriptor);
 	address = base_address + offset;
 	limit = base_address
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1201602

FromJuergen Gross <jgross@suse.com>
Date2015-08-06 11:20 +0200
Message-ID<pUpvd-4Ct-21@gated-at.bofh.it>
In reply to#1201595
Please ignore, V3 coming soon.


Juergen

On 08/06/2015 11:07 AM, Juergen Gross wrote:
> Commit 37868fe113ff ("x86/ldt: Make modify_ldt synchronous") introduced
> a new struct ldt_struct anchored at mm->context.ldt.
>
> Adapt the x86 fpu emulation to use that new structure.
>
> Cc: <stable@vger.kernel.org> # 37868fe113ff: x86/ldt: Make modify_ldt synchronous
> Cc: <stable@vger.kernel.org> # a5b9e5a2f14f: x86/ldt: Make modify_ldt optional
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
>   arch/x86/math-emu/fpu_entry.c   |  3 +--
>   arch/x86/math-emu/fpu_system.h  | 18 +++++++++++++++---
>   arch/x86/math-emu/get_address.c |  3 +--
>   3 files changed, 17 insertions(+), 7 deletions(-)
>
> diff --git a/arch/x86/math-emu/fpu_entry.c b/arch/x86/math-emu/fpu_entry.c
> index f37e84a..203318a 100644
> --- a/arch/x86/math-emu/fpu_entry.c
> +++ b/arch/x86/math-emu/fpu_entry.c
> @@ -29,7 +29,6 @@
>
>   #include <asm/uaccess.h>
>   #include <asm/traps.h>
> -#include <asm/desc.h>
>   #include <asm/user.h>
>   #include <asm/fpu/internal.h>
>
> @@ -181,7 +180,7 @@ void math_emulate(struct math_emu_info *info)
>   			math_abort(FPU_info, SIGILL);
>   		}
>
> -		code_descriptor = LDT_DESCRIPTOR(FPU_CS);
> +		code_descriptor = *FPU_get_ldt_descriptor(FPU_CS);
>   		if (SEG_D_SIZE(code_descriptor)) {
>   			/* The above test may be wrong, the book is not clear */
>   			/* Segmented 32 bit protected mode */
> diff --git a/arch/x86/math-emu/fpu_system.h b/arch/x86/math-emu/fpu_system.h
> index 9ccecb6..9330583 100644
> --- a/arch/x86/math-emu/fpu_system.h
> +++ b/arch/x86/math-emu/fpu_system.h
> @@ -16,9 +16,21 @@
>   #include <linux/kernel.h>
>   #include <linux/mm.h>
>
> -/* s is always from a cpu register, and the cpu does bounds checking
> - * during register load --> no further bounds checks needed */
> -#define LDT_DESCRIPTOR(s)	(((struct desc_struct *)current->mm->context.ldt)[(s) >> 3])
> +#include <asm/desc.h>
> +#include <asm/mmu_context.h>
> +
> +static inline struct desc_struct *FPU_get_ldt_descriptor(unsigned seg)
> +{
> +	static struct desc_struct zero_desc;
> +
> +#ifdef CONFIG_MODIFY_LDT_SYSCALL
> +	seg >>= 3;
> +	if (seg < current->mm->context.ldt->size)
> +		return current->mm->context.ldt->entries + seg;
> +#endif
> +	return &zero_desc;
> +}
> +
>   #define SEG_D_SIZE(x)		((x).b & (3 << 21))
>   #define SEG_G_BIT(x)		((x).b & (1 << 23))
>   #define SEG_GRANULARITY(x)	(((x).b & (1 << 23)) ? 4096 : 1)
> diff --git a/arch/x86/math-emu/get_address.c b/arch/x86/math-emu/get_address.c
> index 6ef5e99..f912edd 100644
> --- a/arch/x86/math-emu/get_address.c
> +++ b/arch/x86/math-emu/get_address.c
> @@ -20,7 +20,6 @@
>   #include <linux/stddef.h>
>
>   #include <asm/uaccess.h>
> -#include <asm/desc.h>
>
>   #include "fpu_system.h"
>   #include "exception.h"
> @@ -158,7 +157,7 @@ static long pm_address(u_char FPU_modrm, u_char segment,
>   		addr->selector = PM_REG_(segment);
>   	}
>
> -	descriptor = LDT_DESCRIPTOR(PM_REG_(segment));
> +	descriptor = *FPU_get_ldt_descriptor(segment);
>   	base_address = SEG_BASE_ADDR(descriptor);
>   	address = base_address + offset;
>   	limit = base_address
>

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web