Tarantool development patches archive
 help / color / mirror / Atom feed
From: Alexander Turenko <alexander.turenko@tarantool.org>
To: Ilya Markov <imarkov@tarantool.org>,
	Kirill Yukhin <kyukhin@tarantool.org>
Cc: Alexander Turenko <alexander.turenko@tarantool.org>,
	tarantool-patches@freelists.org
Subject: [tarantool-patches] [PATCH] Use automatic storage for digest.pbkdf2 results
Date: Mon, 14 May 2018 10:13:28 +0300	[thread overview]
Message-ID: <06ec3d50d0f58b15199a7230f82769ca3a702154.1526281547.git.alexander.turenko@tarantool.org> (raw)

It prevents rewriting result by an another thread after coio_call(), but
before lua_pushlstring(). Such case is possible because libeio uses
thread pool internally and static __thread storage can be reused before
lua_pushlstring() if many parallel digest.pbkdf2() calls are on the fly.

Fixes #3396.
---

branch: Totktonada/gh-3396-reentrant-digest-pbkdf2
travis-ci: https://travis-ci.org/tarantool/tarantool/builds/378586123
(broken on centos 7 due to https://bugs.centos.org/view.php?id=14769)

Don't sure my understanding of the problem is right, but the fix works
for the test case I have posted into the issue. I would be appreciated
for comments re source of the issue.

 src/lua/digest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/lua/digest.c b/src/lua/digest.c
index bf738b3f5..b0572baf7 100644
--- a/src/lua/digest.c
+++ b/src/lua/digest.c
@@ -79,7 +79,7 @@ lua_pbkdf2(lua_State *L)
 	const char *salt = lua_tostring(L, 2);
 	int num_iterations = lua_tointeger(L, 3);
 	int digest_len = lua_tointeger(L, 4);
-	static __thread unsigned char digest[PBKDF2_MAX_DIGEST_SIZE];
+	unsigned char digest[PBKDF2_MAX_DIGEST_SIZE];
 
 	if (coio_call(digest_pbkdf2_f, password, strlen(password), salt,
 				  strlen(salt), digest, num_iterations, digest_len) < 0) {
@@ -99,4 +99,4 @@ tarantool_lua_digest_init(struct lua_State *L)
 	};
 	luaL_register_module(L, "digest", lua_digest_methods);
 	lua_pop(L, 1);
-};
\ No newline at end of file
+};
-- 
2.15.1

                 reply	other threads:[~2018-05-14  7:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=06ec3d50d0f58b15199a7230f82769ca3a702154.1526281547.git.alexander.turenko@tarantool.org \
    --to=alexander.turenko@tarantool.org \
    --cc=imarkov@tarantool.org \
    --cc=kyukhin@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH] Use automatic storage for digest.pbkdf2 results' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox