Commit b1e34a2
tls_openssl: fix per-thread state double-free across fork()
Register a pthread_atfork prepare handler that calls OPENSSL_thread_stop()
before each fork(). CRYPTO_set_mem_functions() routes all OpenSSL allocations
to shared memory, but per-thread structures (ERR_STATE, DRBG) use thread-local
storage pointers inherited across fork(). Without cleanup, child processes
inherit a stale pointer to the parent per-thread state; if the parent frees or
re-creates that state, the child next OpenSSL call triggers a double-free
(detected by QM_MALLOC_DBG as SIGABRT).
After OPENSSL_thread_stop() the thread-local pointer is NULL. Both parent and
child lazily allocate fresh per-thread state on the next OpenSSL call.
This complements the existing on_exit(_exit) handler which covers the same
class of double-free at process exit time.
(cherry picked from commit c8d148c)
(cherry picked from commit 66cca03)1 parent 0b482b8 commit b1e34a2
1 file changed
Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
162 | 163 | | |
163 | 164 | | |
164 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
165 | 190 | | |
166 | 191 | | |
167 | 192 | | |
| |||
297 | 322 | | |
298 | 323 | | |
299 | 324 | | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
300 | 332 | | |
301 | 333 | | |
302 | 334 | | |
| |||
0 commit comments