Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent crash by not loading engine if there is multiple libcrypto.so #363

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions gost_eng.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
* This file is distributed under the same license as OpenSSL *
* *
**********************************************************************/
#ifdef __linux__
# define _GNU_SOURCE
# include <link.h>
#endif
#include <string.h>
#include <openssl/crypto.h>
#include <openssl/err.h>
Expand Down Expand Up @@ -424,8 +428,29 @@ static int bind_gost_engine(ENGINE* e) {
return ret;
}

#ifdef __linux__
static int libcrypto_so_count = 0;

static int gost_dl_callback(struct dl_phdr_info *info, size_t size, void *data)
{
if (strstr(info->dlpi_name, "libcrypto.so"))
libcrypto_so_count++;

return 0;
}
#endif

static int check_gost_engine(ENGINE* e, const char* id)
{
#ifdef __linux__
/* Sanity check to prevent crash of gost.so loading by wrong libcrypto.so. */
dl_iterate_phdr(gost_dl_callback, NULL);
if (libcrypto_so_count > 1) {
fprintf(stderr, "error:%s:%d: Multiple instances of libcrypto.so, %s engine wont load to prevent crashes.\n",
__FILE__, __LINE__, id);
return 0;
}
#endif
if (id != NULL && strcmp(id, engine_gost_id) != 0)
return 0;
if (ameth_GostR3410_2001) {
Expand Down