Thread (11 messages) 11 messages, 3 authors, 2017-06-08

[PATCH v2 1/2] arm64: ftrace: don't validate branch via PLT in ftrace_make_nop()

flat view
STALE3422d SUPERSEDED

From: Will Deacon <hidden>
Date: 2017-06-05 17:15:52

Revision v2 of 7 in this series.

Revisions (7)
  1. v1 [diff vs current]
  2. v2
  3. v2 current
  4. v2
  5. v3 [diff vs current]
  6. v3 [diff vs current]
  7. v3 [diff vs current]
On Tue, May 30, 2017 at 01:52:19PM +0000, Ard Biesheuvel wrote:
quoted hunk ↗ jump to hunk
When turning branch instructions into NOPs, we attempt to validate the
action by comparing the old value at the call site with the opcode of
a direct relative branch instruction pointing at the old target.

However, these call sites are statically initialized to call _mcount(),
and may be redirected via a PLT entry if the module is loaded far away
from the kernel text, leading to false negatives and spurious errors.

So skip the validation if CONFIG_ARM64_MODULE_PLTS is configured.

Signed-off-by: Ard Biesheuvel <redacted>
---
 arch/arm64/kernel/ftrace.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c
index 40ad08ac569a..a8db6857cad6 100644
--- a/arch/arm64/kernel/ftrace.c
+++ b/arch/arm64/kernel/ftrace.c
@@ -84,12 +84,15 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec,
 		    unsigned long addr)
 {
 	unsigned long pc = rec->ip;
-	u32 old, new;
+	u32 old = 0, new;
 
-	old = aarch64_insn_gen_branch_imm(pc, addr, AARCH64_INSN_BRANCH_LINK);
+	if (!IS_ENABLED(CONFIG_ARM64_MODULE_PLTS))
+		old = aarch64_insn_gen_branch_imm(pc, addr,
+						  AARCH64_INSN_BRANCH_LINK);
 	new = aarch64_insn_gen_nop();
 
-	return ftrace_modify_code(pc, old, new, true);
+	return ftrace_modify_code(pc, old, new,
+				  !IS_ENABLED(CONFIG_ARM64_MODULE_PLTS));
Even in the case of PLTs, the instruction is still a branch instruction,
so could we validate the basic opcode fields rather than disable the check
altogether?

Will
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help