From patchwork Wed Oct 19 08:24:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4575 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp205250wrs; Wed, 19 Oct 2022 01:48:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7CkwJ6stliVXWxW68t/TFi3BGT37lsAw9yY6Z5G/wsuVZBHHhHTjez37HQfo6qxCnWVeRI X-Received: by 2002:a17:903:283:b0:17f:7596:e328 with SMTP id j3-20020a170903028300b0017f7596e328mr7187519plr.56.1666169328347; Wed, 19 Oct 2022 01:48:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666169328; cv=none; d=google.com; s=arc-20160816; b=txtoGBj4hYH5z6usIYVUdpb/M7tXVoNPTDBNl18U6PV2h7jAq13lBtIE9h/EGb+hqX P+INlcppayeEMbspNLQ7NTCG2qbHi5ac0sdPzML1zCAsaH0yMq1YRoREboKIdTlJ26Vg /PAeLUUhEf4WWyVrJDWnnuAgksbrw5SOW7JkFy56ye+0nnFt9nTec/r9Ff6/TtgAuH/b cgeOBTfCYpwLRpidEh/soFKBciuHov5X7va8z1DNHT4j7vzPXTOOCXWhfI8iDwhWeyNl pua1JoE6j4twFgETIAEerUPCCrnxWY0FeMUX6KJ9cWGvkVA35Pm8HXbu/yO9MT6KBrdT dEmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ih/K2NUmVLF3iW/uqIxyeNeXFamF3KjqXdHGTKCImpE=; b=YaYexLELIFSiaUzxjAGFdW6mwIzZlAPvPjfs/0kE7D0lm43NGC9uZ4m/hzZa4RZ38I KlRn1EG3PEWheUKsx9x4M2KKR/iPUWbHpSphWDK8b460fYc6c+e/uX7WyaFdcH0awiOl mRt4qVOZd2tbq67VcP0z9F0mDJkuhEt/Lj1uDPE/X/uL7GU3IcnKLL5M3vTRwJGabb7O QZkuiZXUDj9toCi7ceBCzzmqnEOuF8P7wLbgLBiNfTWgrEdwAqyerdVbFIAQrVhTqKTd zEu/IXC36x+YU295MOKRYpqvRAU1zTA4ywIrEEanTbiVz64gSua9ffinyeZhh3Qwr1hg z1Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bIN9wvWP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s4-20020a170902ea0400b00182631bdf78si9423946plg.222.2022.10.19.01.48.35; Wed, 19 Oct 2022 01:48:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bIN9wvWP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231547AbiJSIsG (ORCPT + 99 others); Wed, 19 Oct 2022 04:48:06 -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 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747105169548804459?= X-GMAIL-MSGID: =?utf-8?q?1747105169548804459?= 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 synthetic 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_ +#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 = (__force const void __user *)addr; + int ret; - return strnlen_user_nofault(uaddr, MAX_STRING_SIZE); + ret = strnlen_user_nofault(uaddr, MAX_STRING_SIZE); + /* + * strnlen_user_nofault returns zero on fault, insert the + * FAULT_STRING when that occurs. + */ + if (ret <= 0) + return strlen(FAULT_STRING) + 1; + return ret; } /* Return the length of string -- including null terminal byte */ @@ -34,7 +44,18 @@ kern_fetch_store_strlen(unsigned long ad len++; } while (c && ret == 0 && len < MAX_STRING_SIZE); - 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 >= 0) { + *(u32 *)dest = make_data_loc(ret, __dest - base); + } else { + strscpy(__dest, FAULT_STRING, len); + ret = strlen(__dest) + 1; + } } /* @@ -55,8 +76,7 @@ kern_fetch_store_string_user(unsigned lo __dest = get_loc_data(dest, base); ret = strncpy_from_user_nofault(__dest, uaddr, maxlen); - if (ret >= 0) - *(u32 *)dest = make_data_loc(ret, __dest - base); + set_data_loc(ret, dest, __dest, base, maxlen); return ret; } @@ -87,8 +107,7 @@ kern_fetch_store_string(unsigned long ad * probing. */ ret = strncpy_from_kernel_nofault(__dest, (void *)addr, maxlen); - if (ret >= 0) - *(u32 *)dest = make_data_loc(ret, __dest - base); + set_data_loc(ret, dest, __dest, base, maxlen); return ret; }