Thread (2 messages) flat view 2 messages, 2 authors, 12d ago
COOLING12d

[PATCH net] selftests: af_unix: verify SCM_PIDFD pidfd in cmsg_check_dead()

From: Lei Zhu <hidden>
Date: 2026-08-17 06:12:01
Also in: linux-kselftest
Subsystem: kernel selftest framework, networking [general], networking [unix sockets], the rest · Maintainers: Shuah Khan, Shuah Khan, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Kuniyuki Iwashima, Linus Torvalds

From: Lei Zhu <redacted>

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 <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help