<p></p>
<h3>Description</h3>
<p>When using HSM keys (via OpenSSL engine) the engine and private keys are loaded in the child processes since PKCS#11 modules rarely survive <code>fork()</code>.</p>
<p>With OpenSSL 1.1.1 and the call to <code>OPENSSL_init_ssl()</code> in <code>tls_init.c</code> the engine linked-list is now initialized in the master process. Subsequently the technique used in <code>tls_init.c:660 CONF_modules_load_file()</code> will fail as each child process manipulates the linked-list. Even if the engine linked-list manipulation itself is protected by global locks; traversing the linked-list will encounter invalid memory locations as the nodes are insert by other child processes.</p>
<p>This issue is filed as a marker; I will be providing patches to change the way HSM private keys are loaded in the child process to avoid linked-list corruption.</p>
<h3>Troubleshooting</h3>
<ul>
<li>use soft (PEM) keys — no issue as OpenSSL engine is not relevant in this context</li>
</ul>
<h4>Reproduction</h4>
<ul>
<li>configure TLS with OpenSSL engine key(e.g pkcs11 engine with SoftHSM keys)</li>
</ul>
<h3>Additional Information</h3>
<p>Root cause: the function <code>CONF_modules_load_file()</code> will configure OpenSSL engines from a OpenSSL configuration file but it also adds each engine to the  global linked list. Unfortunately there is no OpenSSL function to reset the linked-list in the child process. It seems to be initialized once at start-up: the linked-list head/tail pointers are static variables and their initialization is protected by OpenSSL's <code>RUN_ONCE</code> mechanism, so it doesn't seem it supported mechanism to have them reinitialized after <code>fork()</code>.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/2839">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZOLBPG2XICVNMHKCGDT7VIDXANCNFSM5DFCZ4FA">unsubscribe</a>.<br />Triage notifications on the go with GitHub Mobile for <a href="https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675">iOS</a> or <a href="https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub">Android</a>.
<img src="https://github.com/notifications/beacon/ABO7UZPDSDSROM33OLYEWVLT7VIDXA5CNFSM5DFCZ4FKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4OVML7DQ.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/2839",
"url": "https://github.com/kamailio/kamailio/issues/2839",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>