[PATCH] tracing: fprobe: fix the length of unused fgraph_data

Martin Kaiser posted 1 patch 1 week, 4 days ago
kernel/trace/fprobe.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] tracing: fprobe: fix the length of unused fgraph_data
Posted by Martin Kaiser 1 week, 4 days ago
If fprobe_entry does not fill the allocated fgraph_data completely, the
unused part is zeroed with memset.

Fix the length for this memset call. Both reserved_words and used are in
units of return stack words, but memset needs the number of bytes.

Cc: stable@vger.kernel.org
Fixes: 4346ba160409 ("fprobe: Rewrite fprobe on function-graph tracer")
Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 kernel/trace/fprobe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
index dcadf1d23b8a..6a1192515afd 100644
--- a/kernel/trace/fprobe.c
+++ b/kernel/trace/fprobe.c
@@ -451,7 +451,7 @@ static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops
 		}
 	}
 	if (used < reserved_words)
-		memset(fgraph_data + used, 0, reserved_words - used);
+		memset(fgraph_data + used, 0, (reserved_words - used) * sizeof(long));
 
 	/* If any exit_handler is set, data must be used. */
 	return used != 0;
-- 
2.43.7
Re: [PATCH] tracing: fprobe: fix the length of unused fgraph_data
Posted by Steven Rostedt 1 week, 4 days ago
On Mon, 23 Mar 2026 11:19:36 +0100
Martin Kaiser <martin@kaiser.cx> wrote:

> If fprobe_entry does not fill the allocated fgraph_data completely, the
> unused part is zeroed with memset.
> 
> Fix the length for this memset call. Both reserved_words and used are in
> units of return stack words, but memset needs the number of bytes.
> 
> Cc: stable@vger.kernel.org
> Fixes: 4346ba160409 ("fprobe: Rewrite fprobe on function-graph tracer")
> Signed-off-by: Martin Kaiser <martin@kaiser.cx>
> ---
>  kernel/trace/fprobe.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> index dcadf1d23b8a..6a1192515afd 100644
> --- a/kernel/trace/fprobe.c
> +++ b/kernel/trace/fprobe.c
> @@ -451,7 +451,7 @@ static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops
>  		}
>  	}
>  	if (used < reserved_words)
> -		memset(fgraph_data + used, 0, reserved_words - used);
> +		memset(fgraph_data + used, 0, (reserved_words - used) * sizeof(long));

So fgraph_data is only used internally between the fprobe_fgraph_entry()
and fprobe_return() as it only exists on the fgraph shadow stack. I'm not
even sure if the unused portion needs to be zeroed out.

Thus, this may be correct, but it doesn't look like a true bug that needs a
stable tag.

-- Steve


>  
>  	/* If any exit_handler is set, data must be used. */
>  	return used != 0;
Re: [PATCH] tracing: fprobe: fix the length of unused fgraph_data
Posted by Masami Hiramatsu (Google) 1 week, 3 days ago
On Mon, 23 Mar 2026 10:48:18 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Mon, 23 Mar 2026 11:19:36 +0100
> Martin Kaiser <martin@kaiser.cx> wrote:
> 
> > If fprobe_entry does not fill the allocated fgraph_data completely, the
> > unused part is zeroed with memset.
> > 
> > Fix the length for this memset call. Both reserved_words and used are in
> > units of return stack words, but memset needs the number of bytes.
> > 
> > Cc: stable@vger.kernel.org
> > Fixes: 4346ba160409 ("fprobe: Rewrite fprobe on function-graph tracer")
> > Signed-off-by: Martin Kaiser <martin@kaiser.cx>
> > ---
> >  kernel/trace/fprobe.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> > index dcadf1d23b8a..6a1192515afd 100644
> > --- a/kernel/trace/fprobe.c
> > +++ b/kernel/trace/fprobe.c
> > @@ -451,7 +451,7 @@ static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops
> >  		}
> >  	}
> >  	if (used < reserved_words)
> > -		memset(fgraph_data + used, 0, reserved_words - used);
> > +		memset(fgraph_data + used, 0, (reserved_words - used) * sizeof(long));
> 
> So fgraph_data is only used internally between the fprobe_fgraph_entry()
> and fprobe_return() as it only exists on the fgraph shadow stack. I'm not
> even sure if the unused portion needs to be zeroed out.
> 
> Thus, this may be correct, but it doesn't look like a true bug that needs a
> stable tag.

Hmm, indeed. Maybe we'd better just remove this memset from for-next.

Thanks,

> 
> -- Steve
> 
> 
> >  
> >  	/* If any exit_handler is set, data must be used. */
> >  	return used != 0;
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>
Re: [PATCH] tracing: fprobe: fix the length of unused fgraph_data
Posted by Martin Kaiser 1 week, 3 days ago
Thus wrote Masami Hiramatsu (mhiramat@kernel.org):

> On Mon, 23 Mar 2026 10:48:18 -0400
> Steven Rostedt <rostedt@goodmis.org> wrote:

> > On Mon, 23 Mar 2026 11:19:36 +0100
> > Martin Kaiser <martin@kaiser.cx> wrote:

> > > If fprobe_entry does not fill the allocated fgraph_data completely, the
> > > unused part is zeroed with memset.

> > > Fix the length for this memset call. Both reserved_words and used are in
> > > units of return stack words, but memset needs the number of bytes.

> > > Cc: stable@vger.kernel.org
> > > Fixes: 4346ba160409 ("fprobe: Rewrite fprobe on function-graph tracer")
> > > Signed-off-by: Martin Kaiser <martin@kaiser.cx>
> > > ---
> > >  kernel/trace/fprobe.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)

> > > diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> > > index dcadf1d23b8a..6a1192515afd 100644
> > > --- a/kernel/trace/fprobe.c
> > > +++ b/kernel/trace/fprobe.c
> > > @@ -451,7 +451,7 @@ static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops
> > >  		}
> > >  	}
> > >  	if (used < reserved_words)
> > > -		memset(fgraph_data + used, 0, reserved_words - used);
> > > +		memset(fgraph_data + used, 0, (reserved_words - used) * sizeof(long));

> > So fgraph_data is only used internally between the fprobe_fgraph_entry()
> > and fprobe_return() as it only exists on the fgraph shadow stack. I'm not
> > even sure if the unused portion needs to be zeroed out.

> > Thus, this may be correct, but it doesn't look like a true bug that needs a
> > stable tag.

> Hmm, indeed. Maybe we'd better just remove this memset from for-next.

Ok, I see your point. I'll send a v2 that removes the memset.

Best regards,
Martin

> Thanks,


> > -- Steve



> > >  	/* If any exit_handler is set, data must be used. */
> > >  	return used != 0;



> -- 
> Masami Hiramatsu (Google) <mhiramat@kernel.org>
Re: [PATCH] tracing: fprobe: fix the length of unused fgraph_data
Posted by Masami Hiramatsu (Google) 1 week, 3 days ago
On Tue, 24 Mar 2026 09:05:12 +0100
Martin Kaiser <martin@kaiser.cx> wrote:

> Thus wrote Masami Hiramatsu (mhiramat@kernel.org):
> 
> > On Mon, 23 Mar 2026 10:48:18 -0400
> > Steven Rostedt <rostedt@goodmis.org> wrote:
> 
> > > On Mon, 23 Mar 2026 11:19:36 +0100
> > > Martin Kaiser <martin@kaiser.cx> wrote:
> 
> > > > If fprobe_entry does not fill the allocated fgraph_data completely, the
> > > > unused part is zeroed with memset.
> 
> > > > Fix the length for this memset call. Both reserved_words and used are in
> > > > units of return stack words, but memset needs the number of bytes.
> 
> > > > Cc: stable@vger.kernel.org
> > > > Fixes: 4346ba160409 ("fprobe: Rewrite fprobe on function-graph tracer")
> > > > Signed-off-by: Martin Kaiser <martin@kaiser.cx>
> > > > ---
> > > >  kernel/trace/fprobe.c | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> > > > diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> > > > index dcadf1d23b8a..6a1192515afd 100644
> > > > --- a/kernel/trace/fprobe.c
> > > > +++ b/kernel/trace/fprobe.c
> > > > @@ -451,7 +451,7 @@ static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops
> > > >  		}
> > > >  	}
> > > >  	if (used < reserved_words)
> > > > -		memset(fgraph_data + used, 0, reserved_words - used);
> > > > +		memset(fgraph_data + used, 0, (reserved_words - used) * sizeof(long));
> 
> > > So fgraph_data is only used internally between the fprobe_fgraph_entry()
> > > and fprobe_return() as it only exists on the fgraph shadow stack. I'm not
> > > even sure if the unused portion needs to be zeroed out.
> 
> > > Thus, this may be correct, but it doesn't look like a true bug that needs a
> > > stable tag.
> 
> > Hmm, indeed. Maybe we'd better just remove this memset from for-next.
> 
> Ok, I see your point. I'll send a v2 that removes the memset.

Yeah, thanks!

> 
> Best regards,
> Martin
> 
> > Thanks,
> 
> 
> > > -- Steve
> 
> 
> 
> > > >  	/* If any exit_handler is set, data must be used. */
> > > >  	return used != 0;
> 
> 
> 
> > -- 
> > Masami Hiramatsu (Google) <mhiramat@kernel.org>


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>
Re: [PATCH] tracing: fprobe: fix the length of unused fgraph_data
Posted by Masami Hiramatsu (Google) 1 week, 4 days ago
On Mon, 23 Mar 2026 11:19:36 +0100
Martin Kaiser <martin@kaiser.cx> wrote:

> If fprobe_entry does not fill the allocated fgraph_data completely, the
> unused part is zeroed with memset.
> 
> Fix the length for this memset call. Both reserved_words and used are in
> units of return stack words, but memset needs the number of bytes.
> 
> Cc: stable@vger.kernel.org
> Fixes: 4346ba160409 ("fprobe: Rewrite fprobe on function-graph tracer")
> Signed-off-by: Martin Kaiser <martin@kaiser.cx>

Good catch!

Thanks,

> ---
>  kernel/trace/fprobe.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> index dcadf1d23b8a..6a1192515afd 100644
> --- a/kernel/trace/fprobe.c
> +++ b/kernel/trace/fprobe.c
> @@ -451,7 +451,7 @@ static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops
>  		}
>  	}
>  	if (used < reserved_words)
> -		memset(fgraph_data + used, 0, reserved_words - used);
> +		memset(fgraph_data + used, 0, (reserved_words - used) * sizeof(long));
>  
>  	/* If any exit_handler is set, data must be used. */
>  	return used != 0;
> -- 
> 2.43.7
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>
[PATCH v2] tracing: fprobe: do not zero out unused fgraph_data
Posted by Martin Kaiser 1 week, 3 days ago
If fprobe_entry does not fill the allocated fgraph_data completely, the
unused part does not have to be zeroed.

fgraph_data is a short-lived part of the shadow stack. The preceding
length field allows locating the end regardless of the content.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
v2:
 - remove the memset instead of fixing the length

 kernel/trace/fprobe.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
index dcadf1d23b8a..56d145017902 100644
--- a/kernel/trace/fprobe.c
+++ b/kernel/trace/fprobe.c
@@ -450,8 +450,6 @@ static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops
 				used += FPROBE_HEADER_SIZE_IN_LONG + size_words;
 		}
 	}
-	if (used < reserved_words)
-		memset(fgraph_data + used, 0, reserved_words - used);
 
 	/* If any exit_handler is set, data must be used. */
 	return used != 0;
-- 
2.43.7
Re: [PATCH v2] tracing: fprobe: do not zero out unused fgraph_data
Posted by Masami Hiramatsu (Google) 1 week, 3 days ago
On Tue, 24 Mar 2026 09:47:08 +0100
Martin Kaiser <martin@kaiser.cx> wrote:

> If fprobe_entry does not fill the allocated fgraph_data completely, the
> unused part does not have to be zeroed.
> 
> fgraph_data is a short-lived part of the shadow stack. The preceding
> length field allows locating the end regardless of the content.
> 
> Signed-off-by: Martin Kaiser <martin@kaiser.cx>

OK, thanks for update. Let me pick it.

Thanks,

> ---
> v2:
>  - remove the memset instead of fixing the length
> 
>  kernel/trace/fprobe.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> index dcadf1d23b8a..56d145017902 100644
> --- a/kernel/trace/fprobe.c
> +++ b/kernel/trace/fprobe.c
> @@ -450,8 +450,6 @@ static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops
>  				used += FPROBE_HEADER_SIZE_IN_LONG + size_words;
>  		}
>  	}
> -	if (used < reserved_words)
> -		memset(fgraph_data + used, 0, reserved_words - used);
>  
>  	/* If any exit_handler is set, data must be used. */
>  	return used != 0;
> -- 
> 2.43.7
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>
Re: [PATCH v2] tracing: fprobe: do not zero out unused fgraph_data
Posted by Steven Rostedt 1 week, 3 days ago
On Tue, 24 Mar 2026 09:47:08 +0100
Martin Kaiser <martin@kaiser.cx> wrote:

Hi Martin,

First, please do not send a v2 as a reply to v1. A new version should
always start a new mail thread.

> If fprobe_entry does not fill the allocated fgraph_data completely, the
> unused part does not have to be zeroed.
> 
> fgraph_data is a short-lived part of the shadow stack. The preceding
> length field allows locating the end regardless of the content.
> 
> Signed-off-by: Martin Kaiser <martin@kaiser.cx>
> ---
> v2:

But to maintain a link to the previous version, I recommend adding here:

Changes since v1: https://lore.kernel.org/all/20260324084804.375764-1-martin@kaiser.cx


>  - remove the memset instead of fixing the length
> 
>  kernel/trace/fprobe.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> index dcadf1d23b8a..56d145017902 100644
> --- a/kernel/trace/fprobe.c
> +++ b/kernel/trace/fprobe.c
> @@ -450,8 +450,6 @@ static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops
>  				used += FPROBE_HEADER_SIZE_IN_LONG + size_words;
>  		}
>  	}
> -	if (used < reserved_words)
> -		memset(fgraph_data + used, 0, reserved_words - used);
>  
>  	/* If any exit_handler is set, data must be used. */
>  	return used != 0;

As for the patch,

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

-- Steve
Re: [PATCH v2] tracing: fprobe: do not zero out unused fgraph_data
Posted by Masami Hiramatsu (Google) 1 week, 3 days ago
On Tue, 24 Mar 2026 08:39:03 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Tue, 24 Mar 2026 09:47:08 +0100
> Martin Kaiser <martin@kaiser.cx> wrote:
> 
> Hi Martin,
> 
> First, please do not send a v2 as a reply to v1. A new version should
> always start a new mail thread.
> 
> > If fprobe_entry does not fill the allocated fgraph_data completely, the
> > unused part does not have to be zeroed.
> > 
> > fgraph_data is a short-lived part of the shadow stack. The preceding
> > length field allows locating the end regardless of the content.
> > 
> > Signed-off-by: Martin Kaiser <martin@kaiser.cx>
> > ---
> > v2:
> 
> But to maintain a link to the previous version, I recommend adding here:
> 
> Changes since v1: https://lore.kernel.org/all/20260324084804.375764-1-martin@kaiser.cx

Ah, this is a good idea for the patch which does not have cover mail.

Thanks :)

> 
> 
> >  - remove the memset instead of fixing the length
> > 
> >  kernel/trace/fprobe.c | 2 --
> >  1 file changed, 2 deletions(-)
> > 
> > diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> > index dcadf1d23b8a..56d145017902 100644
> > --- a/kernel/trace/fprobe.c
> > +++ b/kernel/trace/fprobe.c
> > @@ -450,8 +450,6 @@ static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops
> >  				used += FPROBE_HEADER_SIZE_IN_LONG + size_words;
> >  		}
> >  	}
> > -	if (used < reserved_words)
> > -		memset(fgraph_data + used, 0, reserved_words - used);
> >  
> >  	/* If any exit_handler is set, data must be used. */
> >  	return used != 0;
> 
> As for the patch,
> 
> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> 
> -- Steve
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>