From nobody Fri Dec 19 04:01:19 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5409F4C96 for ; Wed, 26 Feb 2025 01:05:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740531937; cv=none; b=Sn1QRZSrZfGY8Jrpm52JdxoCyETE1pdhnZalr5gK5Ug3D3cD0bakuUra+TVZIIu8+vC0P8CraJJSVoGRGcnsv1H9ytgcvuj3/M5IBmeyL//Q/e2/tFrSdyyemHDm5Olh0KmaoSNwTuRnTsJ4hqjCOXivkGReLmCbxfX6mdqJMaQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740531937; c=relaxed/simple; bh=X6zLOLeQZJjOVQdhs+fZU6VdfZOuMQ2OC0ArLkxixdM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=D18kyYLw42bHu4KI76FPNIXbZqsvrkAqy0Iq8FRpoLy/Y27TSfXlW9tAJVJPAXIQ1497qDW9s8dY7k3Ub0ftu5s8jtQoka6/cIis4KFd2Nheo6eiI4fRP6KoYu/MdaT+6jKuTF5JBNEKfX/BjrjTxIuELEIoLmOV9mU/JekaEok= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEFD6C4CEE6; Wed, 26 Feb 2025 01:05:36 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tn5sO-00000009EYl-2RGr; Tue, 25 Feb 2025 20:06:16 -0500 Message-ID: <20250226010616.432688791@goodmis.org> User-Agent: quilt/0.68 Date: Tue, 25 Feb 2025 20:05:57 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Masahiro Yamada , Catalin Marinas , Will Deacon , Mark Brown , Nathan Chancellor , "Arnd Bergmann" Subject: [for-next][PATCH 1/4] ftrace: Test mcount_loc addr before calling ftrace_call_addr() References: <20250226010556.526552688@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The addresses in the mcount_loc can be zeroed and then moved by KASLR making them invalid addresses. ftrace_call_addr() for ARM 64 expects a valid address to kernel text. If the addr read from the mcount_loc section is invalid, it must not call ftrace_call_addr(). Move the addr check before calling ftrace_call_addr() in ftrace_process_locs(). Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Masahiro Yamada Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Brown Link: https://lore.kernel.org/20250225182054.290128736@goodmis.org Fixes: ef378c3b8233 ("scripts/sorttable: Zero out weak functions in mcount_= loc table") Reported-by: Nathan Chancellor Reported-by: "Arnd Bergmann" Tested-by: Nathan Chancellor Closes: https://lore.kernel.org/all/20250225025631.GA271248@ax162/ Closes: https://lore.kernel.org/all/91523154-072b-437b-bbdc-0b70e9783fd0@ap= p.fastmail.com/ Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 27c8def2139d..183f72cf15ed 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -7063,7 +7063,9 @@ static int ftrace_process_locs(struct module *mod, pg =3D start_pg; while (p < end) { unsigned long end_offset; - addr =3D ftrace_call_adjust(*p++); + + addr =3D *p++; + /* * Some architecture linkers will pad between * the different mcount_loc sections of different @@ -7075,6 +7077,8 @@ static int ftrace_process_locs(struct module *mod, continue; } =20 + addr =3D ftrace_call_adjust(addr); + end_offset =3D (pg->index+1) * sizeof(pg->records[0]); if (end_offset > PAGE_SIZE << pg->order) { /* We should have allocated enough */ --=20 2.47.2