From patchwork Sun Jul 2 14:47:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 13299207 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 54143EB64DA for ; Sun, 2 Jul 2023 14:47:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229844AbjGBOrY (ORCPT ); Sun, 2 Jul 2023 10:47:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229820AbjGBOrX (ORCPT ); Sun, 2 Jul 2023 10:47:23 -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 9103DE6D; Sun, 2 Jul 2023 07:47:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 703C160AFF; Sun, 2 Jul 2023 14:47:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8124C433C8; Sun, 2 Jul 2023 14:47:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688309240; bh=0j3BWNbc1EuIzI14t2vLiSWuYOrWEhCXmtAiUJ1Ieoo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=avuKLwDiBbU6kUUkcFm26n8F33qwy3lyQ8+OM6g9oGJNosVoWfqr8R10IgOgo33to Lkv7JiLodUnnObnxXu/0TpGawQt+iZmt4Daxy8Gl8dWnwqbrWyalRkduBrMWcCEt7c riQNKq97VuyWOf2EkIEth0A2B1mHVW1GiDcyRI+hc2CVppG9PCa2b9ZPRb9lK0GG2P /2C2RuNl1Tzyt76V8S+cENV66ve16/0mJbzBTNxQSn+EOkWDDVPLrSCa2FyqJo1xyu LnYUs5ZkaDz7NUzKyfzt0F/1SVNLGm6KDwviaWtc548yyiAnF5gd/JHZQxQsQUXfbx uxNN+utxDH5oQ== From: "Masami Hiramatsu (Google)" To: Steven Rostedt Cc: Dan Carpenter , linux-trace-kernel@vger.kernel.org, LKML , Masami Hiramatsu Subject: [PATCH 1/3] tracing/probes: Fix to avoid double count of the string length on the array Date: Sun, 2 Jul 2023 23:47:17 +0900 Message-ID: <168830923752.2278819.12200306485001986374.stgit@mhiramat.roam.corp.google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog In-Reply-To: <168830922841.2278819.9165254236027770818.stgit@mhiramat.roam.corp.google.com> References: <168830922841.2278819.9165254236027770818.stgit@mhiramat.roam.corp.google.com> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org From: Masami Hiramatsu (Google) If an array is specified with the ustring or symstr, the length of the strings are accumlated on both of 'ret' and 'total', which means the length is double counted. Just set the length to the 'ret' value to aviod double count. Reported-by: Dan Carpenter Closes: https://lore.kernel.org/all/8819b154-2ba1-43c3-98a2-cbde20892023@moroto.mountain/ Fixes: 88903c464321 ("tracing/probe: Add ustring type for user-space string") Cc: stable@vger.kernel.org Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Steven Rostedt (Google) --- kernel/trace/trace_probe_tmpl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h index 00707630788d..4735c5cb76fa 100644 --- a/kernel/trace/trace_probe_tmpl.h +++ b/kernel/trace/trace_probe_tmpl.h @@ -156,11 +156,11 @@ process_fetch_insn_bottom(struct fetch_insn *code, unsigned long val, code++; goto array; case FETCH_OP_ST_USTRING: - ret += fetch_store_strlen_user(val + code->offset); + ret = fetch_store_strlen_user(val + code->offset); code++; goto array; case FETCH_OP_ST_SYMSTR: - ret += fetch_store_symstrlen(val + code->offset); + ret = fetch_store_symstrlen(val + code->offset); code++; goto array; default: From patchwork Sun Jul 2 14:47:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 13299208 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 CCDEEEB64D9 for ; Sun, 2 Jul 2023 14:47:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbjGBOre (ORCPT ); Sun, 2 Jul 2023 10:47:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229863AbjGBOrc (ORCPT ); Sun, 2 Jul 2023 10:47:32 -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 1330AE7C; Sun, 2 Jul 2023 07:47:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 81B9660C23; Sun, 2 Jul 2023 14:47:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FA09C433C7; Sun, 2 Jul 2023 14:47:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688309249; bh=2jfrAoMO9/kQoKHT25bmipL2nxynNXAFTeOpPLGh8dM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MJeyzMvOtAY5zLGziIGZvukiqdPzsdAlcxcsGQtg1x9cK0Xkw4L0FFJWz1hqk82Vp CkNfsJFTRYIrJ3ilEnPTjV5keLJXkfEGrvIJWGx9fNWewLCn1VcEikNnYxIJUs3Qmz ZcsJZ4qMwy5QSKjPx6ABgueXEO4uasH/hkgKqDoZsIWCtQor8+wrBSXuaw4d12XZQ8 wdDBqmxGXDT4Or9edVsXSv6ajFmQeLHUHQ7/xDpNYx1a9A+nCbC9hJFz6/GCtaaAfZ gjs8DD66vWxyH3bvQ79yQdwiCLwxQ/OvhWY7Di9MO5VOe9KqiOsxtFRyjctp33BHsR rda1JADnnpKmg== From: "Masami Hiramatsu (Google)" To: Steven Rostedt Cc: Dan Carpenter , linux-trace-kernel@vger.kernel.org, LKML , Masami Hiramatsu Subject: [PATCH 2/3] tracing/probes: Fix to exit fetching if an error is detected Date: Sun, 2 Jul 2023 23:47:26 +0900 Message-ID: <168830924625.2278819.7022958622963157629.stgit@mhiramat.roam.corp.google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog In-Reply-To: <168830922841.2278819.9165254236027770818.stgit@mhiramat.roam.corp.google.com> References: <168830922841.2278819.9165254236027770818.stgit@mhiramat.roam.corp.google.com> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org From: Masami Hiramatsu (Google) Fix to exit fetching arguments if an error is detected when storing strings. Without this fix, if an array is specified with string types it may store the data at the wrong address. Reported-by: Dan Carpenter Closes: https://lore.kernel.org/all/8819b154-2ba1-43c3-98a2-cbde20892023@moroto.mountain/ Fixes: 9b960a38835f ("tracing: probeevent: Unify fetch_insn processing common part") Cc: stable@vger.kernel.org Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Steven Rostedt (Google) --- kernel/trace/trace_probe_tmpl.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h index 4735c5cb76fa..d6f2bf69f9bc 100644 --- a/kernel/trace/trace_probe_tmpl.h +++ b/kernel/trace/trace_probe_tmpl.h @@ -193,6 +193,8 @@ process_fetch_insn_bottom(struct fetch_insn *code, unsigned long val, default: return -EILSEQ; } + if (ret < 0) + return ret; code++; /* 4th stage: modify stored value if needed */ From patchwork Sun Jul 2 14:47:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 13299209 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 413DAEB64D9 for ; Sun, 2 Jul 2023 14:47:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229756AbjGBOrv (ORCPT ); Sun, 2 Jul 2023 10:47:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229754AbjGBOru (ORCPT ); Sun, 2 Jul 2023 10:47:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50945E5E; Sun, 2 Jul 2023 07:47:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E0E2260C2C; Sun, 2 Jul 2023 14:47:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 577A6C433CB; Sun, 2 Jul 2023 14:47:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688309258; bh=YM6t77hkrmL0BQ4fCrPPMAXrOgv5IQjPa1agd03fP70=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZAJv7+bSjNkfj3L2nXyNjhcy/BxEBu9FTQlSatczbFtOg2/U4+IOT0Q5G+jZ7Gwp0 8br1UiPmexAvFkKepIeq+BHXRm34QM7uAcbDZLAXQzMPIUxXpVd3yz+FEDUP2D31uT ifZRTotfXmdnv/oG8/vN3yht+H+v8cu+KY1afvHB7GjtCfZ1oLraoNvrmuNwACqveh NcLqFAIQV7UWGD45KskndizDCZ007dQ+0Of/TvnX21oWBw95EimjBbDyghdPqgSy70 bEut4WLCgQG/xWwDWxv0xE0eipXo0txH/jUnc/A7T1rDZSR8BBPmaGUkpulMWAn0h8 1EqLwGQhISZjQ== From: "Masami Hiramatsu (Google)" To: Steven Rostedt Cc: Dan Carpenter , linux-trace-kernel@vger.kernel.org, LKML , Masami Hiramatsu Subject: [PATCH 3/3] tracing/probes: Fix return value when "(fault)" is injected Date: Sun, 2 Jul 2023 23:47:35 +0900 Message-ID: <168830925534.2278819.7237772177111801959.stgit@mhiramat.roam.corp.google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog In-Reply-To: <168830922841.2278819.9165254236027770818.stgit@mhiramat.roam.corp.google.com> References: <168830922841.2278819.9165254236027770818.stgit@mhiramat.roam.corp.google.com> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org From: Masami Hiramatsu (Google) When the "(fault)" is injected, the return value of fetch_store_string*() should be the length of the "(fault)", but an error code is returned. Fix it to return the correct length and update the data_loc according the updated length. This needs to update a ftracetest test case, which expects trace output to appear as '(fault)' instead of '"(fault)"'. Fixes: 2e9906f84fc7 ("tracing: Add "(fault)" name injection to kernel probes") Cc: stable@vger.kernel.org Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Steven Rostedt (Google) --- kernel/trace/trace_probe_kernel.h | 17 +++++++---------- .../ftrace/test.d/kprobe/kprobe_args_user.tc | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/kernel/trace/trace_probe_kernel.h b/kernel/trace/trace_probe_kernel.h index c4e1d4c03a85..63d90fe4eb87 100644 --- a/kernel/trace/trace_probe_kernel.h +++ b/kernel/trace/trace_probe_kernel.h @@ -48,14 +48,15 @@ fetch_store_strlen(unsigned long addr) 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) +static nokprobe_inline int 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 { + if (ret < 0) { strscpy(__dest, FAULT_STRING, len); ret = strlen(__dest) + 1; } + + *(u32 *)dest = make_data_loc(ret, __dest - base); + return ret; } /* @@ -76,9 +77,7 @@ fetch_store_string_user(unsigned long addr, void *dest, void *base) __dest = get_loc_data(dest, base); ret = strncpy_from_user_nofault(__dest, uaddr, maxlen); - set_data_loc(ret, dest, __dest, base, maxlen); - - return ret; + return set_data_loc(ret, dest, __dest, base, maxlen); } /* @@ -107,9 +106,7 @@ fetch_store_string(unsigned long addr, void *dest, void *base) * probing. */ ret = strncpy_from_kernel_nofault(__dest, (void *)addr, maxlen); - set_data_loc(ret, dest, __dest, base, maxlen); - - return ret; + return set_data_loc(ret, dest, __dest, base, maxlen); } static nokprobe_inline int diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc index d25d01a19778..8dcc0b29bd36 100644 --- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc +++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_user.tc @@ -29,6 +29,6 @@ echo 1 > events/kprobes/myevent/enable ln -s foo $TMPDIR/bar echo 0 > events/kprobes/myevent/enable -grep myevent trace | grep -q 'path=(fault) path2=(fault)' +grep myevent trace | grep -q 'path="*(fault)"* path2="*(fault)"*' exit 0