The branch main has been updated by olivier:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=727a83e90098e1c0fc4acdcf9b8099a70e6ea2b2

commit 727a83e90098e1c0fc4acdcf9b8099a70e6ea2b2
Author:     Olivier Cochard <[email protected]>
AuthorDate: 2026-07-30 14:28:42 +0000
Commit:     Olivier Cochard <[email protected]>
CommitDate: 2026-07-30 14:28:42 +0000

    tests/procdesc: Fix race in pdopenpid_pdwait_only_one
    
    The child exited immediately after pdfork(), so the parent's pdopenpid() 
could
    catch it mid-exit (P_WEXIT) and fail with EBUSY.
    Block the child on a pipe until the parent has opened the second descriptor,
    then release it
    
    Approved by:    markj
    Sponsored by:   Netflix
    Differential Revision:  https://reviews.freebsd.org/D58546
---
 tests/sys/kern/procdesc.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/tests/sys/kern/procdesc.c b/tests/sys/kern/procdesc.c
index 541f15b49338..1feaef34e2cb 100644
--- a/tests/sys/kern/procdesc.c
+++ b/tests/sys/kern/procdesc.c
@@ -519,16 +519,29 @@ ATF_TC_WITHOUT_HEAD(pdopenpid_pdwait_only_one);
 ATF_TC_BODY(pdopenpid_pdwait_only_one, tc)
 {
        pid_t child;
-       int fd1, fd2, status;
+       int fd1, fd2, pip[2], status;
+
+       ATF_REQUIRE_EQ(pipe(pip), 0);
 
        child = pdfork(&fd1, PD_DAEMON);
        ATF_REQUIRE_MSG(child >= 0, "pdfork: %s", strerror(errno));
-       if (child == 0)
+       if (child == 0) {
+               char c;
+
+               close(pip[1]);
+               /* Block until the parent has opened the second fd. */
+               (void)read(pip[0], &c, 1);
                _exit(42);
+       }
+       ATF_REQUIRE(close(pip[0]) == 0);
 
+       /* Open the second fd while the child is still alive. */
        fd2 = pdopenpid(child, 0);
        ATF_REQUIRE_MSG(fd2 >= 0, "pdopenpid: %s", strerror(errno));
 
+       /* Release the child so that it exits. */
+       ATF_REQUIRE(close(pip[1]) == 0);
+
        /* Collect via the first fd. */
        ATF_REQUIRE_MSG(pdwait(fd1, &status, WEXITED, NULL, NULL) == 0,
            "pdwait(fd1): %s", strerror(errno));

Reply via email to