@@ -22,25 +22,28 @@ patched = [">= 0.1.6"]
22
22
23
23
# ` openssl-probe ` may cause memory corruption in multi-threaded processes
24
24
25
- ` openssl-probe ` offers non-` unsafe ` methods that call environment setters , which may be called
25
+ ` openssl-probe ` offers non-` unsafe ` methods that call ` std::env::set_var ` , which may be called
26
26
in a multithreaded environment, and potentially clash with environment access on other threads.
27
27
28
28
When these methods are called while other threads are active and accessing the environment, it
29
- may cause the other threads to access dangling pointer values in the cases where the underlying
29
+ may cause other threads to access dangling environment pointers in the cases where the underlying
30
30
environment data is moved or resized in response to an additional environment variable being
31
31
added, or a variable's contents being enlarged.
32
32
33
33
This is shown to occur on Linux, but it will also likely occur on any other platform where ` getenv `
34
34
and ` setenv ` are not thread-safe, though trigger conditions may vary widely.
35
35
36
+ Note that these function calls are completely safe and sound in purely single-threaded environments,
37
+ or multi-threaded environments where it can be proven that no simultaneous read and writes to the
38
+ environment occur.
39
+
36
40
## Rust's ` set_env `
37
41
38
- This crate, and all callers of the Rust ` set_env ` function (< https://doc.rust-lang.org/std/env/fn.set_var.html > )
39
- are unsound due to some early decisions in the Rust ecosystem that provided these functions without
40
- an ` unsafe ` marker. The real problem, however, lies in the POSIX standard which defines this method
42
+ This crate, and all other callers of the Rust ` set_env ` function (< https://doc.rust-lang.org/std/env/fn.set_var.html > )
43
+ are unsound due to the unfortunate reality of the POSIX standard which defines these enviornment access methods
41
44
without making any sort of thread-safety guarantees.
42
45
43
- In Rust's 2024 edition these environment setters are made ` unsafe ` and the documentation was updated to note
46
+ In Rust's 2024 edition ` std::env::set_var ` is marked as ` unsafe ` and the documentation was updated to note
44
47
that the only safe way to use these functions is in a single-threaded context.
45
48
46
49
## Affected Code
@@ -52,11 +55,11 @@ any other library's function which may call this function directly or indirectly
52
55
do so in certain configurations < https://github.com/sfackler/rust-native-tls/blob/2424bc5efd1b8b4bcf60dbda93259a3f29db7f06/Cargo.toml > .
53
56
54
57
The crate's author released a fix in versions ` >=0.1.6 ` which marks these functions as ` #[deprecated] ` and adds
55
- new ` unsafe ` equivalents < https://github.com/alexcrichton/openssl-probe/commit/3ea7c1af24d7f03c5786872f06ff066e03b75138 > .
58
+ new ` unsafe ` equivalents with safety guidance < https://github.com/alexcrichton/openssl-probe/commit/3ea7c1af24d7f03c5786872f06ff066e03b75138 > .
56
59
57
60
## Alternative Mitigations
58
61
59
- In the case of glibc users, some thread-safety improvements may protect you from ` setenv ` /` getenv ` clashes
62
+ In the case of glibc users, some future thread-safety improvements may protect you from ` setenv ` /` getenv ` clashes
60
63
which were introduced in < https://github.com/bminor/glibc/commit/7a61e7f557a97ab597d6fca5e2d1f13f65685c61 > ,
61
64
however direct ` environ ` access in multithreaded programs will still risk dangling pointer access.
62
65
0 commit comments