Skip to content

Commit 5679b28

Browse files
ardbiesheuvelwilldeacon
authored andcommitted
arm64/alternatives: don't patch up internal branches
Commit f7b93d4 ("arm64/alternatives: use subsections for replacement sequences") moved the alternatives replacement sequences into subsections, in order to keep the as close as possible to the code that they replace. Unfortunately, this broke the logic in branch_insn_requires_update, which assumed that any branch into kernel executable code was a branch that required updating, which is no longer the case now that the code sequences that are patched in are in the same section as the patch site itself. So the only way to discriminate branches that require updating and ones that don't is to check whether the branch targets the replacement sequence itself, and so we can drop the call to kernel_text_address() entirely. Fixes: f7b93d4 ("arm64/alternatives: use subsections for replacement sequences") Reported-by: Alexandru Elisei <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Tested-by: Alexandru Elisei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 09c717c commit 5679b28

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

arch/arm64/kernel/alternative.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,8 @@ bool alternative_is_applied(u16 cpufeature)
4343
*/
4444
static bool branch_insn_requires_update(struct alt_instr *alt, unsigned long pc)
4545
{
46-
unsigned long replptr;
47-
48-
if (kernel_text_address(pc))
49-
return true;
50-
51-
replptr = (unsigned long)ALT_REPL_PTR(alt);
52-
if (pc >= replptr && pc <= (replptr + alt->alt_len))
53-
return false;
54-
55-
/*
56-
* Branching into *another* alternate sequence is doomed, and
57-
* we're not even trying to fix it up.
58-
*/
59-
BUG();
46+
unsigned long replptr = (unsigned long)ALT_REPL_PTR(alt);
47+
return !(pc >= replptr && pc <= (replptr + alt->alt_len));
6048
}
6149

6250
#define align_down(x, a) ((unsigned long)(x) & ~(((unsigned long)(a)) - 1))

0 commit comments

Comments
 (0)