Patch "arm64: SW PAN: Point saved ttbr0 at the zero page when switching to init_mm" has been added to the 4.14-stable tree
Subsystems (3)
This is a note to let you know that I've just added the patch titled
arm64: SW PAN: Point saved ttbr0 at the zero page when switching to init_mm
to the 4.14-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
arm64-sw-pan-point-saved-ttbr0-at-the-zero-page-when-switching-to-init_mm.patch
and it can be found in the queue-4.14 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
0adbdfde8cfc9415aeed2a4955d2d17b3bd9bf13Mon Sep 17 00:00:00 2001
From: Will Deacon <[email protected]>
Date: Wed, 6 Dec 2017 10:42:10 +0000
Subject: arm64: SW PAN: Point saved ttbr0 at the zero page when switching to init_mm
From: Will Deacon <[email protected]>
commit 0adbdfde8cfc9415aeed2a4955d2d17b3bd9bf13 upstream.
update_saved_ttbr0 mandates that mm->pgd is not swapper, since swapper contains kernel mappings and should never be installed into ttbr0. However, this means that callers must avoid passing the init_mm to update_saved_ttbr0 which in turn can cause the saved ttbr0 value to be out-of-date in the context of the idle thread. For example, EFI runtime services may leave the saved ttbr0 pointing at the EFI page table, and kernel threads may end up with stale references to freed page tables.
This patch changes update_saved_ttbr0 so that the init_mm points the saved ttbr0 value to the empty zero page, which always exists and never contains valid translations. EFI and switch can then call into update_saved_ttbr0 unconditionally.
--- arch/arm64/include/asm/efi.h | 4 +--- arch/arm64/include/asm/mmu_context.h | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-)
arch/arm64/include/asm/efi.h +1 -3
@@ -132,11 +132,9 @@ static inline void efi_set_pgd(struct mm* Defer the switch to the current thread's TTBR0_EL1 * until uaccess_enable(). Restore the current * thread's saved ttbr0 corresponding to its active_mm -* (if different from init_mm). */ cpu_set_reserved_ttbr0 (); -if (current->active_mm != &init_mm) -update_saved_ttbr0 (current, current->active_mm); +update_saved_ttbr0 (current, current->active_mm); } } }
arch/arm64/include/asm/mmu_context.h +13 -9
@@ -174,11 +174,17 @@ enter_lazy_tlb(struct mm_struct *mm, strstatic inline void update_saved_ttbr0 (struct task_struct *tsk,struct mm_struct *mm) { -if (system_uses_ttbr0_pan ()) { -BUG_ON (mm->pgd == swapper_pg_dir); -task_thread_info (tsk)->ttbr0 = -virt_to_phys (mm->pgd) |ASID (mm) <<48 ; - } +u64 ttbr; + +if (!system_uses_ttbr0_pan ()) +return ; + +if (mm == &init_mm) + ttbr =__pa_symbol (empty_zero_page); +else + ttbr =virt_to_phys (mm->pgd) |ASID (mm) <<48 ; + +task_thread_info (tsk)->ttbr0 = ttbr; }#else static inline void update_saved_ttbr0(struct task_struct *tsk,
@@ -214,11 +220,9 @@ switch_mm(struct mm_struct *prev, struct* Update the saved TTBR0_EL1 of the scheduled-in task as the previous * value may have not been initialised yet (activate_mm caller) or the * ASID has changed since the last run (following the context switch -* of another thread of the same process). Avoid setting the reserved -* TTBR0_EL1 to swapper_pg_dir (init_mm; e.g. via idle_task_exit). +* of another thread of the same process). */ -if (next != &init_mm) -update_saved_ttbr0 (tsk, next); +update_saved_ttbr0 (tsk, next); }#define deactivate_mm (tsk,mm) do { } while (0)
Patches currently in stable-queue which might be from [email protected] are
queue-4.14/arm64-sw-pan-update-saved-ttbr0-value-on-enter_lazy_tlb.patch queue-4.14/arm64-sw-pan-point-saved-ttbr0-at-the-zero-page-when-switching-to-init_mm.patch queue-4.14/arm64-fpsimd-prevent-registers-leaking-from-dead-tasks.patch