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(test,daemon): make the userns probe revert-sensitive and stop a false invariant shipping
Martin Vogelf9038b84eb3b
diff --git a/src/daemon/ipc.c b/src/daemon/ipc.cindex 1243405c7..cec3b60b4 100644--- a/src/daemon/ipc.c+++ b/src/daemon/ipc.c@@ -1572,7 +1572,17 @@ static void posix_overflow_init_once(void) {#endif /* __linux__ *//* The overflow uid tolerated for ancestors in this process, or- * POSIX_NO_OVERFLOW_UID when none. Derived once from immutable /proc state. */+ * POSIX_NO_OVERFLOW_UID when none.+ *+ * Derived once per process. NOT from immutable state, whatever an earlier+ * revision of this comment claimed: unshare(CLONE_NEWUSER) rewrites+ * /proc/self/uid_map, and pthread_once state survives fork() already marked+ * done. A child that forks WITHOUT exec and then changes namespace therefore+ * keeps the parent answer. That is safe here only because every caller runs in+ * a freshly exec'd process -- the daemon double-fork execs+ * (daemon/bootstrap.c), workers go through cbm_subprocess_spawn's fork+exec,+ * and src/ contains no setns/unshare at all. If you ever add a fork-without-exec+ * path that reaches this check, this cache is WRONG and must go. */static uid_t posix_ancestor_overflow_uid(void) {#ifdef CBM_ENABLE_TEST_SEAMSif (g_posix_overflow_override_active) {diff --git a/tests/test_daemon_ipc.c b/tests/test_daemon_ipc.cindex 9a10f838c..2da597add 100644--- a/tests/test_daemon_ipc.c+++ b/tests/test_daemon_ipc.c@@ -5203,7 +5203,19 @@ TEST(daemon_ipc_posix_single_uid_userns_real_smoke_issue1830) {if (WIFEXITED(status) && WEXITSTATUS(status) == 3) {FAIL("userns smoke could not re-exec /proc/self/exe for the probe");}- ASSERT_TRUE(WIFEXITED(status));+ /* {0,1,2,3} is the whole protocol. Any other code -- a sanitizer exit (LSan+ * defaults to 23), an abort, a signal -- is a broken harness, not a refusal,+ * and must say so with the code it actually saw. */+ if (!WIFEXITED(status)) {+ FAIL("userns probe did not exit normally (signalled) -- not a security verdict");+ }+ if (WEXITSTATUS(status) != 0 && WEXITSTATUS(status) != 1) {+ char unexpected[128];+ (void)snprintf(unexpected, sizeof(unexpected),+ "userns probe exited %d -- not a security verdict",+ WEXITSTATUS(status));+ FAIL(unexpected);+ }ASSERT_EQ(0, WEXITSTATUS(status));PASS();#elsediff --git a/tests/test_main.c b/tests/test_main.cindex 463a41c0a..e25de3026 100644--- a/tests/test_main.c+++ b/tests/test_main.c@@ -954,9 +954,13 @@ int main(int argc, char **argv) {* seven call sites do. Re-exec into this probe so the decision is made by a* process that STARTED inside the namespace, which is the production shape* the test means to cover. */-#if defined(__linux__)+#if defined(__linux__) && defined(CBM_ENABLE_TEST_SEAMS)if (argc == 3 && strcmp(argv[1], "--userns-secure-probe") == 0) {- return cbm_daemon_ipc_private_directory_secure(argv[2]) ? 0 : 1;+ /* _exit, not return: this process exists to answer ONE boolean. A+ * return runs the atexit chain, and the runner is built with+ * -fsanitize=address, so a future leak anywhere in the prologue would+ * exit 23 and read as a security verdict on a test that has none. */+ _exit(cbm_daemon_ipc_private_directory_secure(argv[2]) ? 0 : 1);}#endifint mcp_idxfailclosed_rc = tf_maybe_run_mcp_idxfailclosed_probe(argc, argv);