|
|
d560a5 |
From cfa4385e728116989ad88b4be7c23b4868422778 Mon Sep 17 00:00:00 2001
|
|
|
d560a5 |
From: Milan Broz <gmazyland@gmail.com>
|
|
|
d560a5 |
Date: Mon, 11 Mar 2019 21:21:57 +0100
|
|
|
d560a5 |
Subject: [PATCH] Wait for already running threads if a thread creation
|
|
|
d560a5 |
failed.
|
|
|
d560a5 |
|
|
|
d560a5 |
On memory-constrained systems (like cgroups limited processes)
|
|
|
d560a5 |
thread creation often fails.
|
|
|
d560a5 |
|
|
|
d560a5 |
The code needs to wait for already running threads on error path;
|
|
|
d560a5 |
otherwise these threads can access deallocated memory
|
|
|
d560a5 |
(and cause a segfault or another crash).
|
|
|
d560a5 |
---
|
|
|
d560a5 |
src/core.c | 5 ++++-
|
|
|
d560a5 |
1 file changed, 4 insertions(+), 1 deletion(-)
|
|
|
d560a5 |
|
|
|
d560a5 |
diff --git a/src/core.c b/src/core.c
|
|
|
d560a5 |
index 8361175..65f0537 100644
|
|
|
d560a5 |
--- a/src/core.c
|
|
|
d560a5 |
+++ b/src/core.c
|
|
|
d560a5 |
@@ -310,7 +310,7 @@ static int fill_memory_blocks_mt(argon2_instance_t *instance) {
|
|
|
d560a5 |
|
|
|
d560a5 |
for (r = 0; r < instance->passes; ++r) {
|
|
|
d560a5 |
for (s = 0; s < ARGON2_SYNC_POINTS; ++s) {
|
|
|
d560a5 |
- uint32_t l;
|
|
|
d560a5 |
+ uint32_t l, ll;
|
|
|
d560a5 |
|
|
|
d560a5 |
/* 2. Calling threads */
|
|
|
d560a5 |
for (l = 0; l < instance->lanes; ++l) {
|
|
|
d560a5 |
@@ -335,6 +335,9 @@ static int fill_memory_blocks_mt(argon2_instance_t *instance) {
|
|
|
d560a5 |
sizeof(argon2_position_t));
|
|
|
d560a5 |
if (argon2_thread_create(&thread[l], &fill_segment_thr,
|
|
|
d560a5 |
(void *)&thr_data[l])) {
|
|
|
d560a5 |
+ /* Wait for already running threads */
|
|
|
d560a5 |
+ for (ll = 0; ll < l; ++ll)
|
|
|
d560a5 |
+ argon2_thread_join(thread[ll]);
|
|
|
d560a5 |
rc = ARGON2_THREAD_FAIL;
|
|
|
d560a5 |
goto fail;
|
|
|
d560a5 |
}
|
|
|
d560a5 |
--
|
|
|
d560a5 |
2.20.1
|
|
|
d560a5 |
|