[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] x86/boot: Restrict directmap permissions for .text/.rodata


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 6 Dec 2021 14:58:45 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hthfPL9z/NcdxxnI5ltv4B8p1fDABZ758m7L2Hlcxzk=; b=VNIcTR8ZIpe7W6tSlLH6sIzMN4S/P/avGsO0RLvvRO9IQ+RjsKG8UGnXOaMaBfdPhqxvW9DjnNzhILkcGWufW8BXcPC5qRzdJHwiVjjrd9+4nsXhu9pa7H6a+BJRZtF7wk3hGAzrhxhF1WymdHClWGw1MFviMf4O3n18xnN+d8nPeMqarsL0qK8rF4Vd5ad4TW+44yEUhOJSa9bRUzIPsTsr+CrGAM02Q5yNt3bl6zMwDDbDdHHVti+6z2IOMB9zb0zuPvd+037QmXtjIu0Z0crj1qG08rrbFHuGlz1ZxTr+V/GofUWKP57GdQVTJ7kaO7axsURi5n7KeWpmsbVw9g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T28HLl0dxGvmMLNaBw08HkHX31zYAe3Q6kfYr3wlOp72er5AkY8S0/9wD5cS/+xN67ms6gKUi2rQfIQl5KZvsEHe8Xm2rSkArd6yPAH3Hjr7vOpZfoMVJzKoQv1K3efrAikXELsBNRLR0zBWcWOupPzy3Jb+rCELN+2xYcIT8bLKPw4WMZdO9rnMPpNrZfdRE6HNKtZa4MVWbfwNz4oLzLVJ6HdlUdOLxM1R4DX29CJN3esv0yg1G26RhR7FxxnxaZ7sliUOoqE0LS4sHxXRk4y09rXFg3w3SYHfx07nnoH7juCdchMOSTiGIXj51SLMsNUlo3EyvPA4nKzsYtpFew==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 06 Dec 2021 13:58:58 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 06.12.2021 14:08, Andrew Cooper wrote:
> While we've been diligent to ensure that the main text/data/rodata mappings
> have suitable restrictions, their aliases via the directmap were left fully
> RW.  Worse, we even had pieces of code making use of this as a feature.
> 
> Restrict the permissions, as we have no legitimate need for writeability of
> these areas via the directmap alias.

Where do we end up reading .text and/or .rodata through the directmap? Can't
we zap the mappings altogether?

As to superpage shattering - I understand this is not deemed to be an issue
in the common case since, with Xen moved as high up below 4G as possible,
it wouldn't normally live inside a 1G mapping anyway? This may want calling
out here. Plus, in non-EFI, non-XEN_ALIGN_2M builds isn't this going to
shatter a 2M page at the tail of .rodata?

> Note that the pagetables and cpu0_stack do get written through their directmap
> alias, so we can't just read-only the whole image.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> ---
> CC: Jan Beulich <JBeulich@xxxxxxxx>
> CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
> CC: Wei Liu <wl@xxxxxxx>
> 
> Ever so slightly RFC, as it has only had light testing.
> 
> Notes:
>  * The stubs are still have RX via one alias, RW via another, and these need
>    to stay.  Hardening options include splitting the stubs so the SYSCALL ones
>    can be read-only after setup, and/or expanding the stub size to 4k per CPU
>    so we really can keep the writeable alias as not present when the stub
>    isn't in active use.
>  * Future CPUs with Protection Key Supervisor (Sapphire Rapids and later)
>    would be able to inhibit writeability outside of a permitted region, and
>    because the protection key is per logical thread, we woulnd't need to
>    expand the stubs to 4k per CPU.

I'm afraid I don't follow: The keys still apply to entire pages, don't they?
This would still allow write access by all 16 CPUs sharing a page for their
stubs.

>  * At the time of writing, PV Shim still makes use of .rodata's read/write
>    alias in the directmap to patch the hypercall table, but that runs earlier
>    on boot.  Also, there are patches out to address this.

I did consider committing that change, but it wasn't clear to me whether
there were dependencies on earlier parts of the series that it's part of.

>  * For backporting, this patch depends on c/s e7f147bf4ac7 ("x86/crash: Drop
>    manual hooking of exception_table[]"), and nothing would break at compile
>    time if the dependency was missing.

Hmm, not nice. I'm likely to forget if we would indeed decide to backport
the one here.

Jan




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.