Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Jingjing Xu
Sun, 22 Nov 2026 15:48
[PATCH net-next] selftests: net: py: close the wait pipe after reaping a command
Author: Jingjing Xu
Date: Sun, 22 Nov 2026 15:48
Date: Sun, 22 Nov 2026 15:48
55 lines
10751 bytes
10751 bytes
Commands started with ksft_wait keep the parent write end in ksft_term_fd.
After communicate() reaps the child, that descriptor is still open, so
each completed command leaks a pipe in the Python process.
Close the parent end after successful communication and clear its saved
value, before decoding output or reporting a failed child exit status.
Leave paths where communication has not completed unchanged.
Run this from tools/testing/selftests/net to repeat the supported pipe
handshake. It prints 16 on the original helper and 0 with the fix:
python3 - <<'PYCODE'
import os
from lib.py import bkg
child = ["python3", "-c",
"import os; os.write(int(os.environ['KSFT_READY_FD']), b'1');"
"os.read(int(os.environ['KSFT_WAIT_FD']), 1)"]
before = len(os.listdir("/proc/self/fd"))
for _ in range(16):
with bkg(child, ksft_wait=3): pass
print(len(os.listdir("/proc/self/fd")) - before)
PYCODE
Found by AI-assisted inspection. Both this reproducer and a C helper
using the existing ksft_ready()/ksft_wait() functions confirm the fix.
Normal completion, initialization EOF and nonzero child exit each leak
16 descriptors before and none after; ordinary and ready-only controls
remain clean. No kernel instrumentation or fault injection was used.
No hardware suite was run. Timeout cleanup and a child exiting after
readiness but before the parent's notification remain outside this fix.
Fixes: 71477137994f ("selftests: drv-net: add a way to wait for a local process")
Signed-off-by: Jingjing Xu <xujingjing@cmss.chinamobile.com>
---
tools/testing/selftests/net/lib/py/utils.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py
index 1727bc418073..72c5af28cc7e 100644
--- a/tools/testing/selftests/net/lib/py/utils.py
+++ b/tools/testing/selftests/net/lib/py/utils.py
@@ -105,6 +105,9 @@ class cmd:
if terminate:
self.proc.terminate()
stdout, stderr = self.proc.communicate(timeout=timeout)
+ if self.ksft_term_fd is not None:
+ os.close(self.ksft_term_fd)
+ self.ksft_term_fd = None
self.stdout = stdout.decode("utf-8")
self.stderr = stderr.decode("utf-8")
self.proc.stdout.close()
base-commit: 2208ab00f4f213ade91ab775e7f8c4dacdcc856e
--
2.53.0
Re: [PATCH net-next] selftests: net: py: close the wait pipe after reaping a command
Author: patchwork-bot+netdevbpf
Date: Mon, 30 Nov 2026 17:50
Date: Mon, 30 Nov 2026 17:50
25 lines
8739 bytes
8739 bytes
Hello:
This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Sun, 22 Nov 2026 15:48:27 +0000 you wrote:
> Commands started with ksft_wait keep the parent write end in ksft_term_fd.
> After communicate() reaps the child, that descriptor is still open, so
> each completed command leaks a pipe in the Python process.
>
> Close the parent end after successful communication and clear its saved
> value, before decoding output or reporting a failed child exit status.
> Leave paths where communication has not completed unchanged.
>
> [...]
Here is the summary with links:
- [net-next] selftests: net: py: close the wait pipe after reaping a command
https://git.kernel.org/netdev/net-next/c/df3ce1c37b94
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads