Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2524192yba; Mon, 15 Apr 2019 13:33:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqzSZMYfbCeTKffGyrEQqv4PBQP5dyCVMlzqEZd3ahObsLO6/91nA08kbXbxjn/Qj92S4EnM X-Received: by 2002:a62:4d43:: with SMTP id a64mr11670367pfb.174.1555360381595; Mon, 15 Apr 2019 13:33:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555360381; cv=none; d=google.com; s=arc-20160816; b=kBHIrzHFYRku1G9KIwrJ7dX/ZPTB0/rjQFN4LkuTy7O6K1wZBChROGe4CqHHRWiWST 859QSp1T9IoN0TkU+poajjXtzsJHFwkYFvAd4MoC6TEPsc9PnSUlblYJ+Tzpv86zAEzs McO1fjLT+Fnuf3cmC2HLk6MIT2JitdM5n+T+jIzw/HhY+R+N3BXtE2cRjWm5taAX3YDG xdm7M1MSXqIPper4WLzO7BQIKd9uVxt/l8SjMMIe3JrNrWKDHC0yC9JQP6mn6WhcuqvM ClVv6OXydqb5phfpozdAi4rCjfr6xqOfwF5S7oQ78g5HJk0JEP0cCKbl4mKSPyIMs8jv Yxqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=h3nNsQZcffwCcn0boM97aIG0DtM1Hs8SKVH6uINC4Rc=; b=qala/t8J9guJHt7S/d/gWfzqcaj8fmeLZOHE+jpkk1UFnG6jZ9Xb+0ezHpaX+w91bP +rYXNPBNmd4LynazEqm1Xtxzt2ABIoX+WdBohc+7+W1mIj6Gd89vAzphAjP/v/WUaYID Idl7BGT6xNlNnJLzNksa3WhQioQuDKiI9BNy04ktDuJnBtNto51w6lfOBh7eyD5yi+Bc qd1Vq5VPEeJd9tPaUncZSQ/SsD+yebBpDN14KNqeHbBpBREnx6Y6/Eg3k27gv9gKLQJ5 UG6qUFHgF6zWaOBfj9sJkq7ZkbXAS6eePem0eeySbFQ2H8kpB4ISECMo4ZSwXPm2649B 1nYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=osLex4tW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si21752337pgq.268.2019.04.15.13.32.45; Mon, 15 Apr 2019 13:33:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=osLex4tW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731663AbfDOTN5 (ORCPT + 99 others); Mon, 15 Apr 2019 15:13:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:51942 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731655AbfDOTNz (ORCPT ); Mon, 15 Apr 2019 15:13:55 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B6A9520880; Mon, 15 Apr 2019 19:13:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555355635; bh=5YL+rWJV1VY0G7h6sA/ONOHxtJlgO2PM6OISqDGaYH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=osLex4tWBcirSQgsjgffGOz+pXGVIEeygzgH34XHYe9z2/3gN2sl9cTc3iVLkTak1 6d1gk/ZQdbn+o3phfw2xz9m10m28HIZFQZ89ViWi3G5sclB6Sm7t73CRRlG8/3H9M4 69SCP3UXuMgv2N7h6LwFJd4E1570VqzV9uJbzguw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Rutland , Ard Biesheuvel , Will Deacon Subject: [PATCH 5.0 095/117] arm64/ftrace: fix inadvertent BUG() in trampoline check Date: Mon, 15 Apr 2019 21:01:05 +0200 Message-Id: <20190415183749.669767123@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183744.887851196@linuxfoundation.org> References: <20190415183744.887851196@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel commit 5a3ae7b314a2259b1188b22b392f5eba01e443ee upstream. The ftrace trampoline code (which deals with modules loaded out of BL range of the core kernel) uses plt_entries_equal() to check whether the per-module trampoline equals a zero buffer, to decide whether the trampoline has already been initialized. This triggers a BUG() in the opcode manipulation code, since we end up checking the ADRP offset of a 0x0 opcode, which is not an ADRP instruction. So instead, add a helper to check whether a PLT is initialized, and call that from the frace code. Cc: # v5.0 Fixes: bdb85cd1d206 ("arm64/module: switch to ADRP/ADD sequences for PLT entries") Acked-by: Mark Rutland Signed-off-by: Ard Biesheuvel Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/module.h | 5 +++++ arch/arm64/kernel/ftrace.c | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) --- a/arch/arm64/include/asm/module.h +++ b/arch/arm64/include/asm/module.h @@ -73,4 +73,9 @@ static inline bool is_forbidden_offset_f struct plt_entry get_plt_entry(u64 dst, void *pc); bool plt_entries_equal(const struct plt_entry *a, const struct plt_entry *b); +static inline bool plt_entry_is_initialized(const struct plt_entry *e) +{ + return e->adrp || e->add || e->br; +} + #endif /* __ASM_MODULE_H */ --- a/arch/arm64/kernel/ftrace.c +++ b/arch/arm64/kernel/ftrace.c @@ -107,8 +107,7 @@ int ftrace_make_call(struct dyn_ftrace * trampoline = get_plt_entry(addr, mod->arch.ftrace_trampoline); if (!plt_entries_equal(mod->arch.ftrace_trampoline, &trampoline)) { - if (!plt_entries_equal(mod->arch.ftrace_trampoline, - &(struct plt_entry){})) { + if (plt_entry_is_initialized(mod->arch.ftrace_trampoline)) { pr_err("ftrace: far branches to multiple entry points unsupported inside a single module\n"); return -EINVAL; }