mirleft / ocaml-nocrypto

OCaml cryptographic library
ISC License
111 stars 53 forks source link

nocrypto generated a SIGILL #72

Closed vbmithr closed 9 years ago

vbmithr commented 9 years ago
Core was generated by `./wscat.native wss://www.bitmex.com/realtime'.
Program terminated with signal SIGILL, Illegal instruction.
#0  _mm_aeskeygenassist_si128 (__C=<optimized out>, __X=...)
    at /usr/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/include/wmmintrin.h:89
89        return (__m128i) __builtin_ia32_aeskeygenassist128 ((__v2di)__X, __C);
(gdb) bt
#0  _mm_aeskeygenassist_si128 (__C=<optimized out>, __X=...)
    at /usr/lib/gcc/x86_64-unknown-linux-gnu/5.1.0/include/wmmintrin.h:89
#1  _nc_aesni_derive_e_key (rounds=<optimized out>, rk0=<optimized out>, key=0x11b48b0 "")
    at src/native/aes/aesni.c:106
#2  caml_nc_aes_derive_e_key (key=140480948517120, off1=<optimized out>, rk=140480948517064, 
    rounds=<optimized out>) at src/native/aes/aesni.c:331
#3  0x000000000041b415 in camlNocrypto__Cipher_block__fun_2213 () at src/cipher_block.ml:371
#4  0x000000000041b391 in camlNocrypto__Cipher_block__of_secret_with_1584 () at src/cipher_block.ml:368
#5  0x000000000041c002 in camlNocrypto__Fortuna__create_1298 () at src/fortuna.ml:22
#6  0x000000000041d41c in camlNocrypto__Rng__create_1190 () at src/uncommon.ml:38
#7  0x000000000041daca in camlNocrypto__Rng__entry () at src/rng.ml:49
#8  0x0000000000407bc9 in caml_program ()
#9  0x000000000056720e in caml_start_program ()
#10 0x0000000000000000 in ?? ()
avsm commented 9 years ago

what's your /proc/cpuinfo ?

vbmithr commented 9 years ago
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 42
model name      : Intel(R) Core(TM) i3-2130 CPU @ 3.40GHz
stepping        : 7
microcode       : 0x29
cpu MHz         : 1599.992
cache size      : 3072 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 2
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmper
f eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 popcnt tsc_deadline_timer xsave avx lahf_lm arat epb pln pts dtherm tpr_shadow vnmi flexpriority ept vpid xsaveopt
bugs            :
bogomips        : 6787.30
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:

My other computer is fine, almost same CPU!

vbmithr commented 9 years ago

Though the other computer has the "aes" flag set in flags.

hannesm commented 9 years ago

on your computer with aes, it should work fine. on the other, could you run ./configure --disable-modernity and install to see whether this works fine, please (atm, on x86 AESNI is used by default)?

vbmithr commented 9 years ago

When disabling modernity, it works.

By the way, I have this message:

Fatal error: exception Uncommon.Boot.Unseeded_generator

Is there a simple way to forget about seeding and have the thing working ?

vbmithr commented 9 years ago

I don't understand why aesni gets selected on my non-AES machine.

hannesm commented 9 years ago

[RNG seeding] depends on where you are running on Unix, lwt or xen

vbmithr commented 9 years ago

In _oasis:

  if flag(modernity) && architecture(amd64)
    CCOpt+: -msse2 -maes

By default, -maes is used, with apparently no check if the CPU supports it or not.

vbmithr commented 9 years ago

Unix and lwt

vbmithr commented 9 years ago

Ok, thanks!

avsm commented 9 years ago

A runtime check is definitely needed unfortunately ... several amd64 CPUs will not have AES-NI (and it can be masked by hypervisors as well)

pqwy commented 9 years ago

My little gambit of assuming people mostly have AES-NI didn't work out, in the end... :crying_cat_face:

@avsm In the end definitely, but I was hoping to test-drive the code in a simpler form before adding dynamic detection. I added a small check to the build phase, to start with.

@vbmithr Can you please test out cb910f52e3df3c11eab5fca907d54eaba4456df9 on both machines? Configuration should report different values of Use CPU extensions (SSE2, AES-NI): ... even without manual ./configure flags, and AES-NI should be used only where supported.

vbmithr commented 9 years ago

On 05/07/2015 04:54, David Kaloper wrote:

@vbmithr https://github.com/vbmithr Can you please test out cb910f5 https://github.com/mirleft/ocaml-nocrypto/commit/cb910f52e3df3c11eab5fca907d54eaba4456df9 on both machines? Configuration should report different values of |Use CPU extensions (SSE2, AES-NI): ...| even without manual |./configure| flags, and AES-NI should be used only where supported.

Working now, thanks :)

Vincent

pqwy commented 9 years ago

@vbmithr After this gets merged, you should be able to opam install 0.5.1, which has the check.

Thanks for the report and sorry for using you as a guinea pig.

guinea pig

vbmithr commented 9 years ago

Hahaha :) I had fun with this guinea pig but not took the time to respond. Those animals are frightened all their lives, not really a cool beast to be compared to :))