🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20451

[PATCH net-next] selftests: net: py: close the wait pipe after reaping a command

#20451
From: Jingjing Xu
Date: Sun, 22 Nov 2026 15:48
55 lines
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
Technical Details
Message-ID: <20261122154827.1272059-1-xujingjing@cmss.chinamobile.com>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368729-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368729-linux-kernel-netdev=dewy.ru
From: xujingjing@cmss.chinamobile.com (Jingjing Xu)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next] selftests: net: py: close the wait pipe after reaping a command
Date: Sun, 22 Nov 2026 15:48:27 +0000
Organization: Usenet Network
Message-ID: <20261122154827.1272059-1-xujingjing@cmss.chinamobile.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3669478"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:enC2KWcYEnMtaqlogQyVnXY9Ci4= sha256:tTQpWRRR0ab331BHBZx3hgAxBA7uNiOZDoclrvkyAKc=
	sha1:yiDkRwFEPFtFSs8gBNEWGsqnriA= sha256:KWXlnZ6Vygcfumes6QfTuBMggwH5PEKbpejKQTH8I0g=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 8EE2D125D80; Sun, 22 Nov 2026 18:48:54 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.75
X-Spam-Status: No, score=-2.75 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_INVALID=0.1, DKIM_SIGNED=0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=fail (1024-bit key)
	reason="fail (body has been altered)" header.d=cmss.chinamobile.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id qo5b2I2tmzQj;
	Sun, 22 Nov 2026 18:48:49 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-368729-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=cmss.chinamobile.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 90F8E125D7F; Sun, 22 Nov 2026 18:48:40 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 5FAC228347; Sun, 22 Nov 2026 15:48:39 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795362516;
	b=2ZLwZ3tHBfkQADmogSKvjlp+WesEt6Zr6dEUDQ5J0XGLOrbMoAePSPGCUDKx0033zA6H
	 Pxwg5DbHKn5iDrkxLvVKzE+P/UyfKWM3Rz6P6STrtxQIYRDJt60v/qB0BHaecslcU/id4
	 rrvC1t2f1diBoWpCC90nv0pwwDpCHyejJCkGiLOY8dosGE5CT7Ci0abonSoSYhV+Yg9Yo
	 nMWVNbbkHvGC6v6V7Zcmk0+LN5qa7dowFZXf7+hsOLPYuMQy7lWEcq5Zcz/0etYVSr8uJ
	 PThjrcZqSl86PBmVJ3y/7agNwP9MiFiPsE6H/57eunCIu5HzMQWOuPXmxMDwv5+CG0Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795362516;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:X-RM-TagInfo:
	 X-RM-SPAM-FLAG:Received:X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:
	 Received:X-RM-TRANSID:From:To:Cc:Subject:Date:Message-ID:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=tpi/k1b3USKHOwp9PPTXHQukTIfxQUIEB/5FP/mhyf0=;
	b=EM022sayvdCNbwL7iKTL6XD426n0282YvD6V+A8dB0uaBJ8Alf72enrVqzsGyTLueHBf
	 QsGgzI1ByLYv4E6FXrk9MFo7/3zrsAp/UY6rrdO7eMQnhSopb5YFuzJLfJkrUdzei5UsG
	 +O/gX2BZNp3ZPh3REbZl5jdpduI4LLWQJiIqsvnkEyRNwaKAGKc31M57M94pYzqvctxWt
	 GiEBBjuGTxKKP+2J6w6U2ct2Bw845PdAYlVOoMsM7GMOVu70SV+49M1GSqwTymiz2pSic
	 +bjaLp3RdXinZf30Ga6BU8AjlZx3t+QYZ/SNR3hiaDj+h9G5GLn44RUgDMKOgZ/TFfg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=h2QxIDAy;
	dmarc=pass header.from=cmss.chinamobile.com;
	spf=pass smtp.mailfrom=cmss.chinamobile.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id A7BCD606A334;
	Sun, 22 Nov 2026 15:48:36 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=h2QxIDAy
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=111.22.67.137
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795362515;
	b=qiK3MUPGyEchIwPxKw+qVLLZCuh17XZ6D10paXUQwJ7uKONGls4ctxwle29qqJe0K0Rb
	 WehHv5LAmGyrS6YvFJ9Zf66aindh1eQxoMScw+2kzKUmepj+qQggyzeDZgN7kEOhtClko
	 nzYW3KxQMoaBeB/ERZeeBvoevhOibl66z68qgyD6JMsFtTv/xEDEWkR7FBWn4/V15uOTg
	 F7n8KKXn/Xe4DCvTIyIiIu1NvDPFRoCpOibRw7j4p9iotj4alW0jRbpcKtCItdPhje41U
	 XOo3xM1Jnkhyw68UvKtE80r4SFTW0LugbHwu3Ko1MVr+9d6LQnD+VqcdY3V15oKOAag==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795362515;
	h=DMARC-Filter:DKIM-Signature:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:
	 X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:X-RM-TRANSID:From:
	 To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Transfer-Encoding;
	bh=tpi/k1b3USKHOwp9PPTXHQukTIfxQUIEB/5FP/mhyf0=;
	b=Z5aQzsJC2HqLKJx42wy4tt7Qnt0kSrDScnCPvQPaK4o+mI955gHpNddge33HBV5ZfeWz
	 Dr6x9zOaqZFUu3tQfzXnkyFnyznnNmbYUEeYFqT4KBSu83btKMvlJEPRT/mQWPdTLN9r9
	 3++gd2cyeEGFiLkf0aKgwVg/XDfHMgcyoUhi6voYDJfczxJvAUoRoUpoKWhQIPyV9fU9C
	 emWFKrLWqK22FTgkpovJOpzaaRntaQtMTk7/QL/dxB0qsGFjgPB2CC6GF9Al5UVbXnWL3
	 119DuioJwg29USYiKqTMzE9LQgQVMyflWSZT0UYMDYYo4MYaynR8qnai3r5ZxiKYcTg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=cmss.chinamobile.com;
	spf=pass smtp.mailfrom=cmss.chinamobile.com;
	dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=h2QxIDAy;
	arc=none smtp.remote-ip=111.22.67.137
X-Received: from cmccmta4.chinamobile.com (cmccmta4.chinamobile.com [111.22.67.137])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id DA854606A320;
	Sun, 22 Nov 2026 15:48:31 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DA854606A320
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmss.chinamobile.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmss.chinamobile.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=cmss.chinamobile.com; s=default; l=0;
	h=from:subject:message-id:to:cc:mime-version;
	bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=;
	b=h2QxIDAyQ6AjiTtLOAHPYyqgFapkERNPrI5Xg9hH/Vg+Af/dILQpJUSE9X+bMUDjn2Uo2IR62HxYv
	 TwJq+qf842mgYqtfyLJr8yJIoSkcXhv4b2mw+Bd7QKXG9anPVphuMvVaE+YOD67YqIWwRFFg7GcS3v
	 e7MlIwY8bjlMzFnw=
X-RM-TagInfo: emlType=0                                       
X-RM-SPAM-FLAG: 00000000
X-Received: from spf.mail.chinamobile.com (unknown[10.188.0.87])
	by rmmx-syy-dmz-app08-12008 (RichMail) with SMTP id 2ee86b030ec0b17-d4348;
	Sun, 22 Nov 2026 23:48:28 +0800 (CST)
X-RM-TRANSID: 2ee86b030ec0b17-d4348
X-RM-TagInfo: emlType=0                                       
X-RM-SPAM-FLAG: 00000000
X-Received: from home-ubuntu-251 (unknown[180.106.213.53])
	by rmsmtp-syy-appsvr01-12001 (RichMail) with SMTP id 2ee16b030ecb7c2-72e24;
	Sun, 22 Nov 2026 23:48:28 +0800 (CST)
X-RM-TRANSID: 2ee16b030ecb7c2-72e24
X-Cc: linux-kselftest@vger.kernel.org,
	kuba@kernel.org,
	edumazet@kernel.org,
	pabeni@redhat.com,
	horms@kernel.org,
	shuah@kernel.org,
	sdf@fomichev.me,
	joe@dama.to
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list