From: Suzuki K Poulose Date: Fri, 9 Sep 2016 13:07:11 +0000 (+0100) Subject: arm64: alternative: Disallow patching instructions using literals X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=baa763b565386b1383b87b6fb76e72db84a0ff16;p=linux-beck.git arm64: alternative: Disallow patching instructions using literals The alternative code patching doesn't check if the replaced instruction uses a pc relative literal. This could cause silent corruption in the instruction stream as the instruction will be executed from a different address than what it was compiled for. Catch all such cases. Cc: Marc Zyngier Cc: Andre Przywara Cc: Mark Rutland Cc: Catalin Marinas Suggested-by: Will Deacon Signed-off-by: Suzuki K Poulose Signed-off-by: Will Deacon --- diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c index 4434dabde898..992918dfbe2d 100644 --- a/arch/arm64/kernel/alternative.c +++ b/arch/arm64/kernel/alternative.c @@ -79,6 +79,12 @@ static u32 get_alt_insn(struct alt_instr *alt, u32 *insnptr, u32 *altinsnptr) offset = target - (unsigned long)insnptr; insn = aarch64_set_branch_offset(insn, offset); } + } else if (aarch64_insn_uses_literal(insn)) { + /* + * Disallow patching unhandled instructions using PC relative + * literal addresses + */ + BUG(); } return insn;