Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
Merge branch 'main' into fix/1828-enospc-daemon-start-diagnostics
Martin Vogelca86fdb057b3
diff --cc tests/test_daemon_ipc.cindex c57fa7bb6,252351957..c6e0b900f--- a/tests/test_daemon_ipc.c+++ b/tests/test_daemon_ipc.c@@@ -4951,85 -4953,126 +4954,203 @@@ TEST(daemon_ipc_posix_world_writable_anASSERT_TRUE(refused);PASS();}++ #ifdef CBM_ENABLE_TEST_SEAMS+ /* #1830: /proc/self/uid_map single-uid detection. A single-uid map is exactly+ * one line "<inside> <outside> 1" whose inside id is our euid; anything else —+ * the init map, a count other than 1, a foreign inside id, extra lines, or junk+ * — must read as "not single-uid" so the overflow tolerance never engages. */+ TEST(daemon_ipc_posix_uid_map_single_uid_parse_issue1830) {+ const unsigned long me = 1000;+ ASSERT_TRUE(cbm_daemon_ipc_posix_uid_map_is_single_uid_for_test("1000 1000 1\n", me));+ ASSERT_TRUE(cbm_daemon_ipc_posix_uid_map_is_single_uid_for_test("1000 0 1", me));+ ASSERT_TRUE(!cbm_daemon_ipc_posix_uid_map_is_single_uid_for_test("0 0 4294967295\n", me));+ ASSERT_TRUE(!cbm_daemon_ipc_posix_uid_map_is_single_uid_for_test("1000 1000 2\n", me));+ ASSERT_TRUE(!cbm_daemon_ipc_posix_uid_map_is_single_uid_for_test("42 1000 1\n", me));+ ASSERT_TRUE(!cbm_daemon_ipc_posix_uid_map_is_single_uid_for_test("1000 1000 1\n0 0 1\n", me));+ ASSERT_TRUE(!cbm_daemon_ipc_posix_uid_map_is_single_uid_for_test("", me));+ ASSERT_TRUE(!cbm_daemon_ipc_posix_uid_map_is_single_uid_for_test("not a map", me));+ PASS();+ }++ /* #1830: the ancestor accept/refuse decision. The overflow uid is tolerable for+ * an ancestor ONLY when the single-uid tolerance is engaged, and even then only+ * where a root owner would be: not world-writable unless sticky, and never+ * group-writable (the unmapped owner's host group is unknown). With tolerance+ * OFF (init/multi-uid/unreadable map) an overflow-owned ancestor is refused+ * exactly as before #1830 — that OFF row is what a revert of the tolerance+ * would collapse the ON rows to, so it pins the fix. euid/root/foreign owners+ * behave identically with tolerance on or off. */+ TEST(daemon_ipc_posix_overflow_ancestor_tolerated_only_in_single_uid_ns_issue1830) {+ const unsigned long euid = 1000;+ const unsigned long ovf = 65534;+ const unsigned long foreign = 4242;+ #define ANCESTOR_OK(owner, mode, on, ovfuid) \+ cbm_daemon_ipc_posix_ancestor_stat_ok_for_test((owner), (mode), euid, (on), (ovfuid))++ /* Overflow-owned ancestors, single-uid tolerance ENGAGED. */+ ASSERT_TRUE(ANCESTOR_OK(ovf, 0755, true, ovf));+ ASSERT_TRUE(ANCESTOR_OK(ovf, 0700, true, ovf));+ ASSERT_TRUE(ANCESTOR_OK(ovf, 01777, true, ovf)); /* sticky /tmp shape */+ ASSERT_TRUE(!ANCESTOR_OK(ovf, 0777, true, ovf)); /* world-writable, no sticky */+ ASSERT_TRUE(!ANCESTOR_OK(ovf, 0775, true, ovf)); /* group-writable overflow owner */++ /* Same ancestors, tolerance OFF — the pre-#1830 refusal (and the multi-uid /+ * unreadable-map path). A revert of the fix makes the ON rows read like these. */+ ASSERT_TRUE(!ANCESTOR_OK(ovf, 0755, false, 0));+ ASSERT_TRUE(!ANCESTOR_OK(ovf, 01777, false, 0));++ /* Controls unaffected by the tolerance. */+ ASSERT_TRUE(ANCESTOR_OK(euid, 0755, true, ovf));+ ASSERT_TRUE(ANCESTOR_OK(euid, 0700, false, 0));+ ASSERT_TRUE(ANCESTOR_OK(0, 01777, true, ovf)); /* root-owned sticky /tmp */+ ASSERT_TRUE(!ANCESTOR_OK(0, 0777, true, ovf)); /* root world-writable, no sticky */+ ASSERT_TRUE(!ANCESTOR_OK(foreign, 0755, true, ovf)); /* a mapped-out foreign uid */+ #undef ANCESTOR_OK+ PASS();+ }++ /* #1830 real end-to-end smoke: inside a single-uid user namespace the+ * root-owned ancestors (/, /tmp) are overflow-owned, and the daemon must still+ * create its private directory there. An overflow-owned ancestor cannot be+ * fabricated unprivileged, so this runs the real path only when a user+ * namespace is actually available. O10 whitelisted-skip everywhere it is not:+ * macOS has no user namespaces (compile-gated out); Docker's default seccomp+ * blocks unshare(CLONE_NEWUSER) on the Colima container leg; some kernels ship+ * user namespaces disabled. WHAT WAS TRIED when it skips: fork + unshare+ * CLONE_NEWUSER + a 1:1 uid_map write, which the sandbox denied (EPERM). The+ * deterministic decision coverage above is what binds the fix. */+ TEST(daemon_ipc_posix_single_uid_userns_real_smoke_issue1830) {+ #if defined(__linux__)+ uid_t host_uid = geteuid();+ char probe[TEST_PATH_CAP];+ (void)snprintf(probe, sizeof(probe), "/tmp/cbm-userns-smoke-%ld/x", (long)getpid());+ char probe_dir[TEST_PATH_CAP];+ (void)snprintf(probe_dir, sizeof(probe_dir), "/tmp/cbm-userns-smoke-%ld", (long)getpid());++ pid_t child = fork();+ if (child == 0) {+ /* Child: enter a single-uid user namespace mapping host_uid 1:1. */+ if (unshare(CLONE_NEWUSER) != 0) {+ _exit(2); /* userns unavailable → signal skip to the parent. */+ }+ int sg = open("/proc/self/setgroups", O_WRONLY | O_CLOEXEC);+ if (sg >= 0) {+ (void)!write(sg, "deny", 4);+ (void)close(sg);+ }+ int mf = open("/proc/self/uid_map", O_WRONLY | O_CLOEXEC);+ char line[64];+ int n = snprintf(line, sizeof(line), "%ld %ld 1", (long)host_uid, (long)host_uid);+ bool mapped = mf >= 0 && n > 0 && write(mf, line, (size_t)n) == n;+ if (mf >= 0) {+ (void)close(mf);+ }+ if (!mapped) {+ _exit(2);+ }+ /* Inside the ns / and /tmp now show the overflow uid. With #1830 the+ * daemon can still build its private tree there; without it, refused. */+ bool secured = cbm_daemon_ipc_private_directory_secure(probe);+ _exit(secured ? 0 : 1);+ }+ if (child < 0) {+ FAIL("fork failed for userns smoke");+ }+ int status = 0;+ while (waitpid(child, &status, 0) < 0 && errno == EINTR) {}+ (void)rmdir(probe);+ (void)rmdir(probe_dir);+ if (WIFEXITED(status) && WEXITSTATUS(status) == 2) {+ SKIP_PLATFORM("user namespaces unavailable (no CLONE_NEWUSER / seccomp-blocked)");+ }+ ASSERT_TRUE(WIFEXITED(status));+ ASSERT_EQ(0, WEXITSTATUS(status));+ PASS();+ #else+ SKIP_PLATFORM("user namespaces are Linux-only");+ #endif+ }+ #endif /* CBM_ENABLE_TEST_SEAMS */#endif /* !_WIN32 */+#ifndef _WIN32+enum { IPC_TEST_LOG_CAPTURE_CAP = 16384 };+static char ipc_test_log_capture[IPC_TEST_LOG_CAPTURE_CAP];+static size_t ipc_test_log_capture_used;++static void ipc_test_log_capture_sink(const char *line) {+ if (!line) {+ return;+ }+ size_t length = strlen(line);+ if (ipc_test_log_capture_used + length + 2 > sizeof(ipc_test_log_capture)) {+ return;+ }+ memcpy(ipc_test_log_capture + ipc_test_log_capture_used, line, length);+ ipc_test_log_capture_used += length;+ ipc_test_log_capture[ipc_test_log_capture_used++] = '\n';+ ipc_test_log_capture[ipc_test_log_capture_used] = '\0';+}++/* #1828: a full /tmp made every daemon start die at pending publication, and+ * the only durable trace was `daemon.ipc.listen_failed stage=pending_publication`+ * -- no syscall, no errno, no path. The reporter needed hours (and a wrong+ * `df` on the wrong mount) to find the cause. The failure line must name the+ * errno and the exact artifact path that could not be written. */+TEST(daemon_ipc_listen_failure_names_errno_and_path) {+ static const char key[] = "1828000000000001";+ char parent[TEST_PATH_CAP] = {0};+ char runtime_dir[TEST_PATH_CAP] = {0};+ char socket_path[TEST_PATH_CAP] = {0};+ char pending_path[TEST_PATH_CAP] = {0};+ char expected_path[TEST_PATH_CAP + 16] = {0};+ cbm_daemon_ipc_endpoint_t *endpoint = NULL;+ cbm_daemon_ipc_listener_t *listener = NULL;++ bool parent_ok = ipc_test_parent_new(parent, "enospc-diag");+ if (parent_ok) {+ endpoint = cbm_daemon_ipc_endpoint_new(key, parent);+ }+ if (endpoint) {+ ipc_test_copy_path(runtime_dir, cbm_daemon_ipc_endpoint_runtime_dir(endpoint));+ ipc_test_copy_path(socket_path, cbm_daemon_ipc_endpoint_address(endpoint));+ }+ bool paths_ok = endpoint && ipc_test_socket_pending_path(pending_path, socket_path) &&+ snprintf(expected_path, sizeof(expected_path), "path=%s.tmp", pending_path) > 0;+ if (paths_ok) {+ ipc_test_log_capture_used = 0;+ ipc_test_log_capture[0] = '\0';+ cbm_daemon_ipc_posix_record_write_failure_set_for_test(ENOSPC);+ cbm_log_set_sink_ex(ipc_test_log_capture_sink, CBM_LOG_SINK_REPLACE);+ listener = cbm_daemon_ipc_listen(endpoint);+ cbm_log_set_sink(NULL);+ cbm_daemon_ipc_posix_record_write_failure_set_for_test(0);+ }+ const char *failed = strstr(ipc_test_log_capture, "msg=daemon.ipc.listen_failed");+ bool stage_named = failed && strstr(failed, "stage=pending_publication") != NULL;+ bool errno_named = failed && strstr(failed, "errno=ENOSPC") != NULL;+ bool path_named = failed && strstr(failed, expected_path) != NULL;+ struct stat leftover;+ bool namespace_clean = paths_ok && lstat(socket_path, &leftover) != 0 && errno == ENOENT &&+ lstat(pending_path, &leftover) != 0 && errno == ENOENT;++ cbm_daemon_ipc_listener_close(listener);+ cbm_daemon_ipc_endpoint_free(endpoint);+ th_cleanup(parent_ok ? parent : NULL);++ ASSERT_TRUE(parent_ok);+ ASSERT_TRUE(paths_ok);+ ASSERT_TRUE(listener == NULL);+ ASSERT_TRUE(failed != NULL);+ ASSERT_TRUE(stage_named);+ ASSERT_TRUE(errno_named);+ ASSERT_TRUE(path_named);+ ASSERT_TRUE(namespace_clean);+ PASS();+}+#endif+SUITE(daemon_ipc) {RUN_TEST(daemon_ipc_pending_timeout_race_returns_completed_io);RUN_TEST(daemon_ipc_pending_wait_failure_cancels_and_drains);