We have a php binary that statically links in openssl and openssl extension, to make it portable across all linux distros. This php binary can connect just fine with ssl to pgsql, mariadb, mysql and sqlite. However, when loading trying to connect to a mssql server using the sqlsrv extension, the mssql driver loads libssl.so and libcrypto.so in the version that is installed on the operating system, instead of using the ssl symbols already present in the binary. This seems to create a conflict of some kind and the program deadlocks.
<?php
<?php
$serverName = "sqlserver,1433";
$connectionOptions = [
"Database" => "master",
"Uid" => "sa",
"PWD" => "YourStrong!Pass123",
"TrustServerCertificate" => true
];
$conn = sqlsrv_connect($serverName, $connectionOptions);
if ($conn === false) {
echo "Connection failed for " . phpversion() . ":\n";
die(print_r(sqlsrv_errors(), true));
}
echo "Connection Successful using PHP " . phpversion() . "!\n";
sqlsrv_close($conn);
?>
sendto(5, "\22\1\0X\0\0\1\0\0\0\37\0\6\1\0%\0\1\2\0&\0\1\3\0'\0\4\4\0+\0"..., 88, MSG_NOSIGNAL, NULL, 0) = 88
poll([{fd=5, events=POLLIN}], 1, 14993) = 1 ([{fd=5, revents=POLLIN}])
recvfrom(5, "\4\1\0000\0\0\1\0\0\0\37\0\6\1\0%\0\1\2\0&\0\1\3\0'\0\0\4\0'\0"..., 4096, 0, NULL, NULL) = 48
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 6
newfstatat(6, "", {st_mode=S_IFREG|0644, st_size=18447, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 18447, PROT_READ, MAP_PRIVATE, 6, 0) = 0x7ffb23734000
close(6) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libssl.so.3", O_RDONLY|O_CLOEXEC) = 6
read(6, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832
newfstatat(6, "", {st_mode=S_IFREG|0644, st_size=688160, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 690288, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 6, 0) = 0x7ffb2258d000
mmap(0x7ffb225ac000, 380928, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 6, 0x1f000) = 0x7ffb225ac000
mmap(0x7ffb22609000, 126976, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 6, 0x7c000) = 0x7ffb22609000
mmap(0x7ffb22628000, 57344, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 6, 0x9a000) = 0x7ffb22628000
close(6) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libcrypto.so.3", O_RDONLY|O_CLOEXEC) = 6
read(6, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832
newfstatat(6, "", {st_mode=S_IFREG|0644, st_size=4734232, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 4748720, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 6, 0) = 0x7ffb22105000
mmap(0x7ffb221ca000, 2609152, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 6, 0xc5000) = 0x7ffb221ca000
mmap(0x7ffb22447000, 909312, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 6, 0x342000) = 0x7ffb22447000
mmap(0x7ffb22525000, 413696, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 6, 0x41f000) = 0x7ffb22525000
mmap(0x7ffb2258a000, 9648, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7ffb2258a000
close(6) = 0
mprotect(0x7ffb22525000, 401408, PROT_READ) = 0
mprotect(0x7ffb22628000, 40960, PROT_READ) = 0
munmap(0x7ffb23734000, 18447) = 0
futex(0x5650e7242560, FUTEX_WAKE_PRIVATE, 2147483647) = 0
futex(0x7ffb22635864, FUTEX_WAKE_PRIVATE, 2147483647) = 0
futex(0x7ffb22635858, FUTEX_WAKE_PRIVATE, 2147483647) = 0
futex(0x7ffb22635838, FUTEX_WAKE_PRIVATE, 2147483647) = 0
futex(0x7ffb225898e8, FUTEX_WAKE_PRIVATE, 2147483647) = 0
futex(0x5650e7241dc8, FUTEX_WAKE_PRIVATE, 2147483647) = 0
brk(0x56512523e000) = 0x56512523e000
futex(0x5650e72426e0, FUTEX_WAKE_PRIVATE, 2147483647) = 0
futex(0x7ffb22589824, FUTEX_WAKE_PRIVATE, 2147483647) = 0
PHP version
8.X
PHP SQLSRV or PDO_SQLSRV version
ExtensionVer => 5.12.0
Microsoft ODBC Driver version
libmsodbcsql-18.6.so.1.1
SQL Server version
2022
Client operating system
Debian/Almalinux
Problem description
We have a php binary that statically links in openssl and openssl extension, to make it portable across all linux distros. This php binary can connect just fine with ssl to pgsql, mariadb, mysql and sqlite. However, when loading trying to connect to a mssql server using the
sqlsrvextension, the mssql driver loads libssl.so and libcrypto.so in the version that is installed on the operating system, instead of using the ssl symbols already present in the binary. This seems to create a conflict of some kind and the program deadlocks.Expected behavior and actual behavior
Expected:
Connection Successful using PHP 8.4.18!Actual:
deadlockRepro code or steps to reproduce
Install openssl-dev
link php with openssl and sqlsrv extension against libssl.a and libcrypto.a
run test connection script -> deadlock
link php with openssl and sqlsrv extension against libssl.so and libcrypto.so
run test connection script -> success