From: Ingo Molnar <mingo@kernel.org>
To: Thomas Garnier <thgarnie@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>,
Andrey Ryabinin <aryabinin@virtuozzo.com>,
Alexander Potapenko <glider@google.com>,
Dmitry Vyukov <dvyukov@google.com>,
Kees Cook <keescook@chromium.org>,
Andy Lutomirski <luto@kernel.org>,
Arjan van de Ven <arjan@linux.intel.com>,
Paul Gortmaker <paul.gortmaker@windriver.com>,
Borislav Petkov <bp@suse.de>,
Andy Lutomirski <luto@amacapital.net>,
"Rafael J . Wysocki" <rjw@rjwysocki.net>,
Len Brown <len.brown@intel.com>, Pavel Machek <pavel@ucw.cz>,
Jiri Kosina <jikos@kernel.org>,
Matt Fleming <matt@codeblueprint.co.uk>,
Ard Biesheuvel <ard.biesheuvel@linaro.org>,
Boris Ostrovsky <boris.ostrovsky@oracle.com>,
Juergen Gross <jgross@suse.com>,
Rusty Russell <rusty@rustcorp.com.au>,
Christian Borntraeger <borntraeger@de.ibm.com>,
Fenghua Yu <fenghua.yu@intel.com>H
Subject: Re: [PATCH v2 3/3] x86: Make the GDT remapping read-only on 64 bit
Date: Wed, 1 Feb 2017 10:15:34 +0100 [thread overview]
Message-ID: <20170201091534.GA25025@gmail.com> (raw)
In-Reply-To: <20170126165940.30799-3-thgarnie@google.com>
* Thomas Garnier <thgarnie@google.com> wrote:
> This patch makes the GDT remapped pages read-only to prevent corruption.
> This change is done only on 64 bit.
Please spell '64-bit' consistently through the series. I've seen two variants:
64 bit
64bit
> +/*
> + * The LTR instruction marks the TSS GDT entry as busy. In 64bit, the GDT is
> + * a read-only remapping. To prevent a page fault, the GDT is switched to the
> + * original writeable version when needed.
s/In 64bit,
/On 64-bit kernels,
> + */
> +#ifdef CONFIG_X86_64
> +static inline void native_load_tr_desc(void)
> +{
> + struct desc_ptr gdt;
> + int cpu = raw_smp_processor_id();
> + bool restore = false;
> + struct desc_struct *fixmap_gdt;
> +
> + native_store_gdt(&gdt);
> + fixmap_gdt = get_cpu_fixmap_gdt(cpu);
> +
> + /*
> + * If the current GDT is the read-only fixmap, swap to the original
> + * writeable version. Swap back at the end.
> + */
> + if (gdt.address == (unsigned long)fixmap_gdt) {
> + load_direct_gdt(cpu);
> + restore = true;
> + }
> + asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
> + if (restore)
> + load_fixmap_gdt(cpu);
Please use bool plus 0/1, it's more readable (to me) than the true/false notation.
> extern void switch_to_new_gdt(int);
> +extern void load_direct_gdt(int);
> extern void load_fixmap_gdt(int);
> +/* Load the original GDT from the per-cpu structure */
> +void load_direct_gdt(int cpu)
> +{
> + struct desc_ptr gdt_descr;
> +
> + gdt_descr.address = (long)get_cpu_direct_gdt(cpu);
Please name the functions in an easier to understand way, such as:
get_cpu_gdt_rw()
get_cpu_gdt_ro()
that the GDT is in the direct mappings is less important than the fact the the
address is writable ...
> +}
> +EXPORT_SYMBOL(load_direct_gdt);
EXPORT_SYMBOL_GPL(), or no export at all.
> +EXPORT_SYMBOL(load_fixmap_gdt);
ditto.
> * VT restores TR but not its size. Useless.
> */
> - struct desc_ptr *gdt = this_cpu_ptr(&host_gdt);
> struct desc_struct *descs;
>
> - descs = (void *)gdt->address;
> + descs = (void *)get_current_direct_gdt();
Couldn't the type cast be dropped?
>
> - table_base = gdt->address;
> + table_base = (unsigned long)get_current_direct_gdt();
Instead of spreading these type casts far and wide please introduce another
accessor the returns 'unsigned long':
get_cpu_gdt_rw_vaddr()
or such.
Thanks,
Ingo
next prev parent reply other threads:[~2017-02-01 9:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-26 16:59 [PATCH v2 1/3] x86/mm: Adapt MODULES_END based on Fixmap section size Thomas Garnier
2017-01-26 16:59 ` [PATCH v2 2/3] x86: Remap GDT tables in the Fixmap section Thomas Garnier
2017-01-26 18:52 ` Andy Lutomirski
2017-01-26 19:10 ` Thomas Garnier
2017-01-26 16:59 ` [PATCH v2 3/3] x86: Make the GDT remapping read-only on 64 bit Thomas Garnier
2017-02-01 9:15 ` Ingo Molnar [this message]
2017-02-02 5:13 ` Andy Lutomirski
2017-02-02 7:12 ` Ingo Molnar
2017-02-02 5:14 ` Andy Lutomirski
2017-02-06 22:10 ` Thomas Garnier
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=20170201091534.GA25025@gmail.com \
--to=mingo@kernel.org \
--cc=ard.biesheuvel@linaro.org \
--cc=arjan@linux.intel.com \
--cc=aryabinin@virtuozzo.com \
--cc=boris.ostrovsky@oracle.com \
--cc=borntraeger@de.ibm.com \
--cc=bp@suse.de \
--cc=dvyukov@google.com \
--cc=fenghua.yu@intel.com \
--cc=glider@google.com \
--cc=hpa@zytor.com \
--cc=jgross@suse.com \
--cc=jikos@kernel.org \
--cc=keescook@chromium.org \
--cc=len.brown@intel.com \
--cc=luto@amacapital.net \
--cc=luto@kernel.org \
--cc=matt@codeblueprint.co.uk \
--cc=mingo@redhat.com \
--cc=paul.gortmaker@windriver.com \
--cc=pavel@ucw.cz \
--cc=rjw@rjwysocki.net \
--cc=rusty@rustcorp.com.au \
--cc=tglx@linutronix.de \
--cc=thgarnie@google.com \
/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).