Std.Async.System: concurrent getEnvVar and setEnvVar calls can segfault
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 55/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- backend
Direzione di ricerca
Read src/Std/Async/System.lean around getEnvVar and setEnvVar, then inspect their native implementations in src/runtime/uv/system.cpp and the locking pattern in src/runtime/uv/event_loop.h. Reproduce the race with the supplied Lean program on Linux and check how environment access can be synchronized safely. Done means both tasks complete without a segmentation fault and lookups return none.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
Concurrent calls to Std.Async.System.getEnvVar and Std.Async.System.setEnvVar can reproducibly terminate Lean with SIGSEGV on Linux. These public APIs call uv_os_getenv and uv_os_setenv without synchronization, despite both libuv operations being documented as not thread-safe (eg uv_os_getenv). Repeatedly adding variables can reallocate the process-global environment array while another thread traverses it, leaving the reader accessing stale storage.
Context
This arose while checking concurrency behavior in the new Std.Async.System.getEnvVar and setEnvVar APIs (https://github.com/leanprover/lean4/blob/2d347a21fd2b6a90f0bc6448b8459d0219a2731a/src/Std/Async/System.lean#L245-L273) on Linux. Their native implementations (https://github.com/leanprover/lean4/blob/2d347a21fd2b6a90f0bc6448b8459d0219a2731a/src/runtime/uv/system.cpp#L250-L306) call libuv directly without acquiring a lock. This differs from event-loop operations, which are coordinated through event_loop_guard (https://github.com/leanprover/lean4/blob/2d347a21fd2b6a90f0bc6448b8459d0219a2731a/src/runtime/uv/event_loop.h#L23-L72).
Steps to Reproduce
- Save the following as EnvRace.lean:
module
import Std.Async.System
/-! Reproduces concurrent environment access. -/
public def main : IO Unit := do
let start ← IO.Promise.new
let writer ← IO.asTask (prio := .dedicated) do
discard <| IO.wait start.result?
for i in [0:8000] do
Std.Async.System.setEnvVar s!"LEAN_ENV_RACE_{i}" "x"
let reader ← IO.asTask (prio := .dedicated) do
discard <| IO.wait start.result?
for _ in [0:100000] do
discard <| Std.Async.System.getEnvVar "LEAN_ENV_RACE_MISSING"
start.resolve ()
IO.ofExcept (← IO.wait writer)
IO.ofExcept (← IO.wait reader)
elan run leanprover/lean4:nightly-2026-10-27 lean --run EnvRace.lean- Observe the segmentation fault
Expected behavior: Both tasks complete successfully; each lookup returns none and the process exits with status 0.
Actual behavior: Lean terminates with SIGSEGV inside libc getenv, reached through uv_os_getenv, and the command exits with status 139.
Versions
Lean (version 4.37.0-nightly-2026-10-27, x86_64-unknown-linux-gnu, commit 67bc4fe8130f9b5e1a073c73ed5cda09de6c63fe, Release)
Ubuntu 24.04.5 LTS, Linux 6.8.0-142-generic x86_64
Additional Information
Originally reported by @clairew from Trail of Bits during the Patch the Planet drive.
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
- Lingua principale
- Lean
- Stelle
- 10.3k
- Fork
- 1.1k
- Merge medio
- 19h 8m
- PR unite (30g)
- 421
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di leanprover/lean4
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
leanprover/lean4#16681 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
leanprover/lean4#16305 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
leanprover/lean4#16299 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
leanprover/lean4#16257 ·
I maintainer di solito rispondono entro 1 giorno
-
`IO.FS.realPath` reports every failure as `noFileOrDirectory` instead of classifying by `errno`Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
leanprover/lean4#15683 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di leanprover/lean4
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
-
Upgrade Django to 5.2.18Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
blacklanternsecurity/bbot#3678 ·
I maintainer di solito rispondono entro 2 giorni
-
A failed hydrate call can be dropped when the row's wait is ready tooForse già presa @turbot-agent-fleet l’ha presa oggi. Apertaagent:ready
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
turbot/steampipe-plugin-sdk#1018 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
router-for-me/CLIProxyAPI#7976 ·
I maintainer di solito rispondono entro 1 giorno