Re: [PATCH 3/3] tracing/probes: Fix return value when "(fault)" is injected

From: Google
Date: Thu Jul 06 2023 - 00:40:45 EST


On Wed, 5 Jul 2023 22:49:56 -0400
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:

> On Sun, 2 Jul 2023 23:47:35 +0900
> "Masami Hiramatsu (Google)" <mhiramat@xxxxxxxxxx> wrote:
>
> > From: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
> >
> > 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)"'.
> >
>
> Ah, because of patch 2, the ret < 0 makes it return without printing the
> "fault"?

No, actually set_data_loc() updates the 'ret' argument, but it is just
disposed... (not returned to the caller)

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

So this returns updated 'ret', and also update data_loc to use the
updated 'ret' value (which is the length of the stored data).

>
> Reviewed-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx>

Thank you!

>
> -- Steve
>
>
> > Fixes: 2e9906f84fc7 ("tracing: Add "(fault)" name injection to kernel probes")
> > Cc: stable@xxxxxxxxxxxxxxx
> > Signed-off-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
> > ---


--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>