Skip to content

Commit

Permalink
Merge pull request #21085 from mpirvu/jitserver_ssl_fix
Browse files Browse the repository at this point in the history
Explicitly load libcrypto for JITServer
  • Loading branch information
dsouzai authored Feb 10, 2025
2 parents f3e9891 + c58d7df commit cc83b6a
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions runtime/compiler/net/LoadSSLLibs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,37 @@ namespace JITServer
{
void *loadLibssl()
{
void *result = NULL;
// We want to load libssl.so and get access to the functions inside.
// When libssl3 (or higher) is bundled with the JDK, we want to load that version
// in preference over the one present on the system. `dlopen` will do that because
// the RUNPATH for the JIT dll (from which `dlopen` is invoked) includes the
// "JDK/lib" path where libssl is bundled. However, as part of loading libssl3,
// `dlopen` will also attempt to load libcrypto3 (because it is a dependency).
// This is searched in the RPATH of the jitserver executable for a server,
// or in the RPATH of the java executable for a client. Currently, the jitserver
// executable does not include an RPATH, so libcrypto3 is searched on the system
// and this may fail on systems that do not have version 3 installed. This problem
// can be circumvented by performing an explicit `dlopen` for the crypto library,
// in which case the RUNPATH for the JIT is going to be used as search path.

// Library names for CryptoSSL 3, 1.1.1, 1.1.0, 1.0.2 and symbolic links
static const char * const cryptoLibNames[] =
{
"libcrypto.so.3", // 3.x library name
"libcrypto.so.1.1", // 1.1.x library name
"libcrypto.so.1.0.0", // 1.0.x library name
"libcrypto.so.10", // 1.0.x library name on RHEL
"libcrypto.so" // general symlink library name
};

int numOfLibraries = sizeof(cryptoLibNames) / sizeof(cryptoLibNames[0]);

for (int i = 0; i < numOfLibraries; ++i)
{
if (dlopen(cryptoLibNames[i], RTLD_NOW))
break; // Break out of the loop as soon as the library is loaded
}


// Library names for OpenSSL 3, 1.1.1, 1.1.0, 1.0.2 and symbolic links
static const char * const libNames[] =
Expand All @@ -246,16 +276,13 @@ void *loadLibssl()
"libssl.so" // general symlink library name
};

int numOfLibraries = sizeof(libNames) / sizeof(libNames[0]);

numOfLibraries = sizeof(libNames) / sizeof(libNames[0]);
void *result = NULL;
for (int i = 0; i < numOfLibraries; ++i)
{
result = dlopen(libNames[i], RTLD_NOW);

if (result)
{
return result;
}
break;
}
return result;
}
Expand Down

0 comments on commit cc83b6a

Please sign in to comment.