Netdev List
 help / color / mirror / Atom feed
From: Lei Zhu <zhulei_szu@163.com>
To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org
Cc: kuniyu@google.com, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	shuah@kernel.org, zhulei_szu@163.com
Subject: [PATCH net] selftests: af_unix: verify SCM_PIDFD pidfd in cmsg_check_dead()
Date: Mon, 17 Aug 2026 14:11:21 +0800	[thread overview]
Message-ID: <20260817061121.239648-1-zhulei_szu@163.com> (raw)

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


             reply	other threads:[~2026-08-17  6:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-17  6:11 Lei Zhu [this message]
2026-08-17 15:41 ` [PATCH net] selftests: af_unix: verify SCM_PIDFD pidfd in cmsg_check_dead() Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260817061121.239648-1-zhulei_szu@163.com \
    --to=zhulei_szu@163.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox