[PATCH bpf-next v1 09/14] selftests/bpf: Fix double thread join in uprobe_multi_test

Ihor Solodrai posted 14 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH bpf-next v1 09/14] selftests/bpf: Fix double thread join in uprobe_multi_test
Posted by Ihor Solodrai 1 month, 2 weeks ago
ASAN reported a "joining already joined thread" error. The
release_child() may be called multiple times for the same struct
child.

Fix by setting child->thread to 0 after pthread_join.

Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
---
 tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
index 2ee17ef1dae2..17881e009eee 100644
--- a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
@@ -62,8 +62,10 @@ static void release_child(struct child *child)
 		return;
 	close(child->go[1]);
 	close(child->go[0]);
-	if (child->thread)
+	if (child->thread) {
 		pthread_join(child->thread, NULL);
+		child->thread = 0;
+	}
 	close(child->c2p[0]);
 	close(child->c2p[1]);
 	if (child->pid > 0)
-- 
2.53.0
Re: [PATCH bpf-next v1 09/14] selftests/bpf: Fix double thread join in uprobe_multi_test
Posted by Mykyta Yatsenko 1 month, 2 weeks ago
On 2/12/26 01:13, Ihor Solodrai wrote:
> ASAN reported a "joining already joined thread" error. The
> release_child() may be called multiple times for the same struct
> child.
>
> Fix by setting child->thread to 0 after pthread_join.
>
> Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
> ---
>   tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
> index 2ee17ef1dae2..17881e009eee 100644
> --- a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
> +++ b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
> @@ -62,8 +62,10 @@ static void release_child(struct child *child)
>   		return;
>   	close(child->go[1]);
>   	close(child->go[0]);
> -	if (child->thread)
> +	if (child->thread) {
>   		pthread_join(child->thread, NULL);
> +		child->thread = 0;
> +	}
>   	close(child->c2p[0]);
>   	close(child->c2p[1]);
>   	if (child->pid > 0)
As far as I understand the problem is due to `static struct child child` in
the test_attach_api(), once we initialize thread field of the child
it's not reset before the next test run.
Maybe we should also add memset(&child, 0, sizeof(child));
in test_attach_api() before each test to make sure all fields are reset.

Acked-by: Mykyta Yatsenko <yatsenko@meta.com>
Re: [PATCH bpf-next v1 09/14] selftests/bpf: Fix double thread join in uprobe_multi_test
Posted by Jiri Olsa 1 month, 2 weeks ago
On Thu, Feb 12, 2026 at 02:49:09PM +0000, Mykyta Yatsenko wrote:
> On 2/12/26 01:13, Ihor Solodrai wrote:
> > ASAN reported a "joining already joined thread" error. The
> > release_child() may be called multiple times for the same struct
> > child.
> > 
> > Fix by setting child->thread to 0 after pthread_join.
> > 
> > Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
> > ---
> >   tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c | 4 +++-
> >   1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
> > index 2ee17ef1dae2..17881e009eee 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
> > @@ -62,8 +62,10 @@ static void release_child(struct child *child)
> >   		return;
> >   	close(child->go[1]);
> >   	close(child->go[0]);
> > -	if (child->thread)
> > +	if (child->thread) {
> >   		pthread_join(child->thread, NULL);
> > +		child->thread = 0;
> > +	}
> >   	close(child->c2p[0]);
> >   	close(child->c2p[1]);
> >   	if (child->pid > 0)
> As far as I understand the problem is due to `static struct child child` in
> the test_attach_api(), once we initialize thread field of the child
> it's not reset before the next test run.
> Maybe we should also add memset(&child, 0, sizeof(child));
> in test_attach_api() before each test to make sure all fields are reset.

right, perhaps we could do memset right away in release_child,

jirka

> 
> Acked-by: Mykyta Yatsenko <yatsenko@meta.com>
>
Re: [PATCH bpf-next v1 09/14] selftests/bpf: Fix double thread join in uprobe_multi_test
Posted by Jiri Olsa 1 month, 2 weeks ago
On Wed, Feb 11, 2026 at 05:13:51PM -0800, Ihor Solodrai wrote:
> ASAN reported a "joining already joined thread" error. The
> release_child() may be called multiple times for the same struct
> child.
> 
> Fix by setting child->thread to 0 after pthread_join.
> 
> Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka


> ---
>  tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
> index 2ee17ef1dae2..17881e009eee 100644
> --- a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
> +++ b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
> @@ -62,8 +62,10 @@ static void release_child(struct child *child)
>  		return;
>  	close(child->go[1]);
>  	close(child->go[0]);
> -	if (child->thread)
> +	if (child->thread) {
>  		pthread_join(child->thread, NULL);
> +		child->thread = 0;
> +	}
>  	close(child->c2p[0]);
>  	close(child->c2p[1]);
>  	if (child->pid > 0)
> -- 
> 2.53.0
> 
>