[PATCH net] selftests: af_unix: verify SCM_PIDFD pidfd in cmsg_check_dead()
Lei Zhu <[email protected]>
| Newsgroups | org.kernel.vger.linux-kselftest,org.kernel.vger.netdev |
|---|---|
| Message-ID | <[email protected]> |
From: Lei Zhu <[email protected]> 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 <[email protected]> --- 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