-
Notifications
You must be signed in to change notification settings - Fork 708
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
SIGSEV when re-loading opensc-pkcs11.so #192
Comments
What are your patches to OpenSSL? Turning off GOST in OpenSC does not sound like the solution. On 10/16/2013 5:38 PM, commonism wrote:
Douglas E. Engert DEEngert@anl.gov |
I'll fork OpenSSL on github and branch my patches. |
openssl/openssl#25 A workaround in applications suffering from this should be loading gost via dynamic engine and using LIST_ADD ENGINE *ENGINE_gost(void)
{
struct command
{
char *cmd;
char *arg;
} commands[] =
{
{"SO_PATH", "/usr/lib/x86_64-linux-gnu/openssl-1.0.0/engines/libgost.so"},
{"LIST_ADD","1"},
{"LOAD", NULL},
};
ENGINE_load_dynamic();
ENGINE *e = ENGINE_by_id("dynamic");
if( e == NULL )
{
perror("ENGINE_by_id");
ERR_print_errors_fp(stderr);
exit(1);
}
for (int i = 0; i < sizeof(commands) / sizeof(commands[0]); i++)
{
struct command *cmd = &commands[i];
if( ENGINE_ctrl_cmd_string(e, cmd->cmd, cmd->arg, 0) != 1 )
{
printf("ENGINE_ctrl_cmd_string %s %s \n", cmd->cmd, cmd->arg);
ERR_print_errors_fp(stderr);
exit(1);
}
}
return e;
} This way, gost won't be destroyed by openssl, as it always has a reference in the list. |
I took your code as is and ran it with the most recent version of OpenSC and OpenSSL 1.0.2. There was no error. The output was as follows (identical for crash_now 1 and 0)
please re-open if the problem still applies |
I forgot to mention that I ran the program in valgrind and gdb. |
The following code can be used to reproduce
Set your keyid and pin, compile with
run and it'll crash, maybe not directly but you can see the memory corruption with valgrind
If CRASH_NOW is set, valgrind will provide a trace similar to
in case it is not set, it will fault in ENGINE_cleanup() similar to
The problem is in OpenSSL here.
crashes the same way without using OpenSC at all.
The actual problem is in the gost engine.
The gost engine uses global statics,which do not get unregistered when unloading the engine.
Loading/ENGINE_set_default gost the first time, things get initialized and registered within OpenSSL, doing it the second time, gost gets finished without unregistering the registered 'things', but they get free'd.
This way, loading gost twice destroys OpenSSL internally.
To OpenSC this is a real problem.
ENGINE_init for a engine_pkcs11 will load opensc-pkcs11.so.
Loading opensc-pkcs11.so loads gost in sc_pkcs11_register_openssl_mechanisms().
ENGINE_finish() for will call the engine_pkcs11 pkcs11_finish, which will unmapp the pkcs11 library opensc-pkcs11.so.
Second time ENGINE_init is called, gost is loaded and set default the second time, things break.
This can be fixed in OpenSSL, it should be fixed in OpenSSL.
I provided different patches patching it in multiple ways in OpenSSL, no patch was accepted by OpenSSL.
Therefore I propose to remove gost from OpenSC, using it breaks everything else.
Just do not load it, it'll be broken, but does not work reliable anyway and OpenSC is the wrong scope for repair.
The text was updated successfully, but these errors were encountered: