From: Boris Ostrovsky <boris.ostrovsky@oracle.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>,
Andy Lutomirski <luto@amacapital.net>
Cc: "security@kernel.org" <security@kernel.org>,
Jan Beulich <jbeulich@suse.com>,
Peter Zijlstra <peterz@infradead.org>, X86 ML <x86@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
xen-devel <xen-devel@lists.xen.org>,
Borislav Petkov <bp@alien8.de>, stable <stable@vger.kernel.org>,
Andy Lutomirski <luto@kernel.org>,
Sasha Levin <sasha.levin@oracle.com>
Subject: Re: [Xen-devel] [PATCH v2 1/3] x86/ldt: Make modify_ldt synchronous
Date: Tue, 21 Jul 2015 22:04:44 -0400 [thread overview]
Message-ID: <55AEFA3C.3020006@oracle.com> (raw)
In-Reply-To: <55AEE8A7.4040904@citrix.com>
On 07/21/2015 08:49 PM, Andrew Cooper wrote:
> On 22/07/2015 01:28, Andy Lutomirski wrote:
>> On Tue, Jul 21, 2015 at 5:21 PM, Andrew Cooper
>> <andrew.cooper3@citrix.com> wrote:
>>> On 22/07/2015 01:07, Andy Lutomirski wrote:
>>>> On Tue, Jul 21, 2015 at 4:38 PM, Andrew Cooper
>>>> <andrew.cooper3@citrix.com> wrote:
>>>>> On 21/07/2015 22:53, Boris Ostrovsky wrote:
>>>>>> On 07/21/2015 03:59 PM, Andy Lutomirski wrote:
>>>>>>> --- a/arch/x86/include/asm/mmu_context.h
>>>>>>> +++ b/arch/x86/include/asm/mmu_context.h
>>>>>>> @@ -34,6 +34,44 @@ static inline void load_mm_cr4(struct mm_struct
>>>>>>> *mm) {}
>>>>>>> #endif
>>>>>>> /*
>>>>>>> + * ldt_structs can be allocated, used, and freed, but they are never
>>>>>>> + * modified while live.
>>>>>>> + */
>>>>>>> +struct ldt_struct {
>>>>>>> + int size;
>>>>>>> + int __pad; /* keep the descriptors naturally aligned. */
>>>>>>> + struct desc_struct entries[];
>>>>>>> +};
>>>>>> This breaks Xen which expects LDT to be page-aligned. Not sure why.
>>>>>>
>>>>>> Jan, Andrew?
>>>>> PV guests are not permitted to have writeable mappings to the frames
>>>>> making up the GDT and LDT, so it cannot make unaudited changes to
>>>>> loadable descriptors. In particular, for a 32bit PV guest, it is only
>>>>> the segment limit which protects Xen from the ring1 guest kernel.
>>>>>
>>>>> A lot of this code hasn't been touched in years, and it certainly
>>>>> predates me. The alignment requirement appears to come from the virtual
>>>>> region Xen uses to map the guests GDT and LDT. Strict alignment is
>>>>> required for the GDT so Xen's descriptors starting at 0xe0xx are
>>>>> correct, but the LDT alignment seems to be a side effect of similar
>>>>> codepaths.
>>>>>
>>>>> For an LDT smaller than 8192 entries, I can't see any specific reason
>>>>> for enforcing alignment, other than "that's the way it has always been".
>>>>>
>>>>> However, the guest would still have to relinquish write access to all
>>>>> frames which make up the LDT, which looks to be a bit of an issue given
>>>>> the snippet above.
>>>> Does the LDT itself need to be aligned or just the address passed to
>>>> paravirt_alloc_ldt?
>>> The address which Xen receives needs to be aligned.
>>>
>>> It looks like xen_alloc_ldt() blindly assumes that the desc_struct *ldt
>>> it is passed is page aligned, and passes it straight through.
>> xen_alloc_ldt is just fiddling with protection though, I think. Isn't
>> it xen_set_ldt that's the meat? We could easily pass xen_alloc_ldt a
>> pointer to the ldt_struct.
> So it is. It is the linear_addr in xen_set_ldt() which Xen currently
> audits to be page aligned.
>
>>>>> This will allow ldt_struct itself to be page aligned, and for the size
>>>>> field to sit across the base/limit field of what would logically be
>>>>> selector 0x0008 There would be some issues accessing size. To load
>>>>> frames as an LDT, a guest must drop all refs to the page so that its
>>>>> type may be changed from writeable to segdesc. After that, an
>>>>> update_descriptor hypercall can be used to change size, and I believe
>>>>> the guest may subsequently recreate read-only mappings to the frames in
>>>>> question (although frankly it is getting late so you will want to double
>>>>> check all of this).
>>>>>
>>>>> Anyhow, this looks like an issue which should be fixed up with slightly
>>>>> more PVOps, rather than enforcing a Xen view of the world on native Linux.
>>>>>
>>>> I could presumably make the allocation the other way around so the
>>>> size is at the end. I could even use two separate allocations if
>>>> needed.
Why not wrap mm_context_t's ldt and size into a struct (just like
ldt_struct but without __pad) and have a single allocation of ldt?
I.e.
struct ldt_struct {
int size;
struct desc_struct *entries;
}
--- a/arch/x86/include/asm/mmu.h
+++ b/arch/x86/include/asm/mmu.h
@@ -9,8 +9,7 @@
* we put the segment information here.
*/
typedef struct {
- void *ldt;
- int size;
+ struct ldt_struct ldt;
#ifdef CONFIG_X86_64
/* True if mm supports a task running in 32 bit compatibility
mode. */
-boris
>>> I suspect two separate allocations would be the better solution, as it
>>> means that the size field doesn't need to be subject to funny page
>>> permissions.
>> True. OTOH we never write to the size field after allocating the thing.
> Right, but even reading it is going to cause problems if one of the
> paravirt ops can't re-establish ro mappings.
>
> ~Andrew
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2015-07-22 2:05 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-21 19:59 [PATCH v2 0/3] x86: modify_ldt improvement, test, and config option Andy Lutomirski
2015-07-21 19:59 ` [PATCH v2 1/3] x86/ldt: Make modify_ldt synchronous Andy Lutomirski
2015-07-21 21:53 ` Boris Ostrovsky
2015-07-21 23:38 ` Andrew Cooper
2015-07-22 0:07 ` Andy Lutomirski
2015-07-22 0:21 ` Andrew Cooper
2015-07-22 0:28 ` Andy Lutomirski
2015-07-22 0:49 ` Andrew Cooper
2015-07-22 1:06 ` Andy Lutomirski
2015-07-22 2:04 ` Boris Ostrovsky [this message]
2015-07-22 2:13 ` [Xen-devel] " Andy Lutomirski
2015-07-22 2:01 ` Brian Gerst
2015-07-22 2:12 ` Andy Lutomirski
2015-07-22 2:53 ` Brian Gerst
2015-07-22 4:22 ` Andy Lutomirski
2015-07-21 19:59 ` [PATCH v2 2/3] x86/ldt: Make modify_ldt optional Andy Lutomirski
2015-07-21 20:20 ` Sasha Levin
2015-07-21 20:27 ` Andy Lutomirski
2015-07-21 20:28 ` Brian Gerst
2015-07-21 20:34 ` Andy Lutomirski
2015-07-21 20:54 ` Brian Gerst
2015-07-22 6:06 ` Ingo Molnar
2015-07-22 6:23 ` Andy Lutomirski
2015-07-22 6:27 ` Ingo Molnar
2015-07-22 18:49 ` Andy Lutomirski
2015-07-22 12:34 ` Willy Tarreau
2015-07-21 19:59 ` [PATCH v2 3/3] selftests/x86, x86/ldt: Add a selftest for modify_ldt Andy Lutomirski
2015-07-21 22:02 ` Boris Ostrovsky
2015-07-21 22:34 ` Andy Lutomirski
2015-07-21 23:36 ` Willy Tarreau
2015-07-21 23:40 ` Andy Lutomirski
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=55AEFA3C.3020006@oracle.com \
--to=boris.ostrovsky@oracle.com \
--cc=andrew.cooper3@citrix.com \
--cc=bp@alien8.de \
--cc=jbeulich@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=luto@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=sasha.levin@oracle.com \
--cc=security@kernel.org \
--cc=stable@vger.kernel.org \
--cc=x86@kernel.org \
--cc=xen-devel@lists.xen.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).