[PATCH mptcp-net 2/3] selftests: mptcp: avoid double closing pipe descriptor

Geliang Tang posted 3 patches 2 weeks, 1 day ago
There is a newer version of this series
[PATCH mptcp-net 2/3] selftests: mptcp: avoid double closing pipe descriptor
Posted by Geliang Tang 2 weeks, 1 day ago
From: Geliang Tang <tanggeliang@kylinos.cn>

The pipe descriptor (pipefds[0]) is already closed in main() after
the client() function completes, making the explicit close in
connect_one_server() redundant and potentially harmful.

This patch removes the unnecessary close operations in both the sockopt
and inq test cases to prevent double-closing of file descriptors, which
could lead to undefined behavior if the descriptor is reused.

Fixes: ce9979129a0b ("selftests: mptcp: add mptcp getsockopt test cases")
Fixes: b51880568f20 ("selftests: mptcp: add inq test case")
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/net/mptcp/mptcp_inq.c     | 2 --
 tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 1 -
 2 files changed, 3 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_inq.c b/tools/testing/selftests/net/mptcp/mptcp_inq.c
index 40f2a1b24763..5e2b5913121f 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_inq.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_inq.c
@@ -314,8 +314,6 @@ static void connect_one_server(int fd, int unixfd)
 	close(fd);
 	ret = write(unixfd, "closed", 6);
 	assert(ret == 6);
-
-	close(unixfd);
 }
 
 static void get_tcp_inq(struct msghdr *msgh, unsigned int *inqv)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
index b44b6c9b0550..8d590629a8e9 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
@@ -593,7 +593,6 @@ static void connect_one_server(int fd, int pipefd)
 	/* un-block server */
 	ret = read(pipefd, buf2, 4);
 	assert(ret == 4);
-	close(pipefd);
 
 	assert(strncmp(buf2, "xmit", 4) == 0);
 
-- 
2.48.1
Re: [PATCH mptcp-net 2/3] selftests: mptcp: avoid double closing pipe descriptor
Posted by Matthieu Baerts 2 weeks, 1 day ago
Hi Geliang,

Thank you for the fixes.

On 02/09/2025 03:38, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> The pipe descriptor (pipefds[0]) is already closed in main() after
> the client() function completes, making the explicit close in
> connect_one_server() redundant and potentially harmful.

Mmh, the close() are done from different processes, after fork(), no?

If yes, each process should close the fd, and what was done was correct.
Or did I miss something?

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.