From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933224AbcIEJ7I (ORCPT ); Mon, 5 Sep 2016 05:59:08 -0400 Received: from foss.arm.com ([217.140.101.70]:50798 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933141AbcIEJ67 (ORCPT ); Mon, 5 Sep 2016 05:58:59 -0400 From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com, marc.zyngier@arm.com, mark.rutland@arm.com, james.morse@arm.com, ard.biesheuvel@linaro.org, andre.przywara@arm.com, Suzuki K Poulose Subject: [PATCH v3 4/9] arm64: alternative: Disallow patching instructions using literals Date: Mon, 5 Sep 2016 10:58:24 +0100 Message-Id: <1473069509-2317-5-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473069509-2317-1-git-send-email-suzuki.poulose@arm.com> References: <1473069509-2317-1-git-send-email-suzuki.poulose@arm.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- arch/arm64/kernel/alternative.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c index 4434dab..992918d 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; -- 2.7.4