diff mbox series

[PATCHv2,bpf-next,1/4] bpf: Fix uprobe multi pid filter check

Message ID 20240905115124.1503998-2-jolsa@kernel.org (mailing list archive)
State Handled Elsewhere
Commit 900f362e2062e4a23a53bf89fd3b248cd021f5af
Headers show
Series selftests/bpf: Add uprobe multi pid filter test | expand

Commit Message

Jiri Olsa Sept. 5, 2024, 11:51 a.m. UTC
Uprobe multi link does its own process (thread leader) filtering before
running the bpf program by comparing task's vm pointers.

But as Oleg pointed out there can be processes sharing the vm (CLONE_VM),
so we can't just compare task->vm pointers, but instead we need to use
same_thread_group call.

Suggested-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 kernel/trace/bpf_trace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Oleg Nesterov Sept. 5, 2024, 2:07 p.m. UTC | #1
On 09/05, Jiri Olsa wrote:
>
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -3207,7 +3207,7 @@ static int uprobe_prog_run(struct bpf_uprobe *uprobe,
>  	struct bpf_run_ctx *old_run_ctx;
>  	int err = 0;
>
> -	if (link->task && current->mm != link->task->mm)
> +	if (link->task && !same_thread_group(current, link->task))
>  		return 0;

plus the current check can return false negative if link->task->mm == NULL

Acked-by: Oleg Nesterov <oleg@redhat.com>
diff mbox series

Patch

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index b69a39316c0c..98e395f1baae 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3207,7 +3207,7 @@  static int uprobe_prog_run(struct bpf_uprobe *uprobe,
 	struct bpf_run_ctx *old_run_ctx;
 	int err = 0;
 
-	if (link->task && current->mm != link->task->mm)
+	if (link->task && !same_thread_group(current, link->task))
 		return 0;
 
 	if (sleepable)