* [PATCH v2 0/4] tracing/probes: Fix bugs in process_fetch_insn
@ 2023-07-07 13:40 Masami Hiramatsu (Google)
2023-07-07 13:40 ` [PATCH v2 1/4] tracing/probes: Fix to avoid double count of the string length on the array Masami Hiramatsu (Google)
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Masami Hiramatsu (Google) @ 2023-07-07 13:40 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Dan Carpenter, linux-trace-kernel, LKML, Masami Hiramatsu
Hi,
Here are the 2nd version of fix bugs in process_fetch_insn_*().
The previous version is here;
https://lore.kernel.org/all/168830922841.2278819.9165254236027770818.stgit@mhiramat.roam.corp.google.com/
The first patch [1/4] just updated the description. [2/4] has been
changed because previous one did not consider to store the array data.
So instead of exit, just clear the 'ret' if it has any error code.
[3/4] reverts the patch which did not work. And [4/4] makes each
fetch_store_string*() always updates the data_loc, instead of clearing
it in store_trace_args().
Thank you,
---
Masami Hiramatsu (Google) (4):
tracing/probes: Fix to avoid double count of the string length on the array
tracing/probes: Fix not to count error code to total length
Revert "tracing: Add "(fault)" name injection to kernel probes"
tracing/probes: Fix to record 0-length data_loc in fetch_store_string*() if fails
kernel/trace/trace_events_synth.c | 2 +-
kernel/trace/trace_probe_kernel.h | 29 ++++-------------------------
kernel/trace/trace_probe_tmpl.h | 10 +++++-----
kernel/trace/trace_uprobe.c | 3 ++-
4 files changed, 12 insertions(+), 32 deletions(-)
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/4] tracing/probes: Fix to avoid double count of the string length on the array
2023-07-07 13:40 [PATCH v2 0/4] tracing/probes: Fix bugs in process_fetch_insn Masami Hiramatsu (Google)
@ 2023-07-07 13:40 ` Masami Hiramatsu (Google)
2023-07-07 13:41 ` [PATCH v2 2/4] tracing/probes: Fix not to count error code to total length Masami Hiramatsu (Google)
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Masami Hiramatsu (Google) @ 2023-07-07 13:40 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Dan Carpenter, linux-trace-kernel, LKML, Masami Hiramatsu
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
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 <dan.carpenter@linaro.org>
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) <mhiramat@kernel.org>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
Changes in v2:
- Fix patch description.
---
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:
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 2/4] tracing/probes: Fix not to count error code to total length
2023-07-07 13:40 [PATCH v2 0/4] tracing/probes: Fix bugs in process_fetch_insn Masami Hiramatsu (Google)
2023-07-07 13:40 ` [PATCH v2 1/4] tracing/probes: Fix to avoid double count of the string length on the array Masami Hiramatsu (Google)
@ 2023-07-07 13:41 ` Masami Hiramatsu (Google)
2023-07-07 13:41 ` [PATCH v2 3/4] Revert "tracing: Add "(fault)" name injection to kernel probes" Masami Hiramatsu (Google)
2023-07-07 13:41 ` [PATCH v2 4/4] tracing/probes: Fix to record 0-length data_loc in fetch_store_string*() if fails Masami Hiramatsu (Google)
3 siblings, 0 replies; 9+ messages in thread
From: Masami Hiramatsu (Google) @ 2023-07-07 13:41 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Dan Carpenter, linux-trace-kernel, LKML, Masami Hiramatsu
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
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 <dan.carpenter@linaro.org>
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) <mhiramat@kernel.org>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
Changes in v2:
- Check and clear ret only for the array argument.
---
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;
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 3/4] Revert "tracing: Add "(fault)" name injection to kernel probes"
2023-07-07 13:40 [PATCH v2 0/4] tracing/probes: Fix bugs in process_fetch_insn Masami Hiramatsu (Google)
2023-07-07 13:40 ` [PATCH v2 1/4] tracing/probes: Fix to avoid double count of the string length on the array Masami Hiramatsu (Google)
2023-07-07 13:41 ` [PATCH v2 2/4] tracing/probes: Fix not to count error code to total length Masami Hiramatsu (Google)
@ 2023-07-07 13:41 ` Masami Hiramatsu (Google)
2023-07-07 14:14 ` Steven Rostedt
2023-07-07 13:41 ` [PATCH v2 4/4] tracing/probes: Fix to record 0-length data_loc in fetch_store_string*() if fails Masami Hiramatsu (Google)
3 siblings, 1 reply; 9+ messages in thread
From: Masami Hiramatsu (Google) @ 2023-07-07 13:41 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Dan Carpenter, linux-trace-kernel, LKML, Masami Hiramatsu
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
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.
Link: https://lore.kernel.org/all/20230706230642.3793a593@rorschach.local.home/
Cc: stable@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Tom Zanussi <zanussi@kernel.org>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
kernel/trace/trace_events_synth.c | 2 +-
kernel/trace/trace_probe_kernel.h | 31 ++++++-------------------------
2 files changed, 7 insertions(+), 26 deletions(-)
diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c
index d6a70aff2410..23416ec8e1da 100644
--- a/kernel/trace/trace_events_synth.c
+++ b/kernel/trace/trace_events_synth.c
@@ -478,7 +478,7 @@ static unsigned int trace_string(struct synth_trace_event *entry,
ret = strncpy_from_kernel_nofault(str_field, str_val, STR_VAR_LEN_MAX);
if (ret < 0)
- strcpy(str_field, FAULT_STRING);
+ strcpy(str_field, "(fault)");
(*n_u64) += STR_VAR_LEN_MAX / sizeof(u64);
}
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;
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 4/4] tracing/probes: Fix to record 0-length data_loc in fetch_store_string*() if fails
2023-07-07 13:40 [PATCH v2 0/4] tracing/probes: Fix bugs in process_fetch_insn Masami Hiramatsu (Google)
` (2 preceding siblings ...)
2023-07-07 13:41 ` [PATCH v2 3/4] Revert "tracing: Add "(fault)" name injection to kernel probes" Masami Hiramatsu (Google)
@ 2023-07-07 13:41 ` Masami Hiramatsu (Google)
3 siblings, 0 replies; 9+ messages in thread
From: Masami Hiramatsu (Google) @ 2023-07-07 13:41 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Dan Carpenter, linux-trace-kernel, LKML, Masami Hiramatsu
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
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) <mhiramat@kernel.org>
---
kernel/trace/trace_probe_kernel.h | 6 ++----
kernel/trace/trace_probe_tmpl.h | 4 +---
kernel/trace/trace_uprobe.c | 3 ++-
3 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/kernel/trace/trace_probe_kernel.h b/kernel/trace/trace_probe_kernel.h
index 6deae2ce34f8..37d5696ed768 100644
--- a/kernel/trace/trace_probe_kernel.h
+++ b/kernel/trace/trace_probe_kernel.h
@@ -55,8 +55,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);
+ *(u32 *)dest = make_data_loc((ret >= 0) ? ret : 0, __dest - base);
return ret;
}
@@ -87,8 +86,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);
+ *(u32 *)dest = make_data_loc((ret >= 0) ? ret : 0, __dest - base);
return ret;
}
diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h
index ed9d57c6b041..bbad0503f166 100644
--- a/kernel/trace/trace_probe_tmpl.h
+++ b/kernel/trace/trace_probe_tmpl.h
@@ -267,9 +267,7 @@ 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 {
+ if (unlikely(ret > 0 && arg->dynamic)) {
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;
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/4] Revert "tracing: Add "(fault)" name injection to kernel probes"
2023-07-07 13:41 ` [PATCH v2 3/4] Revert "tracing: Add "(fault)" name injection to kernel probes" Masami Hiramatsu (Google)
@ 2023-07-07 14:14 ` Steven Rostedt
2023-07-07 15:46 ` Masami Hiramatsu
0 siblings, 1 reply; 9+ messages in thread
From: Steven Rostedt @ 2023-07-07 14:14 UTC (permalink / raw)
To: Masami Hiramatsu (Google); +Cc: Dan Carpenter, linux-trace-kernel, LKML
On Fri, 7 Jul 2023 22:41:12 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
> 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)"
> -
Instead of deleting this, why not use it in both places? After applying
your patch, we have:
$ git grep '(fault)' kernel/trace
kernel/trace/trace_events_synth.c: strcpy(str_field, "(fault)");
kernel/trace/trace_probe.c: trace_seq_puts(s, "(fault)");
We could make that consistent with:
kernel/trace/trace_events_synth.c: strcpy(str_field, FAULT_STRING);
kernel/trace/trace_probe.c: trace_seq_puts(s, FAULT_STRING);
-- Steve
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/4] Revert "tracing: Add "(fault)" name injection to kernel probes"
2023-07-07 14:14 ` Steven Rostedt
@ 2023-07-07 15:46 ` Masami Hiramatsu
2023-07-07 15:48 ` Steven Rostedt
0 siblings, 1 reply; 9+ messages in thread
From: Masami Hiramatsu @ 2023-07-07 15:46 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Dan Carpenter, linux-trace-kernel, LKML
On Fri, 7 Jul 2023 10:14:20 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:
> On Fri, 7 Jul 2023 22:41:12 +0900
> "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
>
> > 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)"
> > -
>
> Instead of deleting this, why not use it in both places? After applying
> your patch, we have:
>
> $ git grep '(fault)' kernel/trace
> kernel/trace/trace_events_synth.c: strcpy(str_field, "(fault)");
> kernel/trace/trace_probe.c: trace_seq_puts(s, "(fault)");
>
> We could make that consistent with:
>
> kernel/trace/trace_events_synth.c: strcpy(str_field, FAULT_STRING);
> kernel/trace/trace_probe.c: trace_seq_puts(s, FAULT_STRING);
Indeed. So can I tweak the revert patch more for this?
I would like to move the definition to trace.h.
Thanks,
>
> -- Steve
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/4] Revert "tracing: Add "(fault)" name injection to kernel probes"
2023-07-07 15:46 ` Masami Hiramatsu
@ 2023-07-07 15:48 ` Steven Rostedt
2023-07-08 1:30 ` Masami Hiramatsu
0 siblings, 1 reply; 9+ messages in thread
From: Steven Rostedt @ 2023-07-07 15:48 UTC (permalink / raw)
To: Masami Hiramatsu (Google); +Cc: Dan Carpenter, linux-trace-kernel, LKML
On Sat, 8 Jul 2023 00:46:43 +0900
Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote:
> Indeed. So can I tweak the revert patch more for this?
>
> I would like to move the definition to trace.h.
Sure.
-- Steve
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/4] Revert "tracing: Add "(fault)" name injection to kernel probes"
2023-07-07 15:48 ` Steven Rostedt
@ 2023-07-08 1:30 ` Masami Hiramatsu
0 siblings, 0 replies; 9+ messages in thread
From: Masami Hiramatsu @ 2023-07-08 1:30 UTC (permalink / raw)
To: Steven Rostedt; +Cc: Dan Carpenter, linux-trace-kernel, LKML
On Fri, 7 Jul 2023 11:48:17 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:
> On Sat, 8 Jul 2023 00:46:43 +0900
> Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote:
>
> > Indeed. So can I tweak the revert patch more for this?
> >
> > I would like to move the definition to trace.h.
>
> Sure.
OK, let me update the patch. Thanks!
>
> -- Steve
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-07-08 1:30 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-07 13:40 [PATCH v2 0/4] tracing/probes: Fix bugs in process_fetch_insn Masami Hiramatsu (Google)
2023-07-07 13:40 ` [PATCH v2 1/4] tracing/probes: Fix to avoid double count of the string length on the array Masami Hiramatsu (Google)
2023-07-07 13:41 ` [PATCH v2 2/4] tracing/probes: Fix not to count error code to total length Masami Hiramatsu (Google)
2023-07-07 13:41 ` [PATCH v2 3/4] Revert "tracing: Add "(fault)" name injection to kernel probes" Masami Hiramatsu (Google)
2023-07-07 14:14 ` Steven Rostedt
2023-07-07 15:46 ` Masami Hiramatsu
2023-07-07 15:48 ` Steven Rostedt
2023-07-08 1:30 ` Masami Hiramatsu
2023-07-07 13:41 ` [PATCH v2 4/4] tracing/probes: Fix to record 0-length data_loc in fetch_store_string*() if fails Masami Hiramatsu (Google)
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®