All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] selftests: af_unix: verify SCM_PIDFD pidfd in cmsg_check_dead()
@ 2026-08-17  6:11 Lei Zhu
  2026-08-17 15:41 ` Jakub Kicinski
  0 siblings, 1 reply; 2+ messages in thread
From: Lei Zhu @ 2026-08-17  6:11 UTC (permalink / raw)
  To: netdev, linux-kselftest
  Cc: kuniyu, davem, edumazet, kuba, pabeni, horms, shuah, zhulei_szu

From: Lei Zhu <zhulei@kylinos.cn>

The cmsg_check_dead() function receives an expected_pid parameter but never
actually verifies that the pidfd received via SCM_PIDFD corresponds to that
PID. It only checks the child's exit code via PIDFD_GET_INFO.

Add a PID verification step using get_pid_from_fdinfo_file() to confirm
that the pidfd indeed points to the expected process, matching the
behavior already present in cmsg_check().

Fixes: 861bdc6314a4 ("selftests: net: extend SCM_PIDFD test to cover stale pidfds")
Signed-off-by: Lei Zhu <zhulei@kylinos.cn>
---
 tools/testing/selftests/net/af_unix/scm_pidfd.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/af_unix/scm_pidfd.c b/tools/testing/selftests/net/af_unix/scm_pidfd.c
index 2c18b92a2603..bfc99d0c5ac0 100644
--- a/tools/testing/selftests/net/af_unix/scm_pidfd.c
+++ b/tools/testing/selftests/net/af_unix/scm_pidfd.c
@@ -276,8 +276,15 @@ static int cmsg_check_dead(int fd, int expected_pid)
 		return 1;
 	}
 
+	/* pidfd from SCM_PIDFD should point to the client_pid */
+	pid_t pid = get_pid_from_fdinfo_file(*res.pidfd, "Pid:", sizeof("Pid:") - 1);
+	if (pid != expected_pid) {
+		log_err("wrong SCM_PIDFD %d != %d", pid, expected_pid);
+		close(*res.pidfd);
+		return 1;
+	}
+
 	/*
-	 * pidfd from SCM_PIDFD should point to the client_pid.
 	 * Let's read exit information and check if it's what
 	 * we expect to see.
 	 */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] selftests: af_unix: verify SCM_PIDFD pidfd in cmsg_check_dead()
  2026-08-17  6:11 [PATCH net] selftests: af_unix: verify SCM_PIDFD pidfd in cmsg_check_dead() Lei Zhu
@ 2026-08-17 15:41 ` Jakub Kicinski
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2026-08-17 15:41 UTC (permalink / raw)
  To: Lei Zhu
  Cc: netdev, linux-kselftest, kuniyu, davem, edumazet, pabeni, horms,
	shuah

On Mon, 17 Aug 2026 14:11:21 +0800 Lei Zhu wrote:
> The cmsg_check_dead() function receives an expected_pid parameter but never
> actually verifies that the pidfd received via SCM_PIDFD corresponds to that
> PID. It only checks the child's exit code via PIDFD_GET_INFO.

this breaks the test:

  (scm_pidfd.c:282: errno: None) wrong SCM_PIDFD -1 != <PID>

If you want to improve the test please repost this patch in 2 weeks
after the merge window. This patch should not carry the Fixes tag.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-17 15:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-17  6:11 [PATCH net] selftests: af_unix: verify SCM_PIDFD pidfd in cmsg_check_dead() Lei Zhu
2026-08-17 15:41 ` Jakub Kicinski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.