Skip to content

Conversation

@AlexShalimov
Copy link
Contributor

@AlexShalimov AlexShalimov commented Aug 7, 2025

Fixes #615

When we load module (util_uri.c, line 174), we call pkcs11_CTX_load(). After module successfully loaded (p11_load.c, line 99), both method and handle members of cpriv structure are initialized. Then we call pkcs11_initialize() (p11_load.c, line 105). However, if C_Initialize() method returns error (in my case it was 0x80000384 — "General error from secure messaging system – probably caused by HSM failure or network failure"), we unload module (p11_load.c, lines 106-107). Notice only handle member is nulled; method is unchanged, though it pointers are no more valid. Then we return back to util_ctx_init_libp11(), and it tries to free module once again, calling UTIL_CTX_free_libp11() (util_uri.c, line 180). Ultimately we end up in pkcs11_CTX_unload() (p11_load.c, line 143). There we check if module if loaded by checking method member (p11_load.c, line 147), but it's not null (only handle is cleared). And so we crash when calling cpriv->method->C_Finalize(NULL) (p11_load.c, line 152).

@mtrojnar mtrojnar merged commit 932c086 into OpenSC:master Aug 7, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash on loading dll if it initializes with error

2 participants