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
fix(daemon): admit a group-writable ancestor, and stop inventing an errno (#1537)
Martin Vogelb91abca173ef
diff --git a/src/daemon/ipc.c b/src/daemon/ipc.cindex 92a36b744..d9b1a98e5 100644--- a/src/daemon/ipc.c+++ b/src/daemon/ipc.c@@ -1383,8 +1383,26 @@ static bool posix_directory_parent_secure(int directory_fd) {!cbm_macos_extended_acl_fd_is_deny_only(directory_fd)) {return false;}- return (status.st_mode & 0022) == 0 ||- (status.st_uid == (uid_t)0 && (status.st_mode & S_ISVTX) != 0);+ /* #1537: this ANCESTOR check refused any group-write bit, which is the same+ * rule #1535 removed on the activation side — and the sibling that decision+ * covers but that never got changed. A group-writable ~ or ~/.cache is+ * ordinary (WSL2 ships 0775, so do several distro skeletons and any site+ * with a shared primary group), and refusing it here made the daemon+ * unusable with no way for the reader to see why.+ *+ * WORLD-writable is still refused: any local user could swap a path+ * component. Group-writable is admitted for ancestors only — the private+ * directory itself is chmod'd to 0700 and verified after this walk, so the+ * thing that actually holds data stays owner-private either way. */+ if ((status.st_mode & 0002) != 0) {+ return status.st_uid == (uid_t)0 && (status.st_mode & S_ISVTX) != 0;+ }+ if ((status.st_mode & 0020) != 0) {+ char mode_text[16];+ (void)snprintf(mode_text, sizeof(mode_text), "%04o", (unsigned)(status.st_mode & 07777));+ cbm_log_warn("daemon.private_dir_group_writable_ancestor", "mode", mode_text);+ }+ return true;}/* Validate a path transition only through the two already-open directory@@ -1435,6 +1453,17 @@ static int private_directory_tree_open(const char *directory_path) {ok = false;} else {ok = posix_directory_parent_secure(current_fd);+ if (!ok) {+ /* #1537: this branch used to leave the detail empty, so the+ * caller fell back to printing errno — which NOTHING here sets.+ * A reporter was handed "errno 2" (ENOENT) for a permission+ * refusal and went looking for a missing file that existed.+ * An unset errno is not a diagnosis; name the component. */+ ipc_validation_detail_set("%s: ancestor '%s' is not a usable private-directory "+ "parent (must be owned by you, not world-writable, and "+ "carry no allow-ACL)",+ directory_path, component);+ }bool created = ok && mkdirat(current_fd, component, 0700) == 0;if (!created && errno != EEXIST) {ok = false;diff --git a/tests/test_daemon_ipc.c b/tests/test_daemon_ipc.cindex 94754230e..977826751 100644--- a/tests/test_daemon_ipc.c+++ b/tests/test_daemon_ipc.c@@ -1667,8 +1667,7 @@ TEST(daemon_ipc_endpoint_is_namespaced_by_instance_key) {if (a_startup_status == 1 && !cbm_daemon_ipc_startup_lock_prepare_handoff(a_startup)) {a_startup_status = -1;}- if (other_startup_status == 1 &&- !cbm_daemon_ipc_startup_lock_prepare_handoff(other_startup)) {+ if (other_startup_status == 1 && !cbm_daemon_ipc_startup_lock_prepare_handoff(other_startup)) {other_startup_status = -1;}cbm_daemon_ipc_startup_lock_release(&a_startup);@@ -4712,6 +4711,83 @@ TEST(daemon_ipc_posix_rejects_non_socket_and_symlink_endpoints) {#endif /* !_WIN32 */+#ifndef _WIN32+/* #1537: the daemon's private-directory ancestry walk refused ANY group-write+ * bit on an ancestor — the same rule #1535 removed on the activation side, and+ * the sibling the consolidated strictness decision covers but that never got+ * changed. A group-writable ~ or ~/.cache is ordinary (WSL2 ships 0775, so do+ * several distro skeletons and any shared-primary-group site), so the daemon+ * was unusable there. World-writable must still be refused: any local user+ * could swap a path component. And the private directory itself must still end+ * up owner-private, which is what makes admitting the ancestor safe. */+TEST(daemon_ipc_posix_group_writable_ancestor_is_admitted_issue1537) {+ char parent[TEST_PATH_CAP];+ char ancestor[TEST_PATH_CAP];+ char cache[TEST_PATH_CAP];+ bool paths_ok = false;+ bool ancestor_ready = false;+ bool secured = false;+ bool leaf_owner_private = false;++ if (ipc_test_parent_new(parent, "posix-group-writable-ancestor")) {+ int a = snprintf(ancestor, sizeof(ancestor), "%s/group-writable", parent);+ int c = snprintf(cache, sizeof(cache), "%s/cache", ancestor);+ paths_ok = a > 0 && a < (int)sizeof(ancestor) && c > 0 && c < (int)sizeof(cache);+ }+ if (paths_ok) {+ ancestor_ready = mkdir(ancestor, 0775) == 0 && chmod(ancestor, 0775) == 0;+ }+ if (ancestor_ready) {+ secured = cbm_daemon_ipc_private_directory_secure(cache);+ struct stat leaf;+ leaf_owner_private =+ stat(cache, &leaf) == 0 && S_ISDIR(leaf.st_mode) && (leaf.st_mode & 07777) == 0700;+ }++ (void)rmdir(cache);+ (void)rmdir(ancestor);+ ipc_test_remove_flat_dir(parent);++ ASSERT_TRUE(paths_ok);+ ASSERT_TRUE(ancestor_ready);+ ASSERT_TRUE(secured);+ ASSERT_TRUE(leaf_owner_private);+ PASS();+}++/* The other half of the same decision: world-writable stays refused. A rule+ * that admitted everything would "fix" #1537 by removing the protection. */+TEST(daemon_ipc_posix_world_writable_ancestor_still_refused_issue1537) {+ char parent[TEST_PATH_CAP];+ char ancestor[TEST_PATH_CAP];+ char cache[TEST_PATH_CAP];+ bool paths_ok = false;+ bool ancestor_ready = false;+ bool refused = false;++ if (ipc_test_parent_new(parent, "posix-world-writable-ancestor")) {+ int a = snprintf(ancestor, sizeof(ancestor), "%s/world-writable", parent);+ int c = snprintf(cache, sizeof(cache), "%s/cache", ancestor);+ paths_ok = a > 0 && a < (int)sizeof(ancestor) && c > 0 && c < (int)sizeof(cache);+ }+ if (paths_ok) {+ ancestor_ready = mkdir(ancestor, 0777) == 0 && chmod(ancestor, 0777) == 0;+ }+ if (ancestor_ready) {+ refused = !cbm_daemon_ipc_private_directory_secure(cache);+ }++ (void)rmdir(cache);+ (void)rmdir(ancestor);+ ipc_test_remove_flat_dir(parent);++ ASSERT_TRUE(paths_ok);+ ASSERT_TRUE(ancestor_ready);+ ASSERT_TRUE(refused);+ PASS();+}+#endif /* !_WIN32 */+SUITE(daemon_ipc) {RUN_TEST(daemon_ipc_pending_timeout_race_returns_completed_io);RUN_TEST(daemon_ipc_pending_wait_failure_cancels_and_drains);@@ -4750,6 +4826,8 @@ SUITE(daemon_ipc) {RUN_TEST(daemon_ipc_windows_startup_release_retains_retry_authority);RUN_TEST(daemon_ipc_frame_timeout_poisons_connection);#ifndef _WIN32+ RUN_TEST(daemon_ipc_posix_group_writable_ancestor_is_admitted_issue1537);+ RUN_TEST(daemon_ipc_posix_world_writable_ancestor_still_refused_issue1537);RUN_TEST(daemon_ipc_posix_startup_lock_is_cross_process);RUN_TEST(daemon_ipc_posix_lifetime_reservation_rejects_fork_inheritance);RUN_TEST(daemon_ipc_posix_child_participant_handoff_retains_legacy_bridge);