From patchwork Mon Apr 15 19:01:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 162255 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp3302558jan; Mon, 15 Apr 2019 12:13:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxJ9Rihi2PPXdskDXEuJyENh1bVU9D0dVkfWj41JQ+wz7BqA8QNBucXJYUhsWjEIXN3F29 X-Received: by 2002:a62:1701:: with SMTP id 1mr78272481pfx.120.1555355639797; Mon, 15 Apr 2019 12:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555355639; cv=none; d=google.com; s=arc-20160816; b=tx3s4dCU0Hvz5ISldrDhN1cvHsX00A8W/Yyvs6ibfVwg0vtWjAZGql+oEUJQOxQEuv FlvzhL4leTLfG2Yfi4sU+Gd8MFUtOHyB4PzBKnIrUCwxJHnOOdzeAmo0OnxuKqeyd7kM tyu1uMlW6Fo6wx8pBDSoyl1Q0H1hgv0IRKhoktw75GceA1veVlCgYiAZCPT0JDY1Wm4w gm3/JbrBiDnqm309Y2XUo4PGpIRsbNifbUS56kN47QBcx2NRUx4EcqSzIWPkTGHbpG0M 1fKnXPDtYSYbiejHf9O/z7n/+y525K2/8cB2HTQhyz0HI0pgOwEKEjXjJFV4r4R+5nmb wSow== 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 124si41209128pgi.38.2019.04.15.12.13.59; Mon, 15 Apr 2019 12:13:59 -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 S1731667AbfDOTN6 (ORCPT + 30 others); Mon, 15 Apr 2019 15:13:58 -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 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; }