Commit 4e29d248 authored by Hugh Dickins's avatar Hugh Dickins Committed by Kleber Sacilotto de Souza

kaiser: kaiser_flush_tlb_on_return_to_user() check PCID

Let kaiser_flush_tlb_on_return_to_user() do the X86_FEATURE_PCID
check, instead of each caller doing it inline first: nobody needs
to optimize for the noPCID case, it's clearer this way, and better
suits later changes.  Replace those no-op X86_CR3_PCID_KERN_FLUSH lines
by a BUILD_BUG_ON() in load_new_mm_cr3(), in case something changes.
Acked-by: default avatarJiri Kosina <jkosina@suse.cz>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>

CVE-2017-5754
Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 044b622e
...@@ -159,7 +159,7 @@ static inline void __native_flush_tlb(void) ...@@ -159,7 +159,7 @@ static inline void __native_flush_tlb(void)
* back: * back:
*/ */
preempt_disable(); preempt_disable();
if (kaiser_enabled && this_cpu_has(X86_FEATURE_PCID)) if (kaiser_enabled)
kaiser_flush_tlb_on_return_to_user(); kaiser_flush_tlb_on_return_to_user();
native_write_cr3(native_read_cr3()); native_write_cr3(native_read_cr3());
preempt_enable(); preempt_enable();
...@@ -216,7 +216,7 @@ static inline void __native_flush_tlb_single(unsigned long addr) ...@@ -216,7 +216,7 @@ static inline void __native_flush_tlb_single(unsigned long addr)
*/ */
if (!this_cpu_has(X86_FEATURE_INVPCID_SINGLE)) { if (!this_cpu_has(X86_FEATURE_INVPCID_SINGLE)) {
if (kaiser_enabled && this_cpu_has(X86_FEATURE_PCID)) if (kaiser_enabled)
kaiser_flush_tlb_on_return_to_user(); kaiser_flush_tlb_on_return_to_user();
asm volatile("invlpg (%0)" ::"r" (addr) : "memory"); asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
return; return;
......
...@@ -436,12 +436,12 @@ void kaiser_setup_pcid(void) ...@@ -436,12 +436,12 @@ void kaiser_setup_pcid(void)
/* /*
* Make a note that this cpu will need to flush USER tlb on return to user. * Make a note that this cpu will need to flush USER tlb on return to user.
* Caller checks whether this_cpu_has(X86_FEATURE_PCID) before calling: * If cpu does not have PCID, then the NOFLUSH bit will never have been set.
* if cpu does not, then the NOFLUSH bit will never have been set.
*/ */
void kaiser_flush_tlb_on_return_to_user(void) void kaiser_flush_tlb_on_return_to_user(void)
{ {
this_cpu_write(x86_cr3_pcid_user, if (this_cpu_has(X86_FEATURE_PCID))
this_cpu_write(x86_cr3_pcid_user,
X86_CR3_PCID_USER_FLUSH | KAISER_SHADOW_PGD_OFFSET); X86_CR3_PCID_USER_FLUSH | KAISER_SHADOW_PGD_OFFSET);
} }
EXPORT_SYMBOL(kaiser_flush_tlb_on_return_to_user); EXPORT_SYMBOL(kaiser_flush_tlb_on_return_to_user);
...@@ -41,7 +41,7 @@ static void load_new_mm_cr3(pgd_t *pgdir) ...@@ -41,7 +41,7 @@ static void load_new_mm_cr3(pgd_t *pgdir)
{ {
unsigned long new_mm_cr3 = __pa(pgdir); unsigned long new_mm_cr3 = __pa(pgdir);
if (kaiser_enabled && this_cpu_has(X86_FEATURE_PCID)) { if (kaiser_enabled) {
/* /*
* We reuse the same PCID for different tasks, so we must * We reuse the same PCID for different tasks, so we must
* flush all the entries for the PCID out when we change tasks. * flush all the entries for the PCID out when we change tasks.
...@@ -52,10 +52,10 @@ static void load_new_mm_cr3(pgd_t *pgdir) ...@@ -52,10 +52,10 @@ static void load_new_mm_cr3(pgd_t *pgdir)
* do it here, but can only be used if X86_FEATURE_INVPCID is * do it here, but can only be used if X86_FEATURE_INVPCID is
* available - and many machines support pcid without invpcid. * available - and many machines support pcid without invpcid.
* *
* The line below is a no-op: X86_CR3_PCID_KERN_FLUSH is now 0; * If X86_CR3_PCID_KERN_FLUSH actually added something, then it
* but keep that line in there in case something changes. * would be needed in the write_cr3() below - if PCIDs enabled.
*/ */
new_mm_cr3 |= X86_CR3_PCID_KERN_FLUSH; BUILD_BUG_ON(X86_CR3_PCID_KERN_FLUSH);
kaiser_flush_tlb_on_return_to_user(); kaiser_flush_tlb_on_return_to_user();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment