From nobody Sat Oct 18 02:15:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57BBCC4332F for ; Wed, 19 Oct 2022 08:48:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231550AbiJSIsI (ORCPT ); Wed, 19 Oct 2022 04:48:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231513AbiJSIrj (ORCPT ); Wed, 19 Oct 2022 04:47:39 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A0E087692; Wed, 19 Oct 2022 01:45:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 043E261806; Wed, 19 Oct 2022 08:45:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F7A4C433D6; Wed, 19 Oct 2022 08:45:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169116; bh=a6b1NSqvH/b6gAlJZYFh0Q5qf/RCTEE7cuX29pmcyhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bIN9wvWP3+7+snNcRWMUYsXUXU6tYakCF6UVe+YUcEvJwaHWA98GJLZNWqSyLMGvG TziSD+qsZItV3p0vd8cEygBkndL6I3uyCAb3sE11z1YZy9oQ7Rr4jntMZ37SqXuW1u NsSjqzYE6hlltAiHQQwo60fgGMjFlvGsMk9CAca4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrew Morton , Tom Zanussi , "Masami Hiramatsu (Google)" , "Steven Rostedt (Google)" Subject: [PATCH 6.0 164/862] tracing: Add "(fault)" name injection to kernel probes Date: Wed, 19 Oct 2022 10:24:11 +0200 Message-Id: <20221019083257.216516812@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Steven Rostedt (Google) commit 2e9906f84fc7c99388bb7123ade167250d50f1c0 upstream. Have the specific functions for kernel probes that read strings to inject the "(fault)" name directly. trace_probes.c does this too (for uprobes) but as the code to read strings are going to be used by synthetic events (and perhaps other utilities), it simplifies the code by making sure those other uses do not need to implement the "(fault)" name injection as well. Link: https://lkml.kernel.org/r/20221012104534.644803645@goodmis.org Cc: stable@vger.kernel.org Cc: Andrew Morton Cc: Tom Zanussi Acked-by: Masami Hiramatsu (Google) Reviewed-by: Tom Zanussi Fixes: bd82631d7ccdc ("tracing: Add support for dynamic strings to syntheti= c events") Signed-off-by: Steven Rostedt (Google) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace_probe_kernel.h | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) --- a/kernel/trace/trace_probe_kernel.h +++ b/kernel/trace/trace_probe_kernel.h @@ -2,6 +2,8 @@ #ifndef __TRACE_PROBE_KERNEL_H_ #define __TRACE_PROBE_KERNEL_H_ =20 +#define FAULT_STRING "(fault)" + /* * This depends on trace_probe.h, but can not include it due to * the way trace_probe_tmpl.h is used by trace_kprobe.c and trace_eprobe.c. @@ -13,8 +15,16 @@ static nokprobe_inline int kern_fetch_store_strlen_user(unsigned long addr) { const void __user *uaddr =3D (__force const void __user *)addr; + int ret; =20 - return strnlen_user_nofault(uaddr, MAX_STRING_SIZE); + ret =3D strnlen_user_nofault(uaddr, MAX_STRING_SIZE); + /* + * strnlen_user_nofault returns zero on fault, insert the + * FAULT_STRING when that occurs. + */ + if (ret <=3D 0) + return strlen(FAULT_STRING) + 1; + return ret; } =20 /* Return the length of string -- including null terminal byte */ @@ -34,7 +44,18 @@ kern_fetch_store_strlen(unsigned long ad len++; } while (c && ret =3D=3D 0 && len < MAX_STRING_SIZE); =20 - return (ret < 0) ? ret : len; + /* For faults, return enough to hold the FAULT_STRING */ + return (ret < 0) ? strlen(FAULT_STRING) + 1 : len; +} + +static nokprobe_inline void set_data_loc(int ret, void *dest, void *__dest= , void *base, int len) +{ + if (ret >=3D 0) { + *(u32 *)dest =3D make_data_loc(ret, __dest - base); + } else { + strscpy(__dest, FAULT_STRING, len); + ret =3D strlen(__dest) + 1; + } } =20 /* @@ -55,8 +76,7 @@ kern_fetch_store_string_user(unsigned lo __dest =3D get_loc_data(dest, base); =20 ret =3D strncpy_from_user_nofault(__dest, uaddr, maxlen); - if (ret >=3D 0) - *(u32 *)dest =3D make_data_loc(ret, __dest - base); + set_data_loc(ret, dest, __dest, base, maxlen); =20 return ret; } @@ -87,8 +107,7 @@ kern_fetch_store_string(unsigned long ad * probing. */ ret =3D strncpy_from_kernel_nofault(__dest, (void *)addr, maxlen); - if (ret >=3D 0) - *(u32 *)dest =3D make_data_loc(ret, __dest - base); + set_data_loc(ret, dest, __dest, base, maxlen); =20 return ret; }