Skip to content

fix(daemon): read the peer pid on FreeBSD via LOCAL_PEERCRED - #2967

Merged
DeusData merged 1 commit into
mainfrom
distill/2492-freebsd-peer-pid
Nov 13, 2026
Merged

DeusData merged 1 commit into
mainfrom
distill/2492-freebsd-peer-pid

Conversation

@DeusData

Copy link
Copy Markdown
Owner

Carries forward the FreeBSD peer-credential fix from #2492 by @romanov, credited with a Co-authored-by trailer.

cbm_daemon_ipc_connection_peer_pid() has branches for Linux (SO_PEERCRED), macOS (LOCAL_PEERPID) and NetBSD (LOCAL_PEEREID). FreeBSD defines none of them, so it returned 0, and runtime_accept_connection() closes every connection whose peer pid is 0: on FreeBSD the daemon rejected every client. The new branch reads struct xucred via getsockopt(SOL_LOCAL, LOCAL_PEERCRED) and accepts only the expected layout version, the caller's effective uid and a positive pid, mirroring the Linux branch.

Left out from #2492: three timeout increases that applied to every platform (CBM_STARTUP_TIMEOUT_MS already covers slow hosts).

Proof on FreeBSD 14.4 and 15.1, from a temporary probe on never-merged scratch branches that feeds the binary the smoke test's initialize / initialized / tools/list input:

On macOS, Linux and Windows the branch is compiled out (the preprocessed ipc.c is byte-identical on macOS).

cbm_daemon_ipc_connection_peer_pid() had branches for Linux
(SO_PEERCRED), macOS (LOCAL_PEERPID) and NetBSD (LOCAL_PEEREID), but
FreeBSD defines none of them, so it fell through to `return 0`, and
runtime_accept_connection() closes every connection whose peer pid is
0: on FreeBSD the daemon rejected every client.

Read the peer credentials with getsockopt(SOL_LOCAL, LOCAL_PEERCRED)
into a struct xucred and accept only the expected layout version, the
caller's effective uid and a positive pid, mirroring the Linux branch.
The branch and its <sys/ucred.h> include compile only on FreeBSD.

Carried forward from #2492, which also raised three timeouts on every
platform; those are left out (CBM_STARTUP_TIMEOUT_MS covers slow hosts).

Co-authored-by: Yury Romanov <[email protected]>
Signed-off-by: Martin Vogel <[email protected]>
@DeusData DeusData mentioned this pull request Nov 12, 2026
4 tasks
@DeusData
DeusData merged commit a3e9c91 into main Nov 13, 2026
64 of 68 checks passed
DeusData added a commit to htarnacki/codebase-memory-mcp that referenced this pull request Nov 13, 2026
Brings in main up to 09bd6bb (DeusData#2967 FreeBSD peer pid, DeusData#2974 graph
variation and content loss fixes).

Resolutions:
- scripts/memory-core-baseline.txt (textual conflict): both sides
  lowered counts in the same hunk. pass_parallel.c keeps this branch's
  29 (arena QNs); pass_pkgmap.c takes main's 80 (DeusData#2974 dropped one raw
  free in cbm_pkgmap_build; this branch's pass_pkgmap.c additions add
  no raw site). Both values re-derived by scanning the merged tree with
  scripts/lint-memory-core.py; the lint passes.
- src/pipeline/pass_pkgmap.c (auto-merged): main's deterministic
  manifest order in cbm_pkgmap_build and this branch's Scala package
  index sit in separate functions; the merged file is main plus this
  branch's change unchanged (same per-file patch-id).
- tests/test_edge_imports.c, tests/test_pipeline.c (auto-merged): both
  sides' new tests are kept and registered; main's new tests call no
  function this branch re-signed. Same per-file patch-id as this
  branch's change.

Every other file equals main.

Signed-off-by: Martin Vogel <[email protected]>
DeusData added a commit to ankitsusheel/codebase-memory-mcp that referenced this pull request Nov 14, 2026
Brings the branch up to main d68f491 (DeusData#2967, DeusData#2968, DeusData#2970, DeusData#2974).

src/pipeline/registry.c: main (DeusData#2968) gives registry_resolve_scoped the
calling definition's test verdict (`caller_test`), adds
cbm_registry_resolve_ref for references (USAGE, READS, WRITES) and
routes calls through a static resolve_call_lang. This branch wraps the
lookups with the VB.NET case-insensitive retry. Resolved by keeping
both: vb_resolve_folded takes `caller_test` and passes it to its own
lookup, and the retry hooks cbm_registry_resolve_lang (false),
cbm_registry_resolve_ref and resolve_call_lang (the caller's verdict),
exactly as main's first lookup in each. Without the hook in
cbm_registry_resolve_ref, VB.NET references would have stopped folding.

internal/cbm/vendored/grammars/MANIFEST.md: main added the sql row next
to the vbnet row this branch edits; both rows kept.

scripts/vendored-checksums.txt: regenerated with
scripts/security-vendored.sh --update; only the MANIFEST.md line
differs from main.

Adapted with the merge: the VB.NET registry test passes `false` as the
new caller_test argument of cbm_registry_resolve_call_scoped (a
production caller).

Signed-off-by: Martin Vogel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant