Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp467979ybl; Tue, 28 Jan 2020 06:26:15 -0800 (PST) X-Google-Smtp-Source: APXvYqwvo9nCiIA9HHoXgR5OYzor3EWOH6k5SwAtRIppy4ElQigNe3Wjp0PMDtJh6/j1qaKkfXjX X-Received: by 2002:a54:4e1e:: with SMTP id a30mr2944636oiy.53.1580221575253; Tue, 28 Jan 2020 06:26:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580221575; cv=none; d=google.com; s=arc-20160816; b=Wqm1R7P2f4U1jlNiaOFjzXR+BK13HAfNBRDfj39UvPAdqyvDD+FXerp6Mfl+cnkKpf fkZnolGvMJgOgUO8kAn4l4GbVY/dsaUeJaN7fdvstp+7RGgbVo5bCAYCzt+Lq/ZG+RjK 3UGG9CHfWqEMQO/C/uFLy29ETndvgl9irtxql96eZ17eyVhlN0ocgy/O4z4GGFbpThPc FHcEy4cZs1OVfr4ODlHFRToY6pOFN+vpNK9d+Jo8a9e/nwP69b0NoH5MSI9eeSDVZEbz RnxrcI1E/YXAKJWhFb8PSglcwsPywCHbmZMr2j9gqdcTG+M9aBuTGi7Tx4sLGNHIm+JN CB8w== 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=CGDA87n5/GEG85K/MjE1MryHH/AzHTeUmWJfXiA4drI=; b=WBVceCXBIpt6aVlMuUmHhcvJIj/Ce1Zt4UNMr8ZYLvsS1jdprir+BJH873DNX2PD+N Iv3QGT5soPgGW8y36sO+XUBX3SvrEfxAxaT+pmtDzV3bvo/0VW5B50I5uVyfcdVwvxPS Wv3weyi6/uiubZHLy9xEpue+todX/fpyyNlqyCNvdsW0AHT6tBJX3CfCXL57J5NWAhpB zsivnXAvemQpCfWiu1GqCYqAJKOk+vdo5fYHOLYzjKvJuaUh2uxF6SPiPJDI+qBXBoyS ytX80zEE5dSqcnbMgd//YJ+ERLbPYFjKAFoT14Acvu0/9HDUtqSujlIWGpSCmsWaYojj EIEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="O/MEhx2C"; 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 u8si9103745otq.262.2020.01.28.06.26.03; Tue, 28 Jan 2020 06:26:15 -0800 (PST) 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="O/MEhx2C"; 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 S1732836AbgA1OZF (ORCPT + 99 others); Tue, 28 Jan 2020 09:25:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:51928 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732826AbgA1OZA (ORCPT ); Tue, 28 Jan 2020 09:25:00 -0500 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 A1B742469B; Tue, 28 Jan 2020 14:24:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580221500; bh=yrkzuQLtBjcqycYZGfBIaMYVhUulDyg+nPbXXZm5KEM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O/MEhx2CFyjYg/KMTECiAD0Mc4XFfBN/XoP5jnUSBy0TX6hXZmBbVGBIbjfdm18uo ueq0NyelkYr2aDWrmknGi+lSghZ6+kjrq4X+QSQBMFtPSIgtTzZCKXFZ6MBU8HOhn2 hQIb2L+uen257MmWWLvEeNf4tnwHWNKfctKyNEmA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Sverdlin , "Steven Rostedt (VMware)" , Russell King Subject: [PATCH 4.9 249/271] ARM: 8950/1: ftrace/recordmcount: filter relocation types Date: Tue, 28 Jan 2020 15:06:38 +0100 Message-Id: <20200128135911.090815558@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128135852.449088278@linuxfoundation.org> References: <20200128135852.449088278@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: Alex Sverdlin commit 927d780ee371d7e121cea4fc7812f6ef2cea461c upstream. Scenario 1, ARMv7 ================= If code in arch/arm/kernel/ftrace.c would operate on mcount() pointer the following may be generated: 00000230 : 230: b5f8 push {r3, r4, r5, r6, r7, lr} 232: b500 push {lr} 234: f7ff fffe bl 0 <__gnu_mcount_nc> 234: R_ARM_THM_CALL __gnu_mcount_nc 238: f240 0600 movw r6, #0 238: R_ARM_THM_MOVW_ABS_NC __gnu_mcount_nc 23c: f8d0 1180 ldr.w r1, [r0, #384] ; 0x180 FTRACE currently is not able to deal with it: WARNING: CPU: 0 PID: 0 at .../kernel/trace/ftrace.c:1979 ftrace_bug+0x1ad/0x230() ... CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.4.116-... #1 ... [] (unwind_backtrace) from [] (show_stack+0x11/0x14) [] (show_stack) from [] (dump_stack+0x81/0xa8) [] (dump_stack) from [] (warn_slowpath_common+0x69/0x90) [] (warn_slowpath_common) from [] (warn_slowpath_null+0x17/0x1c) [] (warn_slowpath_null) from [] (ftrace_bug+0x1ad/0x230) [] (ftrace_bug) from [] (ftrace_process_locs+0x27d/0x444) [] (ftrace_process_locs) from [] (ftrace_init+0x91/0xe8) [] (ftrace_init) from [] (start_kernel+0x34b/0x358) [] (start_kernel) from [<00308095>] (0x308095) ---[ end trace cb88537fdc8fa200 ]--- ftrace failed to modify [] prealloc_fixed_plts+0x8/0x60 actual: 44:f2:e1:36 ftrace record flags: 0 (0) expected tramp: c03143e9 Scenario 2, ARMv4T ================== ftrace: allocating 14435 entries in 43 pages ------------[ cut here ]------------ WARNING: CPU: 0 PID: 0 at kernel/trace/ftrace.c:2029 ftrace_bug+0x204/0x310 CPU: 0 PID: 0 Comm: swapper Not tainted 4.19.5 #1 Hardware name: Cirrus Logic EDB9302 Evaluation Board [] (unwind_backtrace) from [] (show_stack+0x20/0x2c) [] (show_stack) from [] (dump_stack+0x20/0x30) [] (dump_stack) from [] (__warn+0xdc/0x104) [] (__warn) from [] (warn_slowpath_null+0x4c/0x5c) [] (warn_slowpath_null) from [] (ftrace_bug+0x204/0x310) [] (ftrace_bug) from [] (ftrace_init+0x3b4/0x4d4) [] (ftrace_init) from [] (start_kernel+0x20c/0x410) [] (start_kernel) from [<00000000>] ( (null)) ---[ end trace 0506a2f5dae6b341 ]--- ftrace failed to modify [] perf_trace_sys_exit+0x5c/0xe8 actual: 1e:ff:2f:e1 Initializing ftrace call sites ftrace record flags: 0 (0) expected tramp: c000fb24 The analysis for this problem has been already performed previously, refer to the link below. Fix the above problems by allowing only selected reloc types in __mcount_loc. The list itself comes from the legacy recordmcount.pl script. Link: https://lore.kernel.org/lkml/56961010.6000806@pengutronix.de/ Cc: stable@vger.kernel.org Fixes: ed60453fa8f8 ("ARM: 6511/1: ftrace: add ARM support for C version of recordmcount") Signed-off-by: Alexander Sverdlin Acked-by: Steven Rostedt (VMware) Signed-off-by: Russell King Signed-off-by: Greg Kroah-Hartman --- scripts/recordmcount.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) --- a/scripts/recordmcount.c +++ b/scripts/recordmcount.c @@ -53,6 +53,10 @@ #define R_AARCH64_ABS64 257 #endif +#define R_ARM_PC24 1 +#define R_ARM_THM_CALL 10 +#define R_ARM_CALL 28 + static int fd_map; /* File descriptor for file being modified. */ static int mmap_failed; /* Boolean flag. */ static char gpfx; /* prefix for global symbol name (sometimes '_') */ @@ -374,6 +378,18 @@ is_mcounted_section_name(char const *con #define RECORD_MCOUNT_64 #include "recordmcount.h" +static int arm_is_fake_mcount(Elf32_Rel const *rp) +{ + switch (ELF32_R_TYPE(w(rp->r_info))) { + case R_ARM_THM_CALL: + case R_ARM_CALL: + case R_ARM_PC24: + return 0; + } + + return 1; +} + /* 64-bit EM_MIPS has weird ELF64_Rela.r_info. * http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf * We interpret Table 29 Relocation Operation (Elf64_Rel, Elf64_Rela) [p.40] @@ -463,6 +479,7 @@ do_file(char const *const fname) break; case EM_ARM: reltype = R_ARM_ABS32; altmcount = "__gnu_mcount_nc"; + is_fake_mcount32 = arm_is_fake_mcount; break; case EM_AARCH64: reltype = R_AARCH64_ABS64;