rustls-ffi icon indicating copy to clipboard operation
rustls-ffi copied to clipboard

[Win32] Crashes with ASAN

Open gvanem opened this issue 3 years ago • 8 comments

I've built and used CrustTls in the demo and libcurl for some time with great success.

But enabling AddressSanitizer (ASAN) feature of latest MSVC-2019 (cl ver. 19.28.29912 for x86), both curl https://whatever ... and a crustls-demo.exe www.vg.no / > test.file abort with this trace:

Sending:
GET / HTTP/1.1
Host: www.vg.no
...
ClientSession wants us to write_tls.
ClientSession wants us to read_tls. First we need to pull some bytes from the socket
=================================================================
==15612==ERROR: AddressSanitizer: memcpy-param-overlap: memory ranges [0x07487200,0x07487735) and [0x0748727f, 0x074877b4) overlap
    #0 0x611a1dcf  (f:\gv\VC_2019\VC\Tools\MSVC\14.28.29910\bin\HostX86\x86\clang_rt.asan_dynamic-i386.dll+0x10031dcf)
    #1 0x106beb in _ZN6rustls4msgs8deframer15MessageDeframer4read17hd804cc7f869bdd48E (F:\MingW32\src\inet\Crypto\Crustls\crustls-demo.exe+0x406beb)
    #2 0x1129aa in _ZN74_$LT$rustls..client..ClientSession$u20$as$u20$rustls..session..Session$GT$8read_tls17h1cfd14ff7a451970E (F:\MingW32\src\inet\Crypto\Crustls\crustls-demo.exe+0x4129aa)
    #3 0x102673 in rustls_client_session_read_tls (F:\MingW32\src\inet\Crypto\Crustls\crustls-demo.exe+0x402673)
    #4 0x24e247 in copy_tls_bytes_into_client_session F:\MingW32\src\inet\Crypto\Crustls\src\main.c:217
    #5 0x24e5d3 in do_read F:\MingW32\src\inet\Crypto\Crustls\src\main.c:345
    #6 0x24f621 in send_request_and_read_response F:\MingW32\src\inet\Crypto\Crustls\src\main.c:434
    #7 0x24ebf0 in main F:\MingW32\src\inet\Crypto\Crustls\src\main.c:591
    #8 0x26038e in _scrt_common_main_seh d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
    #9 0x7656fa28  (C:\WINDOWS\System32\KERNEL32.DLL+0x6b81fa28)
    #10 0x771d7c7d  (C:\WINDOWS\SYSTEM32\ntdll.dll+0x4b2e7c7d)
    #11 0x771d7c4d  (C:\WINDOWS\SYSTEM32\ntdll.dll+0x4b2e7c4d)

0x07487200 is located 0 bytes inside of 18437-byte region [0x07487200,0x0748ba05) allocated by thread T0 here:
    #0 0x611aa74c  (f:\gv\VC_2019\VC\Tools\MSVC\14.28.29910\bin\HostX86\x86\clang_rt.asan_dynamic-i386.dll+0x1003a74c)
    #1 0x140d8c in __rdl_alloc /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src\alloc.rs:356
    #2 0x112685 in _ZN6rustls6client13ClientSession3new17habc44068009b2037E (F:\MingW32\src\inet\Crypto\Crustls\crustls-demo.exe+0x412685)
    #3 0x158a95 in _ZN7crustls6client25rustls_client_session_new28_$u7b$$u7b$closure$u7d$$u7d$17hfc2e02940a78157fE.llvm.16205319766425828457 (F:\MingW32\src\inet\Crypto\Crustls\crustls-demo.exe+0x458a95)
    #4 0x101b7d in rustls_client_session_new (F:\MingW32\src\inet\Crypto\Crustls\crustls-demo.exe+0x401b7d)
    #5 0x24ebbb in main F:\MingW32\src\inet\Crypto\Crustls\src\main.c:591
    #6 0x26038e in _scrt_common_main_seh d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
    #7 0x7656fa28  (C:\WINDOWS\System32\KERNEL32.DLL+0x6b81fa28)
    #8 0x771d7c7d  (C:\WINDOWS\SYSTEM32\ntdll.dll+0x4b2e7c7d)
    #9 0x771d7c4d  (C:\WINDOWS\SYSTEM32\ntdll.dll+0x4b2e7c4d)

0x0748727f is located 127 bytes inside of 18437-byte region [0x07487200,0x0748ba05) allocated by thread T0 here:
    #0 0x611aa74c  (f:\gv\VC_2019\VC\Tools\MSVC\14.28.29910\bin\HostX86\x86\clang_rt.asan_dynamic-i386.dll+0x1003a74c)
    #1 0x140d8c in __rdl_alloc /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src\alloc.rs:356
    #2 0x112685 in _ZN6rustls6client13ClientSession3new17habc44068009b2037E (F:\MingW32\src\inet\Crypto\Crustls\crustls-demo.exe+0x412685)
    #3 0x158a95 in _ZN7crustls6client25rustls_client_session_new28_$u7b$$u7b$closure$u7d$$u7d$17hfc2e02940a78157fE.llvm.16205319766425828457 (F:\MingW32\src\inet\Crypto\Crustls\crustls-demo.exe+0x458a95)
    #4 0x101b7d in rustls_client_session_new (F:\MingW32\src\inet\Crypto\Crustls\crustls-demo.exe+0x401b7d)
    #5 0x24ebbb in main F:\MingW32\src\inet\Crypto\Crustls\src\main.c:591
    #6 0x26038e in _scrt_common_main_seh d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
    #7 0x7656fa28  (C:\WINDOWS\System32\KERNEL32.DLL+0x6b81fa28)
    #8 0x771d7c7d  (C:\WINDOWS\SYSTEM32\ntdll.dll+0x4b2e7c7d)
    #9 0x771d7c4d  (C:\WINDOWS\SYSTEM32\ntdll.dll+0x4b2e7c4d)

SUMMARY: AddressSanitizer: memcpy-param-overlap (f:\gv\VC_2019\VC\Tools\MSVC\14.28.29910\bin\HostX86\x86\clang_rt.asan_dynamic-i386.dll+0x10031dcf)
==15612==ABORTING

CFLAGS used: -fsanitize=address. Ref: https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes#16.9.0

A clang-cl v11 version with the same CFLAGS reports the same. The crash happens right after the 1st recv():

  * 0.292 sec: src/main.c(319) (do_read+149):
    recv (860, 0x0073E890, 2048, 0) --> 2048 bytes.
    0000: 16 03 03 00 7A 02 00 00 76 03 03 46 77 60 1C 0A  ....z...v..Fw`..
    0010: 29 CA 39 FE 7B 37 6E 30 97 77 9C 69 F5 A5 51 2A  )-9¦{7n0ùw£i)ÑQ*
    0020: 8E B8 0B 64 CC A5 64 56 62 6F 15 20 54 3D 19 2B  Ä+.d¦ÑdVbo. T=.+
    0030: 5B 16 7C 0B C7 34 60 9A C0 88 A5 A8 D5 D6 92 71  [.|.¦4`Ü+êÑ¿++Æq
    0040: A2 98 E2 13 2E 3D 57 33 30 7B FA 69 13 03 00 00  óÿG..=W30{·i....
    0050: 2E 00 33 00 24 00 1D 00 20 80 AB 91 09 58 98 98  ..3.$... ǽæ.Xÿÿ
    0060: 74 19 EB D8 97 98 EF 37 C5 88 80 E5 5A 72 17 10  t.d+ùÿn7+êÇsZr..
    0070: 6C 52 23 7E 49 B1 7A ED 53 00 2B 00 02 03 04 14  lR#~I¦zfS.+.....
    0080: 03 03 00 01 01 17 03 03 09 B7 C2 6D 9F 4B C1 92  .........+-mƒK-Æ
    0090: 1E E6 5D BF 27 7F 44 C5 03 40 A8 E5 2C EC F8 0B  .µ]+'.D+.@¿s,8°.
    00A0: 3D CC 0C 13 27 11 6A 46 07 2A 40 2A 76 1F 17 36  =¦..'.jF.*@*v..6
    00B0: BA 6A DD A5 2E 76 7D AA 08 1D C4 ED AF ED 87 C9  ¦j¦Ñ.v}¬..-f¤fç+
    00C0: A6 01 5F 80 8D 6E 97 1B 33 7F EB D0 28 50 14 46  ª._Çìnù.3.d-(P.F
    00D0: C8 90 73 1F 04 CF 05 9D 8A A1 5D 3F 3C 35 B1 7B  +És..-.Øèí]?<5¦{
    00E0: 86 69 C5 B0 40 E0 7E 01 FB B4 5B 0D 85 E7 5E 0A  åi+¦@a~.v¦[.àt^.
    00F0: 52 42 31 49 0B 0B E5 77 F5 C4 B0 55 0B E5 99 CA  RB1I..sw)-¦U.sÖ-
    0100: D5 44 3F D0 A9

(courtesy of my Wsock-trace library)

gvanem avatar Apr 08 '21 17:04 gvanem