Skip to contentSkip to conversation

tracing: fprobe: fix the length of unused fgraph_data

PATCH In review Martin Kaiser 3 participants 10 messages Mar 23 – Mar 24

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tracing: fprobe: fix the length of unused fgraph_data

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.

Fixes 4346ba160409 ("fprobe: Rewrite fprobe on function-graph tracer")
---
 kernel/trace/fprobe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/fprobe.c +1 -1
index dcadf1d23b8a..6a1192515afd 100644
@@ -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;
Signature · 1 line
2.43.7
#1 lore raw
Quoted 9 lines · On Mon, 23 Mar 2026 11:19:36 +0100 Martin Kaiser <[email protected]> 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.

Fixes 4346ba160409 ("fprobe: Rewrite fprobe on function-graph tracer")

Good catch!

Thanks,

Quoted 20 lines
---
 kernel/trace/fprobe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/fprobe.c +1 -1
index dcadf1d23b8a..6a1192515afd 100644
@@ -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;
Signature · 1 line
2.43.7
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
maintainer
#2 lore raw
In reply to Martin Kaiser
Quoted 18 lines · On Mon, 23 Mar 2026 11:19:36 +0100 Martin Kaiser <[email protected]> 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.

Fixes 4346ba160409 ("fprobe: Rewrite fprobe on function-graph tracer")
---
 kernel/trace/fprobe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/fprobe.c +0 -0
index dcadf1d23b8a..6a1192515afd 100644

kernel/trace/fprobe.c static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops · line 454

Quoted 5 lines
kernel/trace/fprobe.c +1 -1
@@ -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

Quoted 3 lines
kernel/trace/fprobe.c +0 -0
 	/* If any exit_handler is set, data must be used. */
 	return used != 0;
#3 lore raw
Quoted 31 lines · On Mon, 23 Mar 2026 10:48:18 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 18 lines · On Mon, 23 Mar 2026 11:19:36 +0100 Martin Kaiser <[email protected]> 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.

Fixes 4346ba160409 ("fprobe: Rewrite fprobe on function-graph tracer")
---
 kernel/trace/fprobe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/fprobe.c +0 -0
index dcadf1d23b8a..6a1192515afd 100644

kernel/trace/fprobe.c static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops · line 454

Quoted 5 lines
kernel/trace/fprobe.c +1 -1
@@ -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.

Quoted 2 lines

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,

Quoted 8 lines

-- Steve

Quoted 3 lines
kernel/trace/fprobe.c +0 -0
 	/* If any exit_handler is set, data must be used. */
 	return used != 0;
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
#4 lore raw

Thus wrote Masami Hiramatsu ([email protected]):

Quoted 34 lines
Quoted 30 lines · On Mon, 23 Mar 2026 10:48:18 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 18 lines · On Mon, 23 Mar 2026 11:19:36 +0100 Martin Kaiser <[email protected]> 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.

Fixes 4346ba160409 ("fprobe: Rewrite fprobe on function-graph tracer")
---
 kernel/trace/fprobe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/fprobe.c +0 -0
index dcadf1d23b8a..6a1192515afd 100644

kernel/trace/fprobe.c static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops · line 454

Quoted 5 lines
kernel/trace/fprobe.c +1 -1
@@ -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.

Quoted 4 lines
Quoted 2 lines

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

Quoted 14 lines

Thanks,

Quoted 6 lines

-- Steve

Quoted 2 lines
kernel/trace/fprobe.c +0 -0
 	/* If any exit_handler is set, data must be used. */
 	return used != 0;
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
#5 lore raw
Quoted 36 lines · On Tue, 24 Mar 2026 09:05:12 +0100 Martin Kaiser <[email protected]> wrote:

Thus wrote Masami Hiramatsu ([email protected]):

Quoted 33 lines
Quoted 30 lines · On Mon, 23 Mar 2026 10:48:18 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 18 lines · On Mon, 23 Mar 2026 11:19:36 +0100 Martin Kaiser <[email protected]> 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.

Fixes 4346ba160409 ("fprobe: Rewrite fprobe on function-graph tracer")
---
 kernel/trace/fprobe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/fprobe.c +0 -0
index dcadf1d23b8a..6a1192515afd 100644

kernel/trace/fprobe.c static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops · line 454

Quoted 5 lines
kernel/trace/fprobe.c +1 -1
@@ -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.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

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!

Quoted 18 lines

Best regards,
Martin

Quoted 14 lines

Thanks,

Quoted 6 lines

-- Steve

Quoted 2 lines
kernel/trace/fprobe.c +0 -0
 	/* If any exit_handler is set, data must be used. */
 	return used != 0;
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
#6 lore raw

PATCH v2 1/1 tracing: fprobe: do not zero out unused fgraph_data

In reply to Martin Kaiser

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.

---
v2:
- remove the memset instead of fixing the length

 kernel/trace/fprobe.c | 2 --
 1 file changed, 2 deletions(-)
kernel/trace/fprobe.c +0 -2
index dcadf1d23b8a..56d145017902 100644
@@ -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;
Signature · 1 line
2.43.7
maintainer Reviewed-by on v2 1/1
#7 lore raw

Re: [PATCH v2] tracing: fprobe: do not zero out unused fgraph_data

On Tue, 24 Mar 2026 09:47:08 +0100
Martin Kaiser <[email protected]> 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.

Quoted 9 lines

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.

---
v2:

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

Changes since v1: https://lore.kernel.org/all/[email protected]

Quoted 10 lines

- remove the memset instead of fixing the length

 kernel/trace/fprobe.c | 2 --
 1 file changed, 2 deletions(-)
kernel/trace/fprobe.c +0 -0
index dcadf1d23b8a..56d145017902 100644

kernel/trace/fprobe.c static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops · line 455

Quoted 8 lines
kernel/trace/fprobe.c +0 -2
@@ -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,

-- Steve

#8 lore raw

Re: [PATCH v2] tracing: fprobe: do not zero out unused fgraph_data

Quoted 14 lines · On Tue, 24 Mar 2026 08:39:03 -0400 Steven Rostedt <[email protected]> wrote:

On Tue, 24 Mar 2026 09:47:08 +0100
Martin Kaiser <[email protected]> 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.

Quoted 6 lines

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.

Quoted 7 lines
Quoted 3 lines

---
v2:

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

Changes since v1: https://lore.kernel.org/all/[email protected]

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

Thanks :)

Quoted 27 lines
Quoted 12 lines

- remove the memset instead of fixing the length

 kernel/trace/fprobe.c | 2 --
 1 file changed, 2 deletions(-)
kernel/trace/fprobe.c +0 -0
index dcadf1d23b8a..56d145017902 100644

kernel/trace/fprobe.c static int fprobe_fgraph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops · line 455

Quoted 8 lines
kernel/trace/fprobe.c +0 -2
@@ -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,

-- Steve

Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
#9 lore raw

Re: [PATCH v2] tracing: fprobe: do not zero out unused fgraph_data

In reply to Martin Kaiser
Quoted 7 lines · On Tue, 24 Mar 2026 09:47:08 +0100 Martin Kaiser <[email protected]> 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.

OK, thanks for update. Let me pick it.

Thanks,

Quoted 23 lines

---
v2:
- remove the memset instead of fixing the length

 kernel/trace/fprobe.c | 2 --
 1 file changed, 2 deletions(-)
kernel/trace/fprobe.c +0 -2
index dcadf1d23b8a..56d145017902 100644
@@ -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;
Signature · 1 line
2.43.7
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>