Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp469159yba; Wed, 15 May 2019 04:40:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqxS17KodGOrKMFHuPVs+aN5j95aq+536ykHKT5oCu7zUcuM1qHc9KrfmWvgTUpbvJShvtWL X-Received: by 2002:a17:902:2e81:: with SMTP id r1mr27399257plb.0.1557920425823; Wed, 15 May 2019 04:40:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557920425; cv=none; d=google.com; s=arc-20160816; b=h7A+HEc2I43kGmq2AdImn1ufUdvQAlhg+Mfsp7mDR7Izz28WFxggcikkyGIgsE31gh cFNdoSZIrZFdFVlVP7SEVwzZZgXRdzMkbYTHKYqtECRplnTFTwaMJnPms3Tc3RlmROU6 ovCO9d36RBIG4MwurrLP6kqLoORzVvvlZLLJsug+HlA85Nz6Burdsx794bN+0S5y9n3o JKQQ7T5tiPdAt4mLJo4UvnNSB32pO8vBQhRIyZ0V3ca+IbDx1orMkCzdEmvPUaj69HfM 6nlNq3or3YbpHuwkY/ZGBXUPGwIi4XrUaqSJ40U8X4o4eu77bJvb+ZQ0nQSJ6DmUjHiO 619Q== 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=YyQZe4nys94wzLeg3IOC0PfzKSSq5DG/JN6hIBAWix4=; b=De0FmresIpOtXtVrRMaVkubctGdlXTNNaqAMLSYNJYidnaadgR8N7Kao/5RRe846FY Jq1wqnF6JZapNEeSgYMzrTLHrH8xCSFTAvjdXY8nES9bVawSIzIGNnUOgMONnKKmcQI8 JcKOs7aLX3YRvLHRe+/WuXyYRepIu8kHvmiGZRRsUWL7nSCW0LtbOYRhcSWAuWnVlhZr zg1Wkd9D+Em0Q9U78xyGmdnpWmryeR6+F7vMqbcYcpW/+ZusA9MIqxHZNVn1vGD3c5zA cKaMb+EzfdQLS5A2QR8aR2WarbfJbnsja+wvbNtCmyJqRppr6ax4GC2Rj29G0/ZZvheB ek8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pxOo5PDk; 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 v20si1571954pgb.361.2019.05.15.04.40.11; Wed, 15 May 2019 04:40:25 -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=pxOo5PDk; 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 S1732860AbfEOLbL (ORCPT + 99 others); Wed, 15 May 2019 07:31:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:42832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732853AbfEOLbI (ORCPT ); Wed, 15 May 2019 07:31:08 -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 ADC9B20818; Wed, 15 May 2019 11:31:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919868; bh=HPW5qmyRt0MdAlds3D8UJxzus/kCZ4tCYnDPQSWmvT0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pxOo5PDkOIZwuRvt2KQf2RRKwy6gcW3GL+Mm2mRu2jcVuallK7aat1nEQVHZBsOds nSvvBb+84MujqwYbehSCHytW9mZLQNfIJaMcspTkSRhIfamxyOzNT134xrMwvwLAjs ZEty/yZQGpMMC+0BUHCkSZgnv0A/9Do/BH/EVwJ8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Will Deacon , dann frazier , Ard Biesheuvel , Catalin Marinas , Sasha Levin Subject: [PATCH 5.0 080/137] arm64/module: ftrace: deal with place relative nature of PLTs Date: Wed, 15 May 2019 12:56:01 +0200 Message-Id: <20190515090659.277259384@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090651.633556783@linuxfoundation.org> References: <20190515090651.633556783@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 [ Upstream commit 4e69ecf4da1ee0b2ac735e1f1bb13935acd5a38d ] Another bodge for the ftrace PLT code: plt_entries_equal() now takes the place relative nature of the ADRP/ADD based PLT entries into account, which means that a struct trampoline instance on the stack is no longer equal to the same set of opcodes in the module struct, given that they don't point to the same place in memory anymore. Work around this by using memcmp() in the ftrace PLT handling code. Acked-by: Will Deacon Tested-by: dann frazier Signed-off-by: Ard Biesheuvel Signed-off-by: Catalin Marinas Signed-off-by: Sasha Levin --- arch/arm64/kernel/ftrace.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c index 07b2981201820..65a51331088eb 100644 --- a/arch/arm64/kernel/ftrace.c +++ b/arch/arm64/kernel/ftrace.c @@ -103,10 +103,15 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) * to be revisited if support for multiple ftrace entry points * is added in the future, but for now, the pr_err() below * deals with a theoretical issue only. + * + * Note that PLTs are place relative, and plt_entries_equal() + * checks whether they point to the same target. Here, we need + * to check if the actual opcodes are in fact identical, + * regardless of the offset in memory so use memcmp() instead. */ trampoline = get_plt_entry(addr, mod->arch.ftrace_trampoline); - if (!plt_entries_equal(mod->arch.ftrace_trampoline, - &trampoline)) { + if (memcmp(mod->arch.ftrace_trampoline, &trampoline, + sizeof(trampoline))) { 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; -- 2.20.1