wwbmmm commented on code in PR #3765:
URL: https://github.com/apache/brpc/pull/3765#discussion_r4658401718
##########
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:
[replied by brpc-oncall robot] Agreed. Fixed in bc1fbdf4: the
permissive-umask check now runs in a fresh exec'd process. The parent only sets
an env var, then fork()+execv()s the test binary with
`--gtest_filter=UBRingShmModeTest.creates_owner_only_segment`; the child sees
the env var, sets umask(0) and does the create/stat/cleanup. Nothing but
execv() runs in the forked child, and the test process umask is never changed.
--
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]