Copilot commented on code in PR #3765:
URL: https://github.com/apache/brpc/pull/3765#discussion_r4657941718
##########
test/brpc_ubring_unittest.cpp:
##########
@@ -821,6 +825,74 @@ TEST(UBRingConfigurationTest,
time_flags_include_units_and_expected_defaults) {
USEC_TO_NSEC);
}
+// Newly created segments must not be accessible to other users of the host.
+// The UBS backend allocates through the external ubsm SDK, which is not
+// available in unit tests, so only the constant it passes to
+// ubsmem_shmem_allocate is checked here.
+TEST(UBRingShmModeTest, segment_mode_is_owner_only) {
+ EXPECT_EQ(0600, SHM_SEGMENT_MODE);
+ EXPECT_EQ(SHM_SEGMENT_MODE, SHM_IPC_MODE);
+}
+
+TEST(UBRingShmModeTest, ipc_segment_mode_and_peer_mapping) {
+ static std::atomic<uint32_t> name_sequence(0);
+ const std::string name = "/brpc_mode_" + std::to_string(getpid()) + "_" +
+ std::to_string(name_sequence.fetch_add(1, std::memory_order_relaxed));
+ brpc::ubring::SHM local_shm = {nullptr, 4 * 1024 * 1024, 0, {0}, 0};
+ ASSERT_LT(name.size(), sizeof(local_shm.name));
+ memcpy(local_shm.name, name.c_str(), name.size() + 1);
+
+ // A permissive umask must not widen the mode of a new segment. umask is
+ // process-wide, so this case runs in a child process and leaves the umask
+ // of this (possibly multi-threaded) process untouched. Only syscalls are
+ // used after the fork.
+ const pid_t pid = fork();
+ ASSERT_GE(pid, 0);
+ if (pid == 0) {
+ umask(0);
+ brpc::ubring::SHM child_shm = {nullptr, local_shm.len, 0, {0}, 0};
Review Comment:
This test still forks from the gtest process and then calls
`IpcShmLocalMalloc` in the child. brpc tests run with background threads, so
the child can inherit a mutex held by a thread that disappeared at `fork`; the
allocation path also uses logging and other non-async-signal-safe library code.
That can deadlock the child and leave the parent blocked in `waitpid`. The
existing HPack test documents this exact hazard
(`test/brpc_hpack_unittest.cpp:47-50`). Please move the umask check to a
separately exec'd helper process (or use another isolation mechanism) rather
than invoking the allocator after `fork`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]