[v5,3/5] tracing/probes: Fix to update dynamic data counter if fetcharg uses it

Message ID 168908494781.123124.8160245359962103684.stgit@devnote2
State New
Headers
Series tracing/probes: Fix bugs in process_fetch_insn |

Commit Message

Masami Hiramatsu (Google) July 11, 2023, 2:15 p.m. UTC
  From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

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 <rostedt@goodmis.org>
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) <mhiramat@kernel.org>
---
 kernel/trace/trace_probe_tmpl.h |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
  

Comments

Steven Rostedt July 13, 2023, 1:34 p.m. UTC | #1
On Tue, 11 Jul 2023 23:15:48 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:

> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> 
> 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 <rostedt@goodmis.org>
> 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) <mhiramat@kernel.org>

Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>

-- Steve

> ---
>  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;
> +			}
>  		}
>  	}
>  }
  
Masami Hiramatsu (Google) July 13, 2023, 2:34 p.m. UTC | #2
On Thu, 13 Jul 2023 09:34:36 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Tue, 11 Jul 2023 23:15:48 +0900
> "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
> 
> > From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> > 
> > 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 <rostedt@goodmis.org>
> > 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) <mhiramat@kernel.org>
> 
> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>

Thank you! I'll pull this series. 

> 
> -- Steve
> 
> > ---
> >  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;
> > +			}
> >  		}
> >  	}
> >  }
>
  

Patch

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;
+			}
 		}
 	}
 }