Closed tersec closed 3 years ago
(gdb) down
#0 br_aes_x86ni_ctr_run (ctx=<optimized out>, iv=<optimized out>, cc=<optimized out>, data=0x7fffed9600b4, len=18446744073541955745) at nimbus-eth2/vendor/nim-bearssl/bearssl/csources/src/symcipher/aes_x86ni_ctr.c:158
158 x1 = _mm_xor_si128(x1,
(gdb) p buf
$1 = (unsigned char *) 0x7ffff7934ff4 ""
(gdb) l 159
154 }
155 if (len >= 64) {
156 x0 = _mm_xor_si128(x0,
157 _mm_loadu_si128((void *)(buf + 0)));
158 x1 = _mm_xor_si128(x1,
159 _mm_loadu_si128((void *)(buf + 16)));
160 x2 = _mm_xor_si128(x2,
161 _mm_loadu_si128((void *)(buf + 32)));
162 x3 = _mm_xor_si128(x3,
163 _mm_loadu_si128((void *)(buf + 48)));
One possible issue is that len
is incorrect, leading it to believe it can access buf + 16
:
(gdb) dow
#0 br_aes_x86ni_ctr_run (ctx=<optimized out>, iv=<optimized out>, cc=<optimized out>, data=0x7fffed9600b4, len=18446744073541955745)
at nimbus-eth2/vendor/nim-bearssl/bearssl/csources/src/symcipher/aes_x86ni_ctr.c:158
158 x1 = _mm_xor_si128(x1,
(gdb) p len
$12 = 18446744073541955745
(gdb) up
#1 0x0000555555ba38ff in do_ctr (xortag=0x7fffffffa920, len=18446744073709551585, data=0x7fffed9600b4, nonce=0x7fffed9600ac,
cc=0x7fffeef19300) at nimbus-eth2/vendor/nim-bearssl/bearssl/csources/src/ssl/ssl_rec_gcm.c:118
118 cc->bc.vtable->run(&cc->bc.vtable, iv, 2, data, len);
(gdb) p len
$13 = 18446744073709551585
(gdb) up
#2 gcm_encrypt (cc=0x7fffeef19300, record_type=21, version=771, data=0x7fffed9600b4, data_len=0x7fffffffa990)
at nimbus-eth2/vendor/nim-bearssl/bearssl/csources/src/ssl/ssl_rec_gcm.c:206
206 do_ctr(cc, buf - 8, buf, len, tmp);
(gdb) p len
$14 = 18446744073709551585
(gdb) p (int64_t)len
$15 = -31
It seems to come from: https://github.com/status-im/nim-chronos/blob/dcf197a8c7891252fc611508a7d364d4953001d9/chronos/streams/tlsstream.nim#L169-L191
https://github.com/status-im/nimbus-eth2/commit/614128654739102e6f4be6544864c57994358292