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>,
"He Chen" <he.chen@linux.intel.com>,
"Brian Gerst" <brgerst@gmail.com>,
"Luis R . Rodriguez" <mcgrof@kernel.org>,
"Adam Buchbinder" <adam.buchbinder@gmail.com>,
"Stanislaw Gruszka" <sgruszka@redhat.com>,
"Arnd Bergmann" <arnd@arndb.de>,
"Dave Hansen" <dave.hansen@intel.com>,
"Chen Yucong" <slaoub@gmail.com>,
"Vitaly Kuznetsov" <vkuznets@redhat.com>,
"David Vrabel" <david.vrabel@citrix.com>,
"Josh Poimboeuf" <jpoimboe@redhat.com>,
"Tim Chen" <tim.c.chen@linux.intel.com>,
"Rik van Riel" <riel@redhat.com>,
"Andi Kleen" <ak@linux.intel.com>, "Jiri Olsa" <jolsa@redhat.com>,
"Prarit Bhargava" <prarit@redhat.com>,
"Michael Ellerman" <mpe@ellerman.id.au>,
"Joerg Roedel" <joro@8bytes.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Radim Krčmář" <rkrcmar@redhat.com>,
x86@kernel.org, linux-kernel@vger.kernel.org,
kasan-dev@googlegroups.com, linux-pm@vger.kernel.org,
linux-efi@vger.kernel.org, xen-devel@lists.xenproject.org,
lguest@lists.ozlabs.org, kvm@vger.kernel.org,
kernel-hardening@lists.openwall.com
Subject: [kernel-hardening] 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
WARNING: multiple messages have this Message-ID (diff)
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
WARNING: multiple messages have this Message-ID (diff)
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: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-26 16:59 [kernel-hardening] [PATCH v2 1/3] x86/mm: Adapt MODULES_END based on Fixmap section size Thomas Garnier
2017-01-26 16:59 ` Thomas Garnier
2017-01-26 16:59 ` Thomas Garnier
2017-01-26 16:59 ` Thomas Garnier
2017-01-26 16:59 ` [kernel-hardening] [PATCH v2 2/3] x86: Remap GDT tables in the Fixmap section Thomas Garnier
2017-01-26 16:59 ` Thomas Garnier
2017-01-26 16:59 ` Thomas Garnier
2017-01-26 16:59 ` Thomas Garnier
2017-01-26 18:52 ` [kernel-hardening] " Andy Lutomirski
2017-01-26 18:52 ` Andy Lutomirski
2017-01-26 19:10 ` [kernel-hardening] " Thomas Garnier
2017-01-26 19:10 ` Thomas Garnier
2017-01-26 19:10 ` Thomas Garnier
2017-01-26 18:52 ` Andy Lutomirski
2017-01-26 16:59 ` Thomas Garnier
2017-01-26 16:59 ` [PATCH v2 3/3] x86: Make the GDT remapping read-only on 64 bit Thomas Garnier
2017-01-26 16:59 ` [kernel-hardening] " Thomas Garnier
2017-01-26 16:59 ` Thomas Garnier
2017-01-26 16:59 ` Thomas Garnier
2017-01-26 16:59 ` Thomas Garnier
2017-02-01 9:15 ` Ingo Molnar
2017-02-01 9:15 ` Ingo Molnar [this message]
2017-02-01 9:15 ` Ingo Molnar
2017-02-01 9:15 ` Ingo Molnar
2017-02-02 5:13 ` [kernel-hardening] " Andy Lutomirski
2017-02-02 5:13 ` Andy Lutomirski
2017-02-02 5:13 ` Andy Lutomirski
2017-02-02 7:12 ` Ingo Molnar
2017-02-02 7:12 ` [kernel-hardening] " Ingo Molnar
2017-02-02 7:12 ` Ingo Molnar
2017-02-02 7:12 ` Ingo Molnar
2017-02-02 5:13 ` Andy Lutomirski
2017-02-02 5:14 ` Andy Lutomirski
2017-02-02 5:14 ` [kernel-hardening] " Andy Lutomirski
2017-02-02 5:14 ` Andy Lutomirski
2017-02-06 22:10 ` [kernel-hardening] " Thomas Garnier
2017-02-06 22:10 ` Thomas Garnier
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=adam.buchbinder@gmail.com \
--cc=ak@linux.intel.com \
--cc=ard.biesheuvel@linaro.org \
--cc=arjan@linux.intel.com \
--cc=arnd@arndb.de \
--cc=aryabinin@virtuozzo.com \
--cc=boris.ostrovsky@oracle.com \
--cc=borntraeger@de.ibm.com \
--cc=bp@suse.de \
--cc=brgerst@gmail.com \
--cc=dave.hansen@intel.com \
--cc=david.vrabel@citrix.com \
--cc=dvyukov@google.com \
--cc=fenghua.yu@intel.com \
--cc=glider@google.com \
--cc=he.chen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jgross@suse.com \
--cc=jikos@kernel.org \
--cc=jolsa@redhat.com \
--cc=joro@8bytes.org \
--cc=jpoimboe@redhat.com \
--cc=kasan-dev@googlegroups.com \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=kvm@vger.kernel.org \
--cc=len.brown@intel.com \
--cc=lguest@lists.ozlabs.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=luto@kernel.org \
--cc=matt@codeblueprint.co.uk \
--cc=mcgrof@kernel.org \
--cc=mingo@redhat.com \
--cc=mpe@ellerman.id.au \
--cc=paul.gortmaker@windriver.com \
--cc=pavel@ucw.cz \
--cc=pbonzini@redhat.com \
--cc=prarit@redhat.com \
--cc=riel@redhat.com \
--cc=rjw@rjwysocki.net \
--cc=rkrcmar@redhat.com \
--cc=rusty@rustcorp.com.au \
--cc=sgruszka@redhat.com \
--cc=slaoub@gmail.com \
--cc=tglx@linutronix.de \
--cc=thgarnie@google.com \
--cc=tim.c.chen@linux.intel.com \
--cc=vkuznets@redhat.com \
--cc=x86@kernel.org \
--cc=xen-devel@lists.xenproject.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.