* [PATCH net-next] selftests: net: py: close the wait pipe after reaping a command
@ 2026-11-22 15:48 Jingjing Xu
2026-11-30 17:42 ` Paolo Abeni
2026-11-30 17:50 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Jingjing Xu @ 2026-11-22 15:48 UTC (permalink / raw)
To: netdev; +Cc: linux-kselftest, kuba, edumazet, pabeni, horms, shuah, sdf, joe
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net-next] selftests: net: py: close the wait pipe after reaping a command
2026-11-22 15:48 [PATCH net-next] selftests: net: py: close the wait pipe after reaping a command Jingjing Xu
@ 2026-11-30 17:42 ` Paolo Abeni
2026-11-30 17:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Paolo Abeni @ 2026-11-30 17:42 UTC (permalink / raw)
To: Jingjing Xu, netdev
Cc: linux-kselftest, kuba, edumazet, horms, shuah, sdf, joe
On 11/22/26 16:48, Jingjing Xu 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.
>
> 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>
Note that this does not deserve the fixes tag: AFAICS selftest outcome
(fail/pass) does not change, and no system resources are permanently leaked.
This is a minor cleanup, dropping the fixes.
Also please consider most substantial targets for other works (i.e.
more reviews and testing are always appreciated).
/P
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net-next] selftests: net: py: close the wait pipe after reaping a command
2026-11-22 15:48 [PATCH net-next] selftests: net: py: close the wait pipe after reaping a command Jingjing Xu
2026-11-30 17:42 ` Paolo Abeni
@ 2026-11-30 17:50 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-11-30 17:50 UTC (permalink / raw)
To: Jingjing Xu
Cc: netdev, linux-kselftest, kuba, edumazet, pabeni, horms, shuah,
sdf, joe
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-30 17:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 15:48 [PATCH net-next] selftests: net: py: close the wait pipe after reaping a command Jingjing Xu
2026-11-30 17:42 ` Paolo Abeni
2026-11-30 17:50 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox