summaryrefslogtreecommitdiffstats
path: root/argon2-Wait-for-already-running-threads-if-a-thread-creatio.patch
diff options
context:
space:
mode:
authorRemi Collet <remi@remirepo.net>2019-04-03 15:32:38 +0200
committerRemi Collet <remi@remirepo.net>2019-04-03 15:32:38 +0200
commita5f8f84fdca700b32402e2a7b0f3a1ae72a64efd (patch)
treef30e50b06bbae748a03a6890815c826a8906d679 /argon2-Wait-for-already-running-threads-if-a-thread-creatio.patch
parent197ce4ceb7ed86114d198340b4da9f6da5c3eeca (diff)
Fix a crash if running under memory pressure (rh #1688752). From Fedora
Diffstat (limited to 'argon2-Wait-for-already-running-threads-if-a-thread-creatio.patch')
-rw-r--r--argon2-Wait-for-already-running-threads-if-a-thread-creatio.patch42
1 files changed, 42 insertions, 0 deletions
diff --git a/argon2-Wait-for-already-running-threads-if-a-thread-creatio.patch b/argon2-Wait-for-already-running-threads-if-a-thread-creatio.patch
new file mode 100644
index 0000000..b872e92
--- /dev/null
+++ b/argon2-Wait-for-already-running-threads-if-a-thread-creatio.patch
@@ -0,0 +1,42 @@
+From cfa4385e728116989ad88b4be7c23b4868422778 Mon Sep 17 00:00:00 2001
+From: Milan Broz <gmazyland@gmail.com>
+Date: Mon, 11 Mar 2019 21:21:57 +0100
+Subject: [PATCH] Wait for already running threads if a thread creation
+ failed.
+
+On memory-constrained systems (like cgroups limited processes)
+thread creation often fails.
+
+The code needs to wait for already running threads on error path;
+otherwise these threads can access deallocated memory
+(and cause a segfault or another crash).
+---
+ src/core.c | 5 ++++-
+ 1 file changed, 4 insertions(+), 1 deletion(-)
+
+diff --git a/src/core.c b/src/core.c
+index 8361175..65f0537 100644
+--- a/src/core.c
++++ b/src/core.c
+@@ -284,7 +284,7 @@ int fill_memory_blocks(argon2_instance_t
+
+ for (r = 0; r < instance->passes; ++r) {
+ for (s = 0; s < ARGON2_SYNC_POINTS; ++s) {
+- uint32_t l;
++ uint32_t l, ll;
+
+ /* 2. Calling threads */
+ for (l = 0; l < instance->lanes; ++l) {
+@@ -309,6 +309,9 @@ int fill_memory_blocks(argon2_instance_t
+ sizeof(argon2_position_t));
+ if (argon2_thread_create(&thread[l], &fill_segment_thr,
+ (void *)&thr_data[l])) {
++ /* Wait for already running threads */
++ for (ll = 0; ll < l; ++ll)
++ argon2_thread_join(thread[ll]);
+ rc = ARGON2_THREAD_FAIL;
+ goto fail;
+ }
+--
+2.20.1
+