All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: Andy Lutomirski <luto@amacapital.net>
Cc: billm@melbpc.org.au, Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	X86 ML <x86@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Andrew Lutomirski <luto@kernel.org>,
	stable <stable@vger.kernel.org>
Subject: Re: [Patch V3] x86/ldt: correct fpu emulation access to ldt
Date: Thu, 6 Aug 2015 18:00:43 +0200	[thread overview]
Message-ID: <55C384AB.9070400@suse.com> (raw)
In-Reply-To: <CALCETrU6zFFAY+tUWy4U13Z8aczAHh-iGbU69XoeEjs+igHFAw@mail.gmail.com>

On 08/06/2015 05:15 PM, Andy Lutomirski wrote:
> On Thu, Aug 6, 2015 at 2:21 AM, Juergen Gross <jgross@suse.com> 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  | 21 ++++++++++++++++++---
>>   arch/x86/math-emu/get_address.c |  3 +--
>>   3 files changed, 20 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..d4a49d7 100644
>> --- a/arch/x86/math-emu/fpu_system.h
>> +++ b/arch/x86/math-emu/fpu_system.h
>> @@ -16,9 +16,24 @@
>>   #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;
>> +       struct desc_struct *ret = &zero_desc;
>> +
>> +#ifdef CONFIG_MODIFY_LDT_SYSCALL
>> +       seg >>= 3;
>> +       mutex_lock(&current->mm->context.lock);
>> +       if (current->mm->context.ldt && seg < current->mm->context.ldt->size)
>> +               ret = current->mm->context.ldt->entries + seg;
>> +       mutex_unlock(&current->mm->context.lock);
>> +#endif
>
> Is there a good reason to return a pointer instead of returning struct
> desc_struct directly?  I think that, if you return a pointer, the
> locking is still wrong.  context.ldt can change at any point during
> which IRQs are enabled (unless you hold the mutex), so I don't think
> the mutex is sufficient -- the pointer can become invalid even after
> this function returns.

Aah, of course. Sorry about that.

I just wanted to avoid returning a 8 byte structure on 32 bit. I'll send
V4...


Thanks,

Juergen


      reply	other threads:[~2015-08-06 16:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-06  9:21 [Patch V3] x86/ldt: correct fpu emulation access to ldt Juergen Gross
2015-08-06 15:15 ` Andy Lutomirski
2015-08-06 16:00   ` Juergen Gross [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55C384AB.9070400@suse.com \
    --to=jgross@suse.com \
    --cc=billm@melbpc.org.au \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.