Skip to content

Commit 91c63be

Browse files
DeusDataclaude
andcommitted
fix(cli): keep config follow-roots off the static TLS block (DeusData#2110)
DeusData#1954's config-symlink follow support stored its opted-in roots in a _Thread_local char[4][4096] -- 16 KiB in the binary's static TLS block. On glibc/x86-64 that block is carved out of every thread's stack, including the parent-death watchdog thread, created with a deliberately tiny 64 KiB stack (PARENT_WATCHDOG_STACK_SIZE, main.c). The extra 16 KiB pushed that thread's pthread_create past the static-TLS + TCB + guard budget, so it failed with EINVAL: client_start_parent_watchdog() returned false and the stdio server exited before answering initialize. The parent-death watchdog regression test (DeusData#406/DeusData#407, scripts/test.sh Step 5) went red on every Linux x86-64 leg while macOS/arm64 stayed green -- its TLS is not stack-carved. Move the buffer off the static TLS block: keep a _Thread_local POINTER (8 bytes) and calloc the 16 KiB lazily on first add, freeing it in follow_clear(). Per-thread isolation and the exact API/semantics are unchanged; the watchdog thread's static-TLS budget is restored. main.c and the watchdog path are untouched. Evidence (local, Linux x86-64 gcc under QEMU + Linux arm64): - PT_TLS MemSiz 59,889 B -> 43,505 B (-16,384 B, exactly the array). - parent-watchdog test 10/10 red -> 10/10 green; red again on revert. - origin/main 10/10 green on the same env (regression is PR-specific). - config editor + cli suites: 522/522 ASan/UBSan (macOS), 523/523 ASan/LeakSanitizer (Linux arm64), no leak. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent a3c24a7 commit 91c63be

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎src/cli/config_edit_path.c‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <errno.h>
1313
#include <stdio.h>
14+
#include <stdlib.h>
1415
#include <string.h>
1516

1617
#ifndef _WIN32
@@ -66,7 +67,16 @@ void cbm_config_edit_target_close(cbm_config_edit_target_t *target) {
6667

6768
#ifndef _WIN32
6869

69-
static CBM_TLS char edit_path_roots[EDIT_PATH_MAX_ROOTS][CBM_CONFIG_EDIT_PATH_MAX];
70+
/* The opted-in follow-roots are per-thread (test isolation), but the storage
71+
* is a heap buffer behind a thread-local POINTER, not a thread-local array.
72+
* A `_Thread_local char[4][4096]` sits in the binary's static TLS block, and
73+
* glibc carves that block out of every thread's stack allocation — including
74+
* the parent-death watchdog's deliberately tiny 64 KiB stack (main.c). The
75+
* 16 KiB array pushed the watchdog's pthread_create over the static-TLS +
76+
* guard budget, so it failed with EINVAL on glibc/x86-64 (green on macOS,
77+
* whose TLS is not stack-carved): #2110 CI. The pointer keeps the static TLS
78+
* block at 8 bytes; the buffer is allocated on first add and freed by clear. */
79+
static CBM_TLS char (*edit_path_roots)[CBM_CONFIG_EDIT_PATH_MAX] = NULL;
7080
static CBM_TLS size_t edit_path_root_count = 0U;
7181

7282
#ifdef CBM_CONFIG_EDIT_PATH_ENABLE_TEST_API
@@ -101,6 +111,12 @@ int cbm_config_edit_path_follow_add_root(const char *root) {
101111
if (!cbm_canonical_path(root, canonical, sizeof(canonical))) {
102112
return -1;
103113
}
114+
if (!edit_path_roots) {
115+
edit_path_roots = calloc(EDIT_PATH_MAX_ROOTS, sizeof(*edit_path_roots));
116+
if (!edit_path_roots) {
117+
return -1;
118+
}
119+
}
104120
if (edit_path_copy(canonical, edit_path_roots[edit_path_root_count],
105121
sizeof(edit_path_roots[0])) != 0) {
106122
return -1;
@@ -111,6 +127,8 @@ int cbm_config_edit_path_follow_add_root(const char *root) {
111127

112128
void cbm_config_edit_path_follow_clear(void) {
113129
edit_path_root_count = 0U;
130+
free(edit_path_roots);
131+
edit_path_roots = NULL;
114132
}
115133

116134
static int edit_path_under_root(const char *canonical) {

0 commit comments

Comments
 (0)