tools/testing/selftests/kselftest_harness.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
From: Geliang Tang <tanggeliang@kylinos.cn>
Fix the pidfd leak in kselftest_harness.h's __wait_for_test() where
childfd = syscall(__NR_pidfd_open, t->pid, 0) is never closed.
Fixes: 73a3cde97677 ("selftests: harness: Implement test timeouts through pidfd")
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
Hi,
While adding more TLS selftests for MPTCP KTLS development, a segmentation
fault occurred. Debugging revealed that the accept() failure was due to MPTCP
tests requiring over 1024 file descriptors simultaneously. I initially raised
the limit to 4096 in [1], but sashiko noted that the real issue was a pidfd
leak in kselftest_harness.h's __wait_for_test(). Hence, this fix addresses that.
Thanks,
-Geliang
[1]
https://patchwork.kernel.org/project/mptcp/patch/ced184831757eaae9e690f65d799809ed22cae28.1776469069.git.tanggeliang@kylinos.cn/
---
tools/testing/selftests/kselftest_harness.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index 75fb016cd190..b12bc4dc3230 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -1001,7 +1001,7 @@ static void __wait_for_test(struct __test_metadata *t)
fprintf(TH_LOG_STREAM,
"# %s: unable to wait on child pidfd\n",
t->name);
- return;
+ goto out;
} else if (ret == 0) {
timed_out = true;
/* signal process group */
@@ -1013,7 +1013,7 @@ static void __wait_for_test(struct __test_metadata *t)
fprintf(TH_LOG_STREAM,
"# %s: Failed to wait for PID %d (errno: %d)\n",
t->name, t->pid, errno);
- return;
+ goto out;
}
if (timed_out) {
@@ -1066,6 +1066,8 @@ static void __wait_for_test(struct __test_metadata *t)
t->name,
status);
}
+out:
+ close(childfd);
}
static void test_harness_list_tests(void)
--
2.51.0
Hi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Unstable: 2 failed test(s): packetdrill_dss packetdrill_mp_capable ⚠️
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/24653726761
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/08cec27d8824
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1083166
If there are some issues, you can reproduce them using the same environment as
the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normal
For more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a
stable tests suite when executed on a public CI like here, it is possible some
reported issues are not due to your modifications. Still, do not hesitate to
help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
On Mon, Apr 20, 2026 at 03:04:57PM +0800, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
(...)
> diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
> index 75fb016cd190..b12bc4dc3230 100644
> --- a/tools/testing/selftests/kselftest_harness.h
> +++ b/tools/testing/selftests/kselftest_harness.h
> @@ -1001,7 +1001,7 @@ static void __wait_for_test(struct __test_metadata *t)
> fprintf(TH_LOG_STREAM,
> "# %s: unable to wait on child pidfd\n",
> t->name);
> - return;
> + goto out;
> } else if (ret == 0) {
> timed_out = true;
> /* signal process group */
> @@ -1013,7 +1013,7 @@ static void __wait_for_test(struct __test_metadata *t)
> fprintf(TH_LOG_STREAM,
> "# %s: Failed to wait for PID %d (errno: %d)\n",
> t->name, t->pid, errno);
> - return;
> + goto out;
> }
>
> if (timed_out) {
> @@ -1066,6 +1066,8 @@ static void __wait_for_test(struct __test_metadata *t)
> t->name,
> status);
> }
> +out:
> + close(childfd);
I think the close() could be directly after the poll().
That would make the code simpler.
> }
>
> static void test_harness_list_tests(void)
> --
> 2.51.0
>
© 2016 - 2026 Red Hat, Inc.