From: Tom Zanussi <zanussi@kernel.org>
To: rostedt@goodmis.org
Cc: mhiramat@kernel.org, linux-kernel@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, akpm@linux-foundation.org,
zwisler@google.com, chinglinyu@google.com
Subject: [PATCH 1/4] tracing/histogram: Don't use strlen to find length of stacktrace variables
Date: Fri, 10 Feb 2023 15:33:03 -0600 [thread overview]
Message-ID: <1ed6906cd9d6477ef2bd8e63c61de20a9ffe64d7.1676063532.git.zanussi@kernel.org> (raw)
In-Reply-To: <cover.1676063532.git.zanussi@kernel.org>
Because stacktraces are saved in dynamic strings,
trace_event_raw_event_synth() uses strlen to determine the length of
the stack. Stacktraces may contain 0-bytes, though, in the saved
addresses, so the length found and passed to reserve() will be too
small.
Fix this by using the first unsigned long in the stack variables to
store the actual number of elements in the stack and have
trace_event_raw_event_synth() use that to determine the length of the
stack.
Signed-off-by: Tom Zanussi <zanussi@kernel.org>
---
kernel/trace/trace_events_hist.c | 12 ++++++++----
kernel/trace/trace_events_synth.c | 7 ++++++-
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 888b7a394ce5..76bd105988c6 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -3135,13 +3135,15 @@ static inline void __update_field_vars(struct tracing_map_elt *elt,
size = min(val->size, STR_VAR_LEN_MAX);
strscpy(str, val_str, size);
} else {
+ char *stack_start = str + sizeof(unsigned long);
int e;
- e = stack_trace_save((void *)str,
+ e = stack_trace_save((void *)stack_start,
HIST_STACKTRACE_DEPTH,
HIST_STACKTRACE_SKIP);
if (e < HIST_STACKTRACE_DEPTH - 1)
- ((unsigned long *)str)[e] = 0;
+ ((unsigned long *)stack_start)[e] = 0;
+ *((unsigned long *)str) = e;
}
var_val = (u64)(uintptr_t)str;
}
@@ -5133,13 +5135,15 @@ static void hist_trigger_elt_update(struct hist_trigger_data *hist_data,
size = min(hist_field->size, STR_VAR_LEN_MAX);
strscpy(str, val_str, size);
} else {
+ char *stack_start = str + sizeof(unsigned long);
int e;
- e = stack_trace_save((void *)str,
+ e = stack_trace_save((void *)stack_start,
HIST_STACKTRACE_DEPTH,
HIST_STACKTRACE_SKIP);
if (e < HIST_STACKTRACE_DEPTH - 1)
- ((unsigned long *)str)[e] = 0;
+ ((unsigned long *)stack_start)[e] = 0;
+ *((unsigned long *)str) = e;
}
hist_val = (u64)(uintptr_t)str;
}
diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c
index d458d7a0dfd7..6209b23c863f 100644
--- a/kernel/trace/trace_events_synth.c
+++ b/kernel/trace/trace_events_synth.c
@@ -538,7 +538,12 @@ static notrace void trace_event_raw_event_synth(void *__data,
val_idx = var_ref_idx[field_pos];
str_val = (char *)(long)var_ref_vals[val_idx];
- len = kern_fetch_store_strlen((unsigned long)str_val);
+ if (event->dynamic_fields[i]->is_stack) {
+ len = *((unsigned long *)str_val);
+ len *= sizeof(unsigned long);
+ } else {
+ len = kern_fetch_store_strlen((unsigned long)str_val);
+ }
fields_size += len;
}
--
2.34.1
next prev parent reply other threads:[~2023-02-10 21:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-10 21:33 [PATCH 0/4] tracing/histogram: Some fixes for new " Tom Zanussi
2023-02-10 21:33 ` Tom Zanussi [this message]
2023-02-13 15:24 ` [PATCH 1/4] tracing/histogram: Don't use strlen to find length of " Masami Hiramatsu
2023-02-13 15:56 ` Steven Rostedt
2023-02-10 21:33 ` [PATCH 2/4] tracing/histogram: Fix a few problems with stacktrace variable printing Tom Zanussi
2023-02-10 21:33 ` [PATCH 3/4] tracing/histogram: Fix stacktrace key Tom Zanussi
2023-02-10 23:07 ` kernel test robot
2023-02-10 21:33 ` [PATCH 4/4] tracing/histogram: Fix stacktrace histogram Documententation Tom Zanussi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1ed6906cd9d6477ef2bd8e63c61de20a9ffe64d7.1676063532.git.zanussi@kernel.org \
--to=zanussi@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=chinglinyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=zwisler@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®