Skip to contentSkip to conversation

rethook: Remove warning messages printed for finding return address of a frame.

PATCH Superseded Kui-Feng Lee 6 participants 6 messages Apr 1, 2024 – Apr 8, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rethook: Remove warning messages printed for finding return address of a frame.

rethook_find_ret_addr() prints a warning message and returns 0 when the target task is running and not the "current" task to prevent returning an incorrect return address. However, this check is incomplete as the target task can still transition to the running state when finding the return address, although it is safe with RCU.

The issue we encounter is that the kernel frequently prints warning messages when BPF profiling programs call to bpf_get_task_stack() on running tasks.

The callers should be aware and willing to take the risk of receiving an incorrect return address from a task that is currently running other than the "current" one. A warning is not needed here as the callers are intent on it.

---
 kernel/trace/rethook.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/rethook.c +1 -1
index fa03094e9e69..4297a132a7ae 100644
@@ -248,7 +248,7 @@ unsigned long rethook_find_ret_addr(struct task_struct *tsk, unsigned long frame
 	if (WARN_ON_ONCE(!cur))
 		return 0;
 
-	if (WARN_ON_ONCE(tsk != current && task_is_running(tsk)))
+	if (tsk != current && task_is_running(tsk))
 		return 0;
 
 	do {
Signature · 1 line
2.34.1
Acked-by on v1 1/1
#1 lore raw
Quoted 26 lines · Kui-Feng Lee

rethook_find_ret_addr() prints a warning message and returns 0 when the target task is running and not the "current" task to prevent returning an incorrect return address. However, this check is incomplete as the target task can still transition to the running state when finding the return address, although it is safe with RCU.

The issue we encounter is that the kernel frequently prints warning messages when BPF profiling programs call to bpf_get_task_stack() on running tasks.

The callers should be aware and willing to take the risk of receiving an incorrect return address from a task that is currently running other than the "current" one. A warning is not needed here as the callers are intent on it.

---
 kernel/trace/rethook.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/rethook.c +0 -0
index fa03094e9e69..4297a132a7ae 100644

kernel/trace/rethook.c unsigned long rethook_find_ret_addr(struct task_struct *tsk, unsigned long frame · line 253

Quoted 7 lines
kernel/trace/rethook.c +1 -1
@@ -248,7 +248,7 @@ unsigned long rethook_find_ret_addr(struct task_struct *tsk, unsigned long frame
        if (WARN_ON_ONCE(!cur))
                return 0;
 
-       if (WARN_ON_ONCE(tsk != current && task_is_running(tsk)))
+       if (tsk != current && task_is_running(tsk))
                return 0;
 

This should probably go through Masami's tree, but the change makes sense to me, given this is an expected condition.

Quoted 5 lines
kernel/trace/rethook.c +0 -1
        do {
--

2.34.1

maintainer
#2 lore raw
Quoted 38 lines · Andrii Nakryiko
Quoted 26 lines · Kui-Feng Lee

rethook_find_ret_addr() prints a warning message and returns 0 when the target task is running and not the "current" task to prevent returning an incorrect return address. However, this check is incomplete as the target task can still transition to the running state when finding the return address, although it is safe with RCU.

The issue we encounter is that the kernel frequently prints warning messages when BPF profiling programs call to bpf_get_task_stack() on running tasks.

The callers should be aware and willing to take the risk of receiving an incorrect return address from a task that is currently running other than the "current" one. A warning is not needed here as the callers are intent on it.

---
  kernel/trace/rethook.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/rethook.c +0 -0
index fa03094e9e69..4297a132a7ae 100644

kernel/trace/rethook.c unsigned long rethook_find_ret_addr(struct task_struct *tsk, unsigned long frame · line 253

Quoted 7 lines
kernel/trace/rethook.c +1 -1
@@ -248,7 +248,7 @@ unsigned long rethook_find_ret_addr(struct task_struct *tsk, unsigned long frame
         if (WARN_ON_ONCE(!cur))
                 return 0;
 
-       if (WARN_ON_ONCE(tsk != current && task_is_running(tsk)))
+       if (tsk != current && task_is_running(tsk))
                 return 0;
 

This should probably go through Masami's tree, but the change makes sense to me, given this is an expected condition.

Quoted 1 line

Masami, I assume you'll pick this up?

Thanks,
Daniel

#3 lore raw
Quoted 8 lines · On Wed, 3 Apr 2024 16:36:25 +0200 Daniel Borkmann <[email protected]> wrote:
Quoted 7 lines · Andrii Nakryiko
Quoted 6 lines · Kui-Feng Lee

rethook_find_ret_addr() prints a warning message and returns 0 when the target task is running and not the "current" task to prevent returning an incorrect return address. However, this check is incomplete as the target task can still transition to the running state when finding the return address, although it is safe with RCU.

Could you tell me more about this last part? This change just remove WARN_ON_ONCE() which warns that the user tries to unwind stack of a running task. This means the task can change the stack in parallel if the task is running on other CPU.
Does the BPF stop the task? or do you have any RCU magic to copy the stack?

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

The issue we encounter is that the kernel frequently prints warning messages when BPF profiling programs call to bpf_get_task_stack() on running tasks.

Hmm, WARN_ON_ONCE should print it once, not frequently.

Quoted 27 lines
Quoted 27 lines
Quoted 16 lines

The callers should be aware and willing to take the risk of receiving an incorrect return address from a task that is currently running other than the "current" one. A warning is not needed here as the callers are intent on it.

---
  kernel/trace/rethook.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/rethook.c +0 -0
index fa03094e9e69..4297a132a7ae 100644

kernel/trace/rethook.c unsigned long rethook_find_ret_addr(struct task_struct *tsk, unsigned long frame · line 253

Quoted 7 lines
kernel/trace/rethook.c +1 -1
@@ -248,7 +248,7 @@ unsigned long rethook_find_ret_addr(struct task_struct *tsk, unsigned long frame
         if (WARN_ON_ONCE(!cur))
                 return 0;
 
-       if (WARN_ON_ONCE(tsk != current && task_is_running(tsk)))
+       if (tsk != current && task_is_running(tsk))
                 return 0;
 

This should probably go through Masami's tree, but the change makes sense to me, given this is an expected condition.

Quoted 3 lines
Quoted 1 line

Masami, I assume you'll pick this up?

OK, anyway it will just return 0 if this situation happens, and caller will get the trampoline address instead of correct return address in this case. I think it does not do any unsafe things. So I agree removing it. But I think the explanation is a bit confusing.

Thank you,

Quoted 3 lines

Thanks,
Daniel

Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
#4 lore raw
Quoted 12 lines · Masami Hiramatsu (Google)
Quoted 8 lines · On Wed, 3 Apr 2024 16:36:25 +0200 Daniel Borkmann <[email protected]> wrote:
Quoted 7 lines · Andrii Nakryiko
Quoted 6 lines · Kui-Feng Lee

rethook_find_ret_addr() prints a warning message and returns 0 when the target task is running and not the "current" task to prevent returning an incorrect return address. However, this check is incomplete as the target task can still transition to the running state when finding the return address, although it is safe with RCU.

Quoted 5 lines

Could you tell me more about this last part? This change just remove WARN_ON_ONCE() which warns that the user tries to unwind stack of a running task. This means the task can change the stack in parallel if the task is running on other CPU.
Does the BPF stop the task? or do you have any RCU magic to copy the stack?

No, the BPF doesn't stop the task or copy the stack. The last part tries to explain that this function can still return an incorrect address even with this check. And calling this function on a target task that is not "current" is safe. Since you think it is confusing. I will remove this part.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The issue we encounter is that the kernel frequently prints warning messages when BPF profiling programs call to bpf_get_task_stack() on running tasks.

Hmm, WARN_ON_ONCE should print it once, not frequently.

You are right! I should rephrase it. In a firm with a large number of hosts, this warning message become a noise.

Quoted 44 lines
Quoted 28 lines
Quoted 28 lines
Quoted 17 lines

The callers should be aware and willing to take the risk of receiving an incorrect return address from a task that is currently running other than the "current" one. A warning is not needed here as the callers are intent on it.

---
   kernel/trace/rethook.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/rethook.c +0 -0
index fa03094e9e69..4297a132a7ae 100644

kernel/trace/rethook.c unsigned long rethook_find_ret_addr(struct task_struct *tsk, unsigned long frame · line 253

Quoted 7 lines
kernel/trace/rethook.c +1 -1
@@ -248,7 +248,7 @@ unsigned long rethook_find_ret_addr(struct task_struct *tsk, unsigned long frame
          if (WARN_ON_ONCE(!cur))
                  return 0;
 
-       if (WARN_ON_ONCE(tsk != current && task_is_running(tsk)))
+       if (tsk != current && task_is_running(tsk))
                  return 0;
 

This should probably go through Masami's tree, but the change makes sense to me, given this is an expected condition.

Quoted 3 lines
Quoted 1 line

Masami, I assume you'll pick this up?

OK, anyway it will just return 0 if this situation happens, and caller will get the trampoline address instead of correct return address in this case. I think it does not do any unsafe things. So I agree removing it. But I think the explanation is a bit confusing.

Thank you,

Quoted 3 lines

Thanks,
Daniel

Acked-by on v1 1/1
#5 lore raw
In reply to Kui-Feng Lee
Quoted 37 lines · Kui-Feng Lee

rethook_find_ret_addr() prints a warning message and returns 0 when the target task is running and not the "current" task to prevent returning an incorrect return address. However, this check is incomplete as the target task can still transition to the running state when finding the return address, although it is safe with RCU.

The issue we encounter is that the kernel frequently prints warning messages when BPF profiling programs call to bpf_get_task_stack() on running tasks.

The callers should be aware and willing to take the risk of receiving an incorrect return address from a task that is currently running other than the "current" one. A warning is not needed here as the callers are intent on it.

---
 kernel/trace/rethook.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/rethook.c +1 -1
index fa03094e9e69..4297a132a7ae 100644
@@ -248,7 +248,7 @@ unsigned long rethook_find_ret_addr(struct task_struct *tsk, unsigned long frame
 	if (WARN_ON_ONCE(!cur))
 		return 0;
 
-	if (WARN_ON_ONCE(tsk != current && task_is_running(tsk)))
+	if (tsk != current && task_is_running(tsk))
 		return 0;
 
 	do {
Signature · 1 line
2.34.1