swipl-devel
swipl-devel copied to clipboard
segfault in crypto library on debian unstable
It looks like v8.5.11 introduced a bug in the crypto library, causing a crash in hashing:
$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.5.11)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
?- crypto_data_hash('asdf', Hash, [algorithm(sha256)]).
SWI-Prolog [thread 1 (main) at Thu Jul 21 10:04:38 2022]: received fatal signal 11 (segv)
C-stack trace labeled "crash":
[0] save_backtrace() at :? [0x7fe007e0334e]
[1] print_c_backtrace() at :? [0x7fe007e034dc]
[2] sigCrashHandler() at :? [0x7fe007e03607]
[3] __restore_rt() at sigaction.c:? [0x7fe007b02940]
[4] EVP_MAC_up_ref() at ??:? [0x7fe006614b00]
[5] pl_crypto_hash_context_copy() at crypto4pl.c:? [0x7fe00780ecad]
[6] PL_next_solution___LD() at :? [0x7fe007d0c122]
[7] query_loop() at :? [0x7fe007d56bf9]
[8] prologToplevel() at :? [0x7fe007d5743d]
[9] PL_toplevel() at ??:? [0x7fe007dd8f4e]
[10] swipl(+0x10b5) [0x55a44e8ee0b5]
[11] __libc_start_main() at ./csu/../csu/libc-start.c:332 [0x7fe007aed81d]
[12] swipl(+0x10fa) [0x55a44e8ee0fa]
Prolog stack:
[12] crypto:_crypto_hash_context_copy/2 [PC=1 in supervisor]
[11] crypto:crypto_data_context/3 [PC=5 in clause 1]
[10] crypto:crypto_data_hash/3 [PC=13 in clause 1]
[9] $toplevel:toplevel_call/1 [PC=3 in clause 1]
[8] $toplevel:stop_backtrace/2 [PC=4 in clause 1]
[7] $tabling:$wfs_call/2 [PC=17 in clause 1]
[6] $toplevel:residue_vars/4 [PC=13 in clause 2]
[5] $toplevel:$execute_goal2/3 [PC=31 in clause 1]
[3] $toplevel:$query_loop/0 [PC=39 in clause 2]
[2] $toplevel:$runtoplevel/0 [PC=19 in clause 1]
[1] $toplevel:$toplevel/0 [PC=3 in clause 1]
[0] system:$c_call_prolog/0 [PC=0 in top query clause]
Running on_halt hooks with status 139
Killing 86853 with default signal handlers
Segmentation fault
v8.5.10 didn't yet have this behavior:
$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.5.10)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
?- crypto_data_hash('asdf', Hash, [algorithm(sha256)]).
Hash = f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b.
This bug still exists on the latest version of v8.5 (v8.5.14), and unfortunately it also got backported in the latest v8.4 (v8.4.3).
Works for me on Ubuntu with 8.5.14
$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.5.14)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
1 ?- crypto_data_hash('asdf', Hash, [algorithm(sha256)]).
Hash = f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b.
Interesting. Which version of Ubuntu are you running?
I'm running Debian unstable. I will try a few other distros to see if it makes a difference. Nevertheless, there must be some change, as older versions of swipl work and newer versions do not, which cannot be explained by a regression in debian.
Probably also important to mention that I've installed all my swipl versions using swivm.
Ok, I figured it out. Somewhat. There is no regression in swipl. The regression is on the side of debian. The reason why v8.4.2 and v8.5.10 worked for me was that these were built some time ago, whereas every other version I tested was built today, using swivm. Having created a brand new debian unstable container, and installing v8.4.2 or v8.5.10 there triggers the exact same bug. On a brand new debian stable container, all versions work just fine.
Conclusion, something changed about debian's build environment in unstable. Probably nothing has to happen in swipl to remedy this. I'll leave this open for a bit though while I figure it out.
These are the systems that I tried it on (Debian is a ChromeBook where I build swipl; Ubuntu is a desktop where I use the dev-PPA version - and where I need to reboot to install the latest system updates):
$ uname -a
Linux 5.10.114-16024-gbdf1547bd4f4 #1 SMP PREEMPT Thu Jun 30 18:19:44 PDT 2022 x86_64 GNU/Linux
[peter@penguin pcre (master=)]$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
Linux 5.13.0-48-generic #54~20.04.1-Ubuntu SMP Thu Jun 2 23:37:17 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
[$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.4 LTS
Release: 20.04
Codename: focal
The OpenSSL libs are not very easy to use :cry: This could be a regressing in OpenSSL, but it could also be an issue in our code, making an invalid call. Possibly running under GDB, especially with the debug symbols for Prolog and OpenSSL installed may give a clue.
This bug appears to be fixed on HEAD (but not in v8.5.15). Did you find a cause or did it somehow fix itself?
Apologies, false alarm. Definitely still broken. I'll look into it with gdb.
I managed to fix the bug. It was a case of using a non-initialized variable, which caused a function to be called that shouldn't have been.
Fixed in the ssl package here: https://github.com/SWI-Prolog/packages-ssl/pull/166
@JanWielemaker - if you merge this, would you consider also pulling it back into stable on the next update to stable?
@JanWielemaker - if you merge this, would you consider also pulling it back into stable on the next update to stable?
Sure. I don't have a timeline though. I'm also unsure whether the next stable should be 8.4.4 or 8.6.0, i.e., based on 8.5.
Closing this. The issue is fixed by SWI-Prolog/packages-ssl@7af9855aa7bbdce6f8ef509d1f181b5d5b0304c5