From patchwork Tue Jul 11 14:15:29 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: 13308800 X-Patchwork-Delegate: mhiramat@kernel.org 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 82D92EB64DD for ; Tue, 11 Jul 2023 14:15:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233395AbjGKOPi (ORCPT ); Tue, 11 Jul 2023 10:15:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233436AbjGKOPf (ORCPT ); Tue, 11 Jul 2023 10:15:35 -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 0083F1705; Tue, 11 Jul 2023 07:15:33 -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 8BF106150D; Tue, 11 Jul 2023 14:15:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2FA8C433C7; Tue, 11 Jul 2023 14:15:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689084933; bh=77y8W85i7xf9qeyXJXcSDIyy5bcBOPvmg0r6OCuWIr4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jHrQijNug8+1yMpULTBzLmTy8i0AMW+NL0U/e2Us3ej9u//1v3DYXBC7a4V8tCFRo pzyk4QOXnXIYS7Bbe4mk4QRqcUlMaa0mUxgwgesOQjGgCP+i9LxMUl2QKtlAgxgeZp czdq6gFzuItu72NyNQ8nwMqKroV3rkPQS80FELKMeO1gsrb7mMElll388oU+banh8E ANvyuKqU4cNSmb3D0OBDToFcoi9pIkFOsG/nFvNWs+Knv3eMrV4qXdtYk+lLBoKv4m n+aG6k8FuzW23nRTIHmxPLKrV3lKpqabhjuZeMw+g+dcg9wMepidCyIK/6JluZHKCD EpqRXj++kRvqw== From: "Masami Hiramatsu (Google)" To: Steven Rostedt Cc: Dan Carpenter , linux-trace-kernel@vger.kernel.org, LKML , Masami Hiramatsu Subject: [PATCH v5 1/5] tracing/probes: Fix to avoid double count of the string length on the array Date: Tue, 11 Jul 2023 23:15:29 +0900 Message-Id: <168908492917.123124.15076463491122036025.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <168908491977.123124.16583481716284477889.stgit@devnote2> References: <168908491977.123124.16583481716284477889.stgit@devnote2> 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 for avoiding double counting. 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 Tue Jul 11 14:15:38 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: 13308801 X-Patchwork-Delegate: mhiramat@kernel.org 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 33718EB64DD for ; Tue, 11 Jul 2023 14:15:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233327AbjGKOPp (ORCPT ); Tue, 11 Jul 2023 10:15:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233445AbjGKOPo (ORCPT ); Tue, 11 Jul 2023 10:15:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79870B0; Tue, 11 Jul 2023 07:15:43 -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 16C1D6150D; Tue, 11 Jul 2023 14:15:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0848FC433C8; Tue, 11 Jul 2023 14:15:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689084942; bh=B/xbZAcfESero9MbnK8hn07jc1YnxzqHt+73/OKFhoI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tsqVZDBrt4sxiMKWtpCFTvByTQZFO7mAdGegliLhzJXs15V7YqWsqgnHerRcec5U+ Q/aaehktA8TSQGy3P2IRj2d9B6EYVTJ+OCKfI/Tfo17m6Rqe1hWpQQW6gLX9r7YOzV VeakEbJVbz9A5ixmsRtkWbHgzaYCL5u/Y7fFK/4vK2ugWUfhC94NjpyxXdz0df++TV 6Zqq6oeZmITh9QUwuYUDk8+gH+gny3tsYjFJqtLbbAFf99Us4d5y94mShmPB1DbFXl ggzQkydSW+OAFgriURtQRzGL9eaRhw2gcBBwwp+58HckLCUKp+XJm+/88Uiegq+3y2 vRhEWB1Io84fA== From: "Masami Hiramatsu (Google)" To: Steven Rostedt Cc: Dan Carpenter , linux-trace-kernel@vger.kernel.org, LKML , Masami Hiramatsu Subject: [PATCH v5 2/5] tracing/probes: Fix not to count error code to total length Date: Tue, 11 Jul 2023 23:15:38 +0900 Message-Id: <168908493827.123124.2175257289106364229.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <168908491977.123124.16583481716284477889.stgit@devnote2> References: <168908491977.123124.16583481716284477889.stgit@devnote2> 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 not to count the error code (which is minus value) to the total used length of array, because it can mess up the return code of process_fetch_insn_bottom(). Also clear the 'ret' value because it will be used for calculating next data_loc entry. 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..ed9d57c6b041 100644 --- a/kernel/trace/trace_probe_tmpl.h +++ b/kernel/trace/trace_probe_tmpl.h @@ -204,6 +204,8 @@ process_fetch_insn_bottom(struct fetch_insn *code, unsigned long val, array: /* the last stage: Loop on array */ if (code->op == FETCH_OP_LP_ARRAY) { + if (ret < 0) + ret = 0; total += ret; if (++i < code->param) { code = s3; From patchwork Tue Jul 11 14:15:48 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: 13308802 X-Patchwork-Delegate: mhiramat@kernel.org 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 7372FEB64DC for ; Tue, 11 Jul 2023 14:15:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233468AbjGKOP6 (ORCPT ); Tue, 11 Jul 2023 10:15:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232888AbjGKOPy (ORCPT ); Tue, 11 Jul 2023 10:15:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C6C8170A; Tue, 11 Jul 2023 07:15:53 -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 D15646150C; Tue, 11 Jul 2023 14:15:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEEF1C433C8; Tue, 11 Jul 2023 14:15:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689084952; bh=5Y9sWGJd4HJzLogg+iWU8edbrK9/5rH7d1aurm3YzgM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aReD0A+1tRpSeAhG5xZHxoEfgPqj/cIAjHv5Z4zOwhd3S7Z4wLSHzDiwKz3dWmVPB olT6rBr8eKo6yrOVIN/QlfyLwLhToLP9rNvm0gIdSpX9aPA+9Yv/6SL/7J4uqSsMjC zHrhLLgcGapkXdRl+Ga4UB03d368RaOzFaoU+ILQhCICSDUW3gzAxhTD7Lfo+Kuvxt jOoJdydJtXRmH/EoxUaPd5caAnHcUz2ElaFcA6ig8tiPnq09t6IiIXQSMuljQ9RAXQ rXpVzluE6t3+fiwKXb4yON3bOY56bvM08Pj3bzk8blEgezzi7N3HgIcOYDgMs6nFk8 LWHO/woKPxf4A== From: "Masami Hiramatsu (Google)" To: Steven Rostedt Cc: Dan Carpenter , linux-trace-kernel@vger.kernel.org, LKML , Masami Hiramatsu Subject: [PATCH v5 3/5] tracing/probes: Fix to update dynamic data counter if fetcharg uses it Date: Tue, 11 Jul 2023 23:15:48 +0900 Message-Id: <168908494781.123124.8160245359962103684.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <168908491977.123124.16583481716284477889.stgit@devnote2> References: <168908491977.123124.16583481716284477889.stgit@devnote2> 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 update dynamic data counter ('dyndata') and max length ('maxlen') only if the fetcharg uses the dynamic data. Also get out arg->dynamic from unlikely(). This makes dynamic data address wrong if process_fetch_insn() returns error on !arg->dynamic case. Suggested-by: Steven Rostedt Link: https://lore.kernel.org/all/20230710233400.5aaf024e@gandalf.local.home/ Fixes: 9178412ddf5a ("tracing: probeevent: Return consumed bytes of dynamic area") Cc: stable@vger.kernel.org Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Steven Rostedt (Google) --- kernel/trace/trace_probe_tmpl.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h index ed9d57c6b041..185da001f4c3 100644 --- a/kernel/trace/trace_probe_tmpl.h +++ b/kernel/trace/trace_probe_tmpl.h @@ -267,11 +267,13 @@ store_trace_args(void *data, struct trace_probe *tp, void *rec, if (unlikely(arg->dynamic)) *dl = make_data_loc(maxlen, dyndata - base); ret = process_fetch_insn(arg->code, rec, dl, base); - if (unlikely(ret < 0 && arg->dynamic)) { - *dl = make_data_loc(0, dyndata - base); - } else { - dyndata += ret; - maxlen -= ret; + if (arg->dynamic) { + if (unlikely(ret < 0)) { + *dl = make_data_loc(0, dyndata - base); + } else { + dyndata += ret; + maxlen -= ret; + } } } } From patchwork Tue Jul 11 14:15:57 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: 13308803 X-Patchwork-Delegate: mhiramat@kernel.org 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 22436EB64DC for ; Tue, 11 Jul 2023 14:16:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233479AbjGKOQM (ORCPT ); Tue, 11 Jul 2023 10:16:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233484AbjGKOQG (ORCPT ); Tue, 11 Jul 2023 10:16:06 -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 B50FF1708; Tue, 11 Jul 2023 07:16:02 -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 1487F614E2; Tue, 11 Jul 2023 14:16:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FB75C433C9; Tue, 11 Jul 2023 14:16:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689084961; bh=LOMI4wDzsq/hXAQmAMNQ62g25jda2U1iBQmNIJ7a+L8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XYHmYYZtT9DWZF9d0bff3fSO3KXst8iYe5u/AyxO+3aKqfGuNsE4/ihcXTYjwXxPx 3aa9a3hL1//H/yyyNqTEMBy3YTZPMJ2KwuSjX9I6Fk/7HrNXpE+icCGRokFsH+BPY1 +PAN87G7p16i7VECnrs71be8M2bMGTffjNocZwQyD1J/ssIt4YIoGCMHB67U2Q05QA w1sLS0LOxXwA0n3wOCApwFca6rXUruLfxD/EUISDEVzDA43qxKjqOS19nmvZ5Gml9l ft2ZZ7MKL8ilVno+SARlP+TwK+WYrB+DncCyjTHy46S0i7wOhaz9fC/AAFumEtZb1t aDz+ax7OfMICg== From: "Masami Hiramatsu (Google)" To: Steven Rostedt Cc: Dan Carpenter , linux-trace-kernel@vger.kernel.org, LKML , Masami Hiramatsu Subject: [PATCH v5 4/5] Revert "tracing: Add "(fault)" name injection to kernel probes" Date: Tue, 11 Jul 2023 23:15:57 +0900 Message-Id: <168908495772.123124.1250788051922100079.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <168908491977.123124.16583481716284477889.stgit@devnote2> References: <168908491977.123124.16583481716284477889.stgit@devnote2> 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) This reverts commit 2e9906f84fc7c99388bb7123ade167250d50f1c0. It was turned out that commit 2e9906f84fc7 ("tracing: Add "(fault)" name injection to kernel probes") did not work correctly and probe events still show just '(fault)' (instead of '"(fault)"'). Also, current '(fault)' is more explicit that it faulted. This also moves FAULT_STRING macro to trace.h so that synthetic event can keep using it, and uses it in trace_probe.c too. Link: https://lore.kernel.org/all/20230706230642.3793a593@rorschach.local.home/ Cc: stable@vger.kernel.org Cc: Andrew Morton Cc: Tom Zanussi Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Steven Rostedt (Google) --- kernel/trace/trace.h | 2 ++ kernel/trace/trace_probe.c | 2 +- kernel/trace/trace_probe_kernel.h | 31 ++++++------------------------- 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 79bdefe9261b..eee1f3ca4749 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -113,6 +113,8 @@ enum trace_type { #define MEM_FAIL(condition, fmt, ...) \ DO_ONCE_LITE_IF(condition, pr_err, "ERROR: " fmt, ##__VA_ARGS__) +#define FAULT_STRING "(fault)" + #define HIST_STACKTRACE_DEPTH 16 #define HIST_STACKTRACE_SIZE (HIST_STACKTRACE_DEPTH * sizeof(unsigned long)) #define HIST_STACKTRACE_SKIP 5 diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 2d2616678295..591399ddcee5 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -65,7 +65,7 @@ int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, void *data, void *ent) int len = *(u32 *)data >> 16; if (!len) - trace_seq_puts(s, "(fault)"); + trace_seq_puts(s, FAULT_STRING); else trace_seq_printf(s, "\"%s\"", (const char *)get_loc_data(data, ent)); diff --git a/kernel/trace/trace_probe_kernel.h b/kernel/trace/trace_probe_kernel.h index c4e1d4c03a85..6deae2ce34f8 100644 --- a/kernel/trace/trace_probe_kernel.h +++ b/kernel/trace/trace_probe_kernel.h @@ -2,8 +2,6 @@ #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. @@ -15,16 +13,8 @@ static nokprobe_inline int fetch_store_strlen_user(unsigned long addr) { const void __user *uaddr = (__force const void __user *)addr; - int ret; - 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 strnlen_user_nofault(uaddr, MAX_STRING_SIZE); } /* Return the length of string -- including null terminal byte */ @@ -44,18 +34,7 @@ fetch_store_strlen(unsigned long addr) len++; } while (c && ret == 0 && len < MAX_STRING_SIZE); - /* 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; - } + return (ret < 0) ? ret : len; } /* @@ -76,7 +55,8 @@ 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); + if (ret >= 0) + *(u32 *)dest = make_data_loc(ret, __dest - base); return ret; } @@ -107,7 +87,8 @@ 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); + if (ret >= 0) + *(u32 *)dest = make_data_loc(ret, __dest - base); return ret; } From patchwork Tue Jul 11 14:16:07 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: 13308804 X-Patchwork-Delegate: mhiramat@kernel.org 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 3D0F3EB64DC for ; Tue, 11 Jul 2023 14:16:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233358AbjGKOQX (ORCPT ); Tue, 11 Jul 2023 10:16:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231344AbjGKOQP (ORCPT ); Tue, 11 Jul 2023 10:16:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36795170C; Tue, 11 Jul 2023 07:16:12 -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 9E32B61360; Tue, 11 Jul 2023 14:16:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D971EC433C7; Tue, 11 Jul 2023 14:16:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689084971; bh=/AcWrvIXlV70CD4DdIzY6zl/jRyB0t5UfH4qkA2Xy84=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HzBtSrQ0OIc31FCAGpYEiDxSYZ9C7gi2brxAmdhKAjQzFnWncfRIkqSFPwCj/gDiH YyQf+yI7ZnoFasEbnIQS8hkl2puowcYyNIdEniwzrsfvMfRrq6y2Xvu/gSXo0sMCVY Up85DELswwwq+gR6Q8C5RRdXjsEp7ME6tkvLfR/8YCA9pr4KwGeFnF+cfZYdYuzeZL d8W6oLO8uFC8PWIaCYK7wmqVOCuDf0m7kgkFOdgS90shxLRAUnxVDKXbOXySLMXyi2 GDRiUMmEcHEES66mWtk0Lu2PcrnRT8w8c9kJrKGnrFaI146XD5GGJWxfw0BvEV9wKg I9NvDkmTPNK5g== From: "Masami Hiramatsu (Google)" To: Steven Rostedt Cc: Dan Carpenter , linux-trace-kernel@vger.kernel.org, LKML , Masami Hiramatsu Subject: [PATCH v5 5/5] tracing/probes: Fix to record 0-length data_loc in fetch_store_string*() if fails Date: Tue, 11 Jul 2023 23:16:07 +0900 Message-Id: <168908496683.123124.4761206188794205601.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <168908491977.123124.16583481716284477889.stgit@devnote2> References: <168908491977.123124.16583481716284477889.stgit@devnote2> 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 record 0-length data to data_loc in fetch_store_string*() if it fails to get the string data. Currently those expect that the data_loc is updated by store_trace_args() if it returns the error code. However, that does not work correctly if the argument is an array of strings. In that case, store_trace_args() only clears the first entry of the array (which may have no error) and leaves other entries. So it should be cleared by fetch_store_string*() itself. Also, 'dyndata' and 'maxlen' in store_trace_args() should be updated only if it is used (ret > 0 and argument is a dynamic data.) Fixes: 40b53b771806 ("tracing: probeevent: Add array type support") Cc: stable@vger.kernel.org Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Steven Rostedt (Google) --- Changes in v4: - Simplify the updating data_loc code with set_data_loc(). Changes in v5: - Move out arg->dynamic check from unlikely() and use likely(). --- kernel/trace/trace_probe_kernel.h | 13 +++++++++---- kernel/trace/trace_probe_tmpl.h | 10 +++------- kernel/trace/trace_uprobe.c | 3 ++- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/kernel/trace/trace_probe_kernel.h b/kernel/trace/trace_probe_kernel.h index 6deae2ce34f8..bb723eefd7b7 100644 --- a/kernel/trace/trace_probe_kernel.h +++ b/kernel/trace/trace_probe_kernel.h @@ -37,6 +37,13 @@ fetch_store_strlen(unsigned long addr) return (ret < 0) ? ret : len; } +static nokprobe_inline void set_data_loc(int ret, void *dest, void *__dest, void *base) +{ + if (ret < 0) + ret = 0; + *(u32 *)dest = make_data_loc(ret, __dest - base); +} + /* * Fetch a null-terminated string from user. Caller MUST set *(u32 *)buf * with max length and relative data location. @@ -55,8 +62,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); - if (ret >= 0) - *(u32 *)dest = make_data_loc(ret, __dest - base); + set_data_loc(ret, dest, __dest, base); return ret; } @@ -87,8 +93,7 @@ fetch_store_string(unsigned long addr, void *dest, void *base) * 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); return ret; } diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h index 185da001f4c3..3935b347f874 100644 --- a/kernel/trace/trace_probe_tmpl.h +++ b/kernel/trace/trace_probe_tmpl.h @@ -267,13 +267,9 @@ store_trace_args(void *data, struct trace_probe *tp, void *rec, if (unlikely(arg->dynamic)) *dl = make_data_loc(maxlen, dyndata - base); ret = process_fetch_insn(arg->code, rec, dl, base); - if (arg->dynamic) { - if (unlikely(ret < 0)) { - *dl = make_data_loc(0, dyndata - base); - } else { - dyndata += ret; - maxlen -= ret; - } + if (arg->dynamic && likely(ret > 0)) { + dyndata += ret; + maxlen -= ret; } } } diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index 8b92e34ff0c8..7b47e9a2c010 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -170,7 +170,8 @@ fetch_store_string(unsigned long addr, void *dest, void *base) */ ret++; *(u32 *)dest = make_data_loc(ret, (void *)dst - base); - } + } else + *(u32 *)dest = make_data_loc(0, (void *)dst - base); return ret; }