From 9d2f3fb577f2bc4cff981cba5fd86b538d32cea2 Mon Sep 17 00:00:00 2001 From: milescoviello Date: Mon, 19 Oct 2026 01:04:18 +0000 Subject: [PATCH] test(libkernel): check close-on-exec on a received host descriptor The only MSG_CMSG_CLOEXEC case received sockets, whose F_GETFD reads the guest's close-on-exec set, so it passed whether or not the received host descriptor was marked. A pipe end goes through unchanged, so receiving one with the flag now has to read back FD_CLOEXEC. Co-Authored-By: Claude Opus 5.5 --- core/libs/tests/GuestSocketRights.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/libs/tests/GuestSocketRights.cpp b/core/libs/tests/GuestSocketRights.cpp index d7febd4124..1141ce3c87 100644 --- a/core/libs/tests/GuestSocketRights.cpp +++ b/core/libs/tests/GuestSocketRights.cpp @@ -133,6 +133,18 @@ static void CheckPassedPipe(const int (&pair)[2]) { Require(close_nid_postfix(writer) == 0); Require(read_nid_postfix(pipe[0], text, sizeof(text)) == 0); Require(close_nid_postfix(pipe[0]) == 0); + + int closing[2] = {-1, -1}; + Require(pipe_nid_postfix(closing) == 0); + control = RightsControl({closing[1]}, length); + Require(SendWith(pair[0], "exec", control.data(), length) == 4); + Require(close_nid_postfix(closing[1]) == 0); + const auto marked = ReceiveWith(pair[1], Space(sizeof(int)), ControlCloseOnExec); + Require(marked.bytes == 4 && marked.controlLength == Space(sizeof(int))); + RequireRecord(marked, 1); + const int markedWriter = ReceivedDescriptor(marked, 0); + Require(fcntl_nid_postfix(markedWriter, GetDescriptorFlags) == 1); + Require(close_nid_postfix(markedWriter) == 0 && close_nid_postfix(closing[0]) == 0); } static void CheckPassedSockets(const int (&pair)[2]) {