Skip to content

emacs/fixrand.c: guard against NULL real_clock_gettime from dlsym failure - #278

Closed
edge-delta[bot] wants to merge 21 commits into
unstablefrom
fix/fixrand-null-clock-gettime-guard
Closed

emacs/fixrand.c: guard against NULL real_clock_gettime from dlsym failure#278
edge-delta[bot] wants to merge 21 commits into
unstablefrom
fix/fixrand-null-clock-gettime-guard

Conversation

@edge-delta

@edge-delta edge-delta Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a NULL pointer guard before calling through real_clock_gettime in the clock_gettime LD_PRELOAD interposer. If dlsym(RTLD_NEXT, "clock_gettime") fails (returns NULL) and the caller requests a clock other than CLOCK_REALTIME, the code previously dereferenced a NULL function pointer — crashing the process with SIGSEGV. Now it returns -1 with errno = ENOSYS.

Triggered by push alert monitorEventId=3FNVByLKQSe4omCvDwADCLVKbhL on commit 78c875f018da565575d949eef4cfed3cdce238c2 (merge of PR #273 into unstable).

Related issues

Changes

  • packages/emacs/fixrand.c: Added if (!real_clock_gettime) { errno = ENOSYS; return -1; } before the return real_clock_gettime(clk_id, tp) fallthrough, preventing a NULL pointer dereference when dlsym fails to resolve the real clock_gettime symbol.

Checklist

  • I've read CONTRIBUTING.md.
  • I've accepted the ICLA (and CCLA if contributing on my employer's time). CLA Assistant will prompt me on this PR if I haven't already.
  • min check passes for the affected packages/harnesses.
  • min patched-build <name> succeeds for any package I added or modified.
  • For new packages: source_provenance points to the canonical upstream and the source builds from source (not a prebuilt release binary) where the required toolchain is available.
  • For version bumps: I've verified the new sha256 against the upstream archive.

Notes for reviewers

This is a one-line defensive guard with no happy-path behavior change. dlsym(RTLD_NEXT, ...) can fail in unusual linker configurations (e.g., if the shim is loaded without libc in the link chain, or in static-linked contexts). The existing read() interposer at line 50 has the same latent issue but predates this push — out of scope for this fix.

Complementary to PR #274 which hardens strtoll validation on the same function's SOURCE_DATE_EPOCH parsing — this fix addresses a different failure path (dlsym resolution, not input validation).


This pull/merge request was created by Edge Delta AI Teammates — automated NULL-safety fix from push event code review.


This pull/merge request was created by Edge Delta AI Teammates — see #code-issues for the original conversation.

0chroma and others added 21 commits June 1, 2026 17:05
Add package for the Haskell Language Server (HLS), the official LSP
implementation for Haskell. Builds from source using GHC + Cabal with
dynamic linking, copying the binary and all required shared libraries
via ldd dependency resolution.

- Source: GitHub tag 2.14.0.0 with automatic extraction
- Build deps: base, cabal, ghc
- Runtime deps: glibc
- Network access enabled for cabal dependency index updates
- Includes standalone version check test
…package)

Info-ZIP unzip 6.0 has been frozen since 2009 and carries unfixed
CVE-2014-8139/8140/8141 + CVE-2018-1000035 (4 HIGH) with no upstream to track —
it was both vuln-exposed AND update-dark (pkgmgr check: no-source). bsdunzip,
added to libarchive in 3.7.0, is its maintained successor.

- New `packages/libarchive` (3.8.7, GithubRepo libarchive/libarchive, BSD-2):
  builds bsdtar/bsdcpio/bsdcat/bsdunzip + libarchive.so against zlib/bzip2/lzma
  (heavy optional backends disabled to keep the dep set lean). Source staged to
  gs://minimal-staging-archives/.

- `packages/unzip` becomes a thin compat shim: a /usr/bin/unzip symlink to
  bsdunzip (libarchive runtime dep). Info-ZIP source + build dropped. bsdunzip
  is a drop-in for the flags our callers use — verified in bsdunzip.1 that
  -o/-q/-d/-p are all supported, so bun + chromium-bin +
  chromium-headless-shell-bin keep invoking `unzip` unchanged. Version-tracking
  now follows libarchive, so it's no longer update-dark.

Locally validated: both build.ncl parse + resolve; `pkgmgr check --package
unzip` now reports up_to_date (3.8.7) instead of a `no-source` skip.

DRAFT — needs the buildbot to verify: libarchive compiles with the chosen
configure flags, bsdunzip is produced, the symlink + OutputBin lint pass, the
roundtrip test extracts via bsdunzip, and the three consumers (bun, chromium-bin,
chromium-headless-shell-bin) still build against bsdunzip.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The sandbox rejected the /usr/bin/unzip -> bsdunzip symlink: bsdunzip lives in
the libarchive package's output, so the symlink 'points outside output
directory'. Replace it with a /bin/sh wrapper that execs /usr/bin/bsdunzip
(provided by the libarchive runtime dep) — a real file, no symlink escape;
callers keep invoking unzip unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…zip plan)

Reverses the bsdunzip migration: bun's build invokes `unzip -o -DD -d` and `-DD`
(don't-restore-timestamps) is an Info-ZIP-only flag bsdunzip lacks, so swapping
unzip→bsdunzip broke bun's build. Info-ZIP is the only impl with `-DD`.

Instead, do what every distro does — keep frozen Info-ZIP 6.0 and apply the
backported security patches. We were shipping the pristine `unzip_6.0.orig`
tarball with NO patches, which is exactly why it scanned 4 HIGH. Now stage +
apply Debian's full 6.0-29 series (31 patches): fixes CVE-2014-8139/8140/8141/
9636/9913, CVE-2015-7696/7697, CVE-2016-9844, CVE-2018-1000035, CVE-2019-13232,
CVE-2022-0529/0530 + build fixes. Patch 30 drops the K&R gmtime()/localtime()
declarations, replacing the manual sed that lived in build.sh.

Drops the new libarchive package (no remaining consumer). unzip stays
update-dark, which is correct: 6.0 is EOL and the patches are its maintenance.

Follow-up: VEX the patched CVE IDs so the version-based scanner (which can't see
the backported fixes) clears them.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… edits)

The previous commit's git-add aborted on the already-removed libarchive
pathspec, so the build.ncl patches Source + build.sh apply-loop never staged.
This adds them: the staged-tarball Source and the series-apply loop (and removes
the now-redundant gmtime sed, handled by patch 30).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
mkromfs/pack_ps read SOURCE_DATE_EPOCH but then do
`if (!buildtime) buildtime = time(NULL)`, treating the sandbox's
SOURCE_DATE_EPOCH=0 (epoch 0 is falsy) as unset and falling back to
wall-clock time. That stamped a non-deterministic gs_romfs_buildtime into
usr/bin/gs. Fall back to time() only when SOURCE_DATE_EPOCH is genuinely
unset (base/mkromfs.c:2614, base/pack_ps.c:344).

Verified on aarch64: two from-scratch builds are byte-identical
(repro-check diff, 196/196 files).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
After the existing fixrand.so shim (getrandom/urandom), the dumped .pdmp
still differed in 11 bytes — two wall-clock timestamps read via
clock_gettime(CLOCK_REALTIME), which the shim didn't cover: the *scratch*
buffer's buffer-display-time (Fcurrent_time in make_initial_frame) and
Vgc_elapsed GC timing (src/alloc.c). Extend the shim to return
SOURCE_DATE_EPOCH for CLOCK_REALTIME (other clocks pass through).

Verified on aarch64: two from-scratch builds are byte-identical
(repro-check diff, 4282/4282 files).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
mono's AOT output had three independent non-determinism sources:

1. build_date: bare `date` in mono/mini/Makefile.am.in ignores
   SOURCE_DATE_EPOCH -> wall-clock in mono-sgen + AOT version strings.
   Pin it from the epoch before autogen.sh.
2. AOT id: aot-compiler.c generate_aotid() emits 16 random bytes into
   each AOT image. The net_4_x build doesn't thread the 'deterministic'
   aot option, so zero the aotid at the source (same emitted result).
3. AOT temp name: g_file_open_tmp("mono_aot_XXXXXX") leaks a random
   suffix into each *.dll.so as a local STT_FILE symbol. Strip the
   runtime-unneeded locals from the AOT images post-install.

Verified on aarch64: two from-scratch builds are byte-identical
(repro-check diff, 3131/3131 files).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…hanges)

Adopts the hardening idea from the Edge Delta bot's #274 (cleanly — no
whole-file reindentation, executable bit preserved): verify the
'if (!buildtime)' pattern exists in both files before sed-ing, so a future
ghostscript that renames it fails the build instead of silently shipping a
non-reproducible binary.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
CPython's configure resolves MODULE__CTYPES_LDFLAGS via PKG_CHECK_MODULES,
which non-deterministically picks '-L/usr/lib/../lib64' vs '-L/usr/lib/../lib'
-> leaks into _sysconfigdata*.py/.json and config-*/Makefile (6 files flip
across builds). Pin LIBFFI_CFLAGS/LIBFFI_LIBS on the configure line so it
uses them verbatim and skips pkg-config; result is '-lffi -ldl' every build.

Verified: with this pin, the _sysconfigdata libffi flip is gone from a
build-twice diff. (Full byte-reproducibility of python additionally needs a
pinned toolchain — .comment records the binutils version — and is gated on
the --enable-optimizations/PGO perf decision; both are out of scope here.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
GHC's code output is already reproducible; the residual is metadata
ordering from hash-set iteration of package/UnitId collections:
1. link-arg/DT_NEEDED/.dynstr order — backport of upstream GHC #26838 /
   MR !15453 (sort preload1 in compiler/GHC/Unit/State.hs); Debian ships
   this exact patch for 9.10.3.
2. ghc-pkg package.cache — sort the .conf list before serialize in
   utils/ghc-pkg/Main.hs (no upstream fix; sort already imported).
Both guarded by grep so a future GHC source change fails the build loudly.
Fixing the compiler propagates to all downstream Haskell (stack, HLS).

DRAFT: Debian-proven + guarded, but not yet local build-twice-verified
(GHC is a multi-hour build_cost_multiple=6 build).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Per review on #277: patch (2) relies on 'sort' being in scope in
utils/ghc-pkg/Main.hs. 9.10.3 imports it (Main.hs:78), but add a grep
guard so a future GHC import reorg fails fast here rather than deep in
the multi-hour Hadrian build. Output-neutral; verified result unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Edge Delta AI Teammates seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

bryan-minimal added a commit that referenced this pull request Jun 20, 2026
Defensive NULL check before deref of real_clock_gettime: if
dlsym(RTLD_NEXT, "clock_gettime") ever returns NULL, fail with ENOSYS
instead of segfaulting. The CLOCK_REALTIME path already returns before
this point, so this only affects pass-through clocks (CLOCK_MONOTONIC,
etc.) — but it makes the shim robust regardless. Folds in the one valid
point from the Edge Delta bot's #278.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@bryan-minimal

Copy link
Copy Markdown
Member

Thanks — the NULL-guard point is valid (defends against dlsym(RTLD_NEXT, "clock_gettime") returning NULL before the deref). Folded it directly into #273 so the emacs reproducibility change stays self-contained, with errno = ENOSYS; return -1 as the failure mode. See e4ccc06. Closing this in favor of that commit.

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.

3 participants