Skip to content

Commit 5b48ba2

Browse files
committed
powerpc/64s: Fix stf mitigation patching w/strict RWX & hash
The stf entry barrier fallback is unsafe to execute in a semi-patched state, which can happen when enabling/disabling the mitigation with strict kernel RWX enabled and using the hash MMU. See the previous commit for more details. Fix it by changing the order in which we patch the instructions. Note the stf barrier fallback is only used on Power6 or earlier. Fixes: bd573a8 ("powerpc/mm/64s: Allow STRICT_KERNEL_RWX again") Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 49b39ec commit 5b48ba2

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

arch/powerpc/lib/feature-fixups.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,17 @@ static void do_stf_entry_barrier_fixups(enum stf_barrier_type types)
150150

151151
pr_devel("patching dest %lx\n", (unsigned long)dest);
152152

153-
patch_instruction((struct ppc_inst *)dest, ppc_inst(instrs[0]));
154-
155-
if (types & STF_BARRIER_FALLBACK)
153+
// See comment in do_entry_flush_fixups() RE order of patching
154+
if (types & STF_BARRIER_FALLBACK) {
155+
patch_instruction((struct ppc_inst *)dest, ppc_inst(instrs[0]));
156+
patch_instruction((struct ppc_inst *)(dest + 2), ppc_inst(instrs[2]));
156157
patch_branch((struct ppc_inst *)(dest + 1),
157-
(unsigned long)&stf_barrier_fallback,
158-
BRANCH_SET_LINK);
159-
else
160-
patch_instruction((struct ppc_inst *)(dest + 1),
161-
ppc_inst(instrs[1]));
162-
163-
patch_instruction((struct ppc_inst *)(dest + 2), ppc_inst(instrs[2]));
158+
(unsigned long)&stf_barrier_fallback, BRANCH_SET_LINK);
159+
} else {
160+
patch_instruction((struct ppc_inst *)(dest + 1), ppc_inst(instrs[1]));
161+
patch_instruction((struct ppc_inst *)(dest + 2), ppc_inst(instrs[2]));
162+
patch_instruction((struct ppc_inst *)dest, ppc_inst(instrs[0]));
163+
}
164164
}
165165

166166
printk(KERN_DEBUG "stf-barrier: patched %d entry locations (%s barrier)\n", i,

0 commit comments

Comments
 (0)