instacart / instacart/TrueTime.swift
Heap buffer overflow
- Dominant language
- Swift
- Stars
- 634
- Forks
- 154
- PR merge metrics
- No merged PRs in 30d
Description
Address sanitizer detects Heap buffer overflow when using TrueTime
I am using Xcode Version 10.0 beta 4 (10L213o)
How to reproduce:
- Create new iOS project
- use cocoapods to add `pod 'TrueTime'` to the project
- change pod swift version from 4 to 3 (otherwise it won't compile)
- in AppDelegate import TrueTime and add `TrueTimeClient.sharedInstance.start()`
- enable address sanitizer
- launch app
```
1116
=================================================================
==8706==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x607000040e30 at pc 0x00010cafe031 bp 0x70000b5ffad0 sp 0x70000b5ffac8
READ of size 1 at 0x607000040e30 thread T2
#0 0x10cafe030 in $S8TrueTime13SocketAddressO7storage4portACSgSPySo09sockaddr_E0VG_s6UInt16VSgtcfC (TrueTime:x86_64+0xb5030)
#1 0x10ca6b478 in $S8TrueTime12HostResolverC7connect33_974D77A194DE214D8271763D66939F35LLyySo9CFHostRefaFyycfU_AA13SocketAddressOSg10Foundation4DataVXEfU_ (TrueTime:x86_64+0x22478)
#2 0x10ca6bb1c in $S8TrueTime12HostResolverC7connect33_974D77A194DE214D8271763D66939F35LLyySo9CFHostRefaFyycfU_AA13SocketAddressOSg10Foundation4DataVXEfU_TA (TrueTime:x86_64+0x22b1c)
#3 0x10ca6bc5d in $S10Foundation4DataV8TrueTime13SocketAddressOSgs5Error_pIgndzo_AcGsAH_pIegnrzo_TR (TrueTime:x86_64+0x22c5d)
#4 0x10ca6c4ba in $S10Foundation4DataV8TrueTime13SocketAddressOSgs5Error_pIgndzo_AcGsAH_pIegnrzo_TRTA (TrueTime:x86_64+0x234ba)
#5 0x10dfea17e in $SSlsE3mapySayqd__Gqd__7ElementQzKXEKlF (libswiftCore.dylib:x86_64+0x1f17e)
#6 0x10ca6a6c2 in $S8TrueTime12HostResolverC7connect33_974D77A194DE214D8271763D66939F35LLyySo9CFHostRefaFyycfU_ (TrueTime:x86_64+0x216c2)
#7 0x10ca6abf0 in $S8TrueTime12HostResolverC7connect33_974D77A194DE214D8271763D66939F35LLyySo9CFHostRefaFyycfU_TA (TrueTime:x86_64+0x21bf0)
#8 0x10ca5dc1d in $SIeg_IeyB_TR (TrueTime:x86_64+0x14c1d)
#9 0x10b7a2105 in __wrap_dispatch_async_block_invoke (libclang_rt.asan_iossim_dynamic.dylib:x86_64+0x52105)
#10 0x10ff5a224 in _dispatch_call_block_and_release (libdispatch.dylib:x86_64+0x3224)
#11 0x10ff5b2df in _dispatch_client_callout (libdispatch.dylib:x86_64+0x42df)
#12 0x10ff628b0 in _dispatch_lane_serial_drain (libdispatch.dylib:x86_64+0xb8b0)
#13 0x10ff6351d in _dispatch_lane_invoke (libdispatch.dylib:x86_64+0xc51d)
#14 0x10ff6d659 in _dispatch_workloop_worker_thread (libdispatch.dylib:x86_64+0x16659)
#15 0x110349fd1 in _pthread_wqthread (libsystem_pthread.dylib:x86_64+0x2fd1)
#16 0x110349be8 in start_wqthread (libsystem_pthread.dylib:x86_64+0x2be8)
#17 0x10fffffff (libdyld.dylib):x86_64+0x2ffff)
0x607000040e30 is located 0 bytes to the right of 80-byte region [0x607000040de0,0x607000040e30)
allocated by thread T2 here:
#0 0x10b7a3e53 in __sanitizer_mz_malloc (libclang_rt.asan_iossim_dynamic.dylib:x86_64+0x53e53)
#1 0x110200e51 in malloc_zone_malloc (libsystem_malloc.dylib:x86_64+0xfe51)
#2 0x10dae8722 in _CFRuntimeCreateInstance (CoreFoundation:x86_64+0x8e722)
#3 0x10da940a2 in __CFDataInit (CoreFoundation:x86_64+0x3a0a2)
#4 0x10f0f639f in _HostLookup_Master_dispatch_GetAddrInfoCallBack(int, addrinfo*, void*) (CFNetwork:x86_64+0x16739f)
#5 0x11015d0d8 in si_libinfo_addrinfo_callback (libsystem_info.dylib:x86_64+0x130d8)
#6 0x11016f55c in si_async_handle_reply (libsystem_info.dylib:x86_64+0x2555c)
#7 0x11015d25c in getaddrinfo_async_handle_reply (libsystem_info.dylib:x86_64+0x1325c)
#8 0x10f19cacb in DispatchHost::GetAddrAsyncHelper::handle_mach_msg_received(unsigned int) (CFNetwork:x86_64+0x20dacb)
#9 0x10f19cbd8 in invocation function for block in DispatchHost::createAndEnqueuePortSource(unsigned int) (CFNetwork:x86_64+0x20dbd8)
#10 0x10b7a26e5 in __wrap_dispatch_source_set_cancel_handler_block_invoke (libclang_rt.asan_iossim_dynamic.dylib:x86_64+0x526e5)
#11 0x10ff5a224 in _dispatch_call_block_and_release (libdispatch.dylib:x86_64+0x3224)
#12 0x10ff5b2df in _dispatch_client_callout (libdispatch.dylib:x86_64+0x42df)
#13 0x10ff5e274 in _dispatch_continuation_pop (libdispatch.dylib:x86_64+0x7274)
#14 0x10ff702e4 in _dispatch_source_invoke (libdispatch.dylib:x86_64+0x192e4)
#15 0x10ff6d659 in _dispatch_workloop_worker_thread (libdispatch.dylib:x86_64+0x16659)
#16 0x110349fd1 in _pthread_wqthread (libsystem_pthread.dylib:x86_64+0x2fd1)
#17 0x110349be8 in start_wqthread (libsystem_pthread.dylib:x86_64+0x2be8)
#18 0x10fffffff (libdyld.dylib):x86_64+0x2ffff)
Thread T2 created by T0 here:
SUMMARY: AddressSanitizer: heap-buffer-overflow (TrueTime:x86_64+0xb5030) in $S8TrueTime13SocketAddressO7storage4portACSgSPySo09sockaddr_E0VG_s6UInt16VSgtcfC
Shadow bytes around the buggy address:
0x1c0e00008170: fd fd fa fa fa fa 00 00 00 00 00 00 00 00 00 00
0x1c0e00008180: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 fa fa
0x1c0e00008190: fa fa 00 00 00 00 00 00 00 00 00 fa fa fa fa fa
0x1c0e000081a0: 00 00 00 00 00 00 00 00 00 00 fa fa fa fa fd fd
0x1c0e000081b0: fd fd fd fd fd fd fd fd fa fa fa fa 00 00 00 00
=>0x1c0e000081c0: 00 00 00 00 00 00[fa]fa fa fa 00 00 00 00 00 00
0x1c0e000081d0: 00 00 00 00 fa fa fa fa 00 00 00 00 00 00 00 00
0x1c0e000081e0: 00 00 fa fa fa fa 00 00 00 00 00 00 00 00 00 00
0x1c0e000081f0: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 fa fa
0x1c0e00008200: fa fa fd fd fd fd fd fd fd fd fd fa fa fa fa fa
0x1c0e00008210: fd fd fd fd fd fd fd fd fd fa fa fa fa fa fd fd
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
2018-07-30 11:03:16.641328+0200 test[8706:749777] =================================================================
2018-07-30 11:03:16.641820+0200 test[8706:749777] ==8706==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x607000040e30 at pc 0x00010cafe031 bp 0x70000b5ffad0 sp 0x70000b5ffac8
2018-07-30 11:03:16.642051+0200 test[8706:749777] READ of size 1 at 0x607000040e30 thread T2
2018-07-30 11:03:16.642260+0200 test[8706:749777] #0 0x10cafe030 in $S8TrueTime13SocketAddressO7storage4portACSgSPySo09sockaddr_E0VG_s6UInt16VSgtcfC (TrueTime:x86_64+0xb5030)
2018-07-30 11:03:16.642473+0200 test[8706:749777] #1 0x10ca6b478 in $S8TrueTime12HostResolverC7connect33_974D77A194DE214D8271763D66939F35LLyySo9CFHostRefaFyycfU_AA13SocketAddressOSg10Foundation4DataVXEfU_ (TrueTime:x86_64+0x22478)
2018-07-30 11:03:16.642655+0200 test[8706:749777] #2 0x10ca6bb1c in $S8TrueTime12HostResolverC7connect33_974D77A194DE214D8271763D66939F35LLyySo9CFHostRefaFyycfU_AA13SocketAddressOSg10Foundation4DataVXEfU_TA (TrueTime:x86_64+0x22b1c)
2018-07-30 11:03:16.642864+0200 test[8706:749777] #3 0x10ca6bc5d in $S10Foundation4DataV8TrueTime13SocketAddressOSgs5Error_pIgndzo_AcGsAH_pIegnrzo_TR (TrueTime:x86_64+0x22c5d)
2018-07-30 11:03:16.643040+0200 test[8706:749777] #4 0x10ca6c4ba in $S10Foundation4DataV8TrueTime13SocketAddressOSgs5Error_pIgndzo_AcGsAH_pIegnrzo_TRTA (TrueTime:x86_64+0x234ba)
2018-07-30 11:03:16.643185+0200 test[8706:749777] #5 0x10dfea17e in $SSlsE3mapySayqd__Gqd__7ElementQzKXEKlF (libswiftCore.dylib:x86_64+0x1f17e)
2018-07-30 11:03:16.643363+0200 test[8706:749777] #6 0x10ca6a6c2 in $S8TrueTime12HostResolverC7connect33_974D77A194DE214D8271763D66939F35LLyySo9CFHostRefaFyycfU_ (TrueTime:x86_64+0x216c2)
2018-07-30 11:03:16.673345+0200 test[8706:749777] #7 0x10ca6abf0 in $S8TrueTime12HostResolverC7connect33_974D77A194DE214D8271763D66939F35LLyySo9CFHostRefaFyycfU_TA (TrueTime:x86_64+0x21bf0)
2018-07-30 11:03:16.673486+0200 test[8706:749777] #8 0x10ca5dc1d in $SIeg_IeyB_TR (TrueTime:x86_64+0x14c1d)
2018-07-30 11:03:16.673631+0200 test[8706:749777] #9 0x10b7a2105 in __wrap_dispatch_async_block_invoke (libclang_rt.asan_iossim_dynamic.dylib:x86_64+0x52105)
2018-07-30 11:03:16.673801+0200 test[8706:749777] #10 0x10ff5a224 in _dispatch_call_block_and_release (libdispatch.dylib:x86_64+0x3224)
2018-07-30 11:03:16.673920+0200 test[8706:749777] #11 0x10ff5b2df in _dispatch_client_callout (libdispatch.dylib:x86_64+0x42df)
2018-07-30 11:03:16.674054+0200 test[8706:749777] #12 0x10ff628b0 in _dispatch_lane_serial_drain (libdispatch.dylib:x86_64+0xb8b0)
2018-07-30 11:03:16.674257+0200 test[8706:749777] #13 0x10ff6351d in _dispatch_lane_invoke (libdispatch.dylib:x86_64+0xc51d)
2018-07-30 11:03:16.674419+0200 test[8706:749777] #14 0x10ff6d659 in _dispatch_workloop_worker_thread (libdispatch.dylib:x86_64+0x16659)
2018-07-30 11:03:16.674580+0200 test[8706:749777] #15 0x110349fd1 in _pthread_wqthread (libsystem_pthread.dylib:x86_64+0x2fd1)
2018-07-30 11:03:16.674705+0200 test[8706:749777] #16 0x110349be8 in start_wqthread (libsystem_pthread.dylib:x86_64+0x2be8)
2018-07-30 11:03:16.674876+0200 test[8706:749777] #17 0x10fffffff (libdyld.dylib):x86_64+0x2ffff)
2018-07-30 11:03:16.675056+0200 test[8706:749777]
2018-07-30 11:03:16.675188+0200 test[8706:749777] 0x607000040e30 is located 0 bytes to the right of 80-byte region [0x607000040de0,0x607000040e30)
2018-07-30 11:03:16.675375+0200 test[8706:749777] allocated by thread T2 here:
2018-07-30 11:03:16.675532+0200 test[8706:749777] #0 0x10b7a3e53 in __sanitizer_mz_malloc (libclang_rt.asan_iossim_dynamic.dylib:x86_64+0x53e53)
2018-07-30 11:03:16.675717+0200 test[8706:749777] #1 0x110200e51 in malloc_zone_malloc (libsystem_malloc.dylib:x86_64+0xfe51)
2018-07-30 11:03:16.675934+0200 test[8706:749777] #2 0x10dae8722 in _CFRuntimeCreateInstance (CoreFoundation:x86_64+0x8e722)
2018-07-30 11:03:16.676092+0200 test[8706:749777] #3 0x10da940a2 in __CFDataInit (CoreFoundation:x86_64+0x3a0a2)
2018-07-30 11:03:16.676355+0200 test[8706:749777] #4 0x10f0f639f in _HostLookup_Master_dispatch_GetAddrInfoCallBack(int, addrinfo*, void*) (CFNetwork:x86_64+0x16739f)
2018-07-30 11:03:16.676569+0200 test[8706:749777] #5 0x11015d0d8 in si_libinfo_addrinfo_callback (libsystem_info.dylib:x86_64+0x130d8)
2018-07-30 11:03:16.676790+0200 test[8706:749777] #6 0x11016f55c in si_async_handle_reply (libsystem_info.dylib:x86_64+0x2555c)
2018-07-30 11:03:16.677007+0200 test[8706:749777] #7 0x11015d25c in getaddrinfo_async_handle_reply (libsystem_info.dylib:x86_64+0x1325c)
2018-07-30 11:03:16.677218+0200 test[8706:749777] #8 0x10f19cacb in DispatchHost::GetAddrAsyncHelper::handle_mach_msg_received(unsigned int) (CFNetwork:x86_64+0x20dacb)
2018-07-30 11:03:16.677455+0200 test[8706:749777] #9 0x10f19cbd8 in invocation function for block in DispatchHost::createAndEnqueuePortSource(unsigned int) (CFNetwork:x86_64+0x20dbd8)
2018-07-30 11:03:16.677660+0200 test[8706:749777] #10 0x10b7a26e5 in __wrap_dispatch_source_set_cancel_handler_block_invoke (libclang_rt.asan_iossim_dynamic.dylib:x86_64+0x526e5)
2018-07-30 11:03:16.677846+0200 test[8706:749777] #11 0x10ff5a224 in _dispatch_call_block_and_release (libdispatch.dylib:x86_64+0x3224)
2018-07-30 11:03:16.678079+0200 test[8706:749777] #12 0x10ff5b2df in _dispatch_client_callout (libdispatch.dylib:x86_64+0x42df)
2018-07-30 11:03:16.678247+0200 test[8706:749777] #13 0x10ff5e274 in _dispatch_continuation_pop (libdispatch.dylib:x86_64+0x7274)
2018-07-30 11:03:16.678527+0200 test[8706:749777] #14 0x10ff702e4 in _dispatch_source_invoke (libdispatch.dylib:x86_64+0x192e4)
2018-07-30 11:03:16.678752+0200 test[8706:749777] #15 0x10ff6d659 in _dispatch_workloop_worker_thread (libdispatch.dylib:x86_64+0x16659)
2018-07-30 11:03:16.679084+0200 test[8706:749777] #16 0x110349fd1 in _pthread_wqthread (libsystem_pthread.dylib:x86_64+0x2fd1)
2018-07-30 11:03:16.679400+0200 test[8706:749777] #17 0x110349be8 in start_wqthread (libsystem_pthread.dylib:x86_64+0x2be8)
2018-07-30 11:03:16.679615+0200 test[8706:749777] #18 0x10fffffff (libdyld.dylib):x86_64+0x2ffff)
2018-07-30 11:03:16.679939+0200 test[8706:749777]
2018-07-30 11:03:16.680181+0200 test[8706:749777] Thread T2 created by T0 here:
2018-07-30 11:03:16.680497+0200 test[8706:749777]
2018-07-30 11:03:16.680701+0200 test[8706:749777]
2018-07-30 11:03:16.680903+0200 test[8706:749777] SUMMARY: AddressSanitizer: heap-buffer-overflow (TrueTime:x86_64+0xb5030) in $S8TrueTime13SocketAddressO7storage4portACSgSPySo09sockaddr_E0VG_s6UInt16VSgtcfC
2018-07-30 11:03:16.681081+0200 test[8706:749777] Shadow bytes around the buggy address:
2018-07-30 11:03:16.681244+0200 test[8706:749777] 0x1c0e00008170: fd fd fa fa fa fa 00 00 00 00 00 00 00 00 00 00
2018-07-30 11:03:16.681412+0200 test[8706:749777] 0x1c0e00008180: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 fa fa
2018-07-30 11:03:16.681599+0200 test[8706:749777] 0x1c0e00008190: fa fa 00 00 00 00 00 00 00 00 00 fa fa fa fa fa
2018-07-30 11:03:16.681801+0200 test[8706:749777] 0x1c0e000081a0: 00 00 00 00 00 00 00 00 00 00 fa fa fa fa fd fd
2018-07-30 11:03:16.681977+0200 test[8706:749777] 0x1c0e000081b0: fd fd fd fd fd fd fd fd fa fa fa fa 00 00 00 00
2018-07-30 11:03:16.682142+0200 test[8706:749777] =>0x1c0e000081c0: 00 00 00 00 00 00[fa]fa fa fa 00 00 00 00 00 00
2018-07-30 11:03:16.682310+0200 test[8706:749777] 0x1c0e000081d0: 00 00 00 00 fa fa fa fa 00 00 00 00 00 00 00 00
2018-07-30 11:03:16.682484+0200 test[8706:749777] 0x1c0e000081e0: 00 00 fa fa fa fa 00 00 00 00 00 00 00 00 00 00
2018-07-30 11:03:16.682687+0200 test[8706:749777] 0x1c0e000081f0: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 fa fa
2018-07-30 11:03:16.682886+0200 test[8706:749777] 0x1c0e00008200: fa fa fd fd fd fd fd fd fd fd fd fa fa fa fa fa
2018-07-30 11:03:16.683049+0200 test[8706:749777] 0x1c0e00008210: fd fd fd fd fd fd fd fd fd fa fa fa fa fa fd fd
2018-07-30 11:03:16.683203+0200 test[8706:749777] Shadow byte legend (one shadow byte represents 8 application bytes):
2018-07-30 11:03:16.683334+0200 test[8706:749777] Addressable: 00
2018-07-30 11:03:16.683516+0200 test[8706:749777] Partially addressable: 01 02 03 04 05 06 07
2018-07-30 11:03:16.683660+0200 test[8706:749777] Heap left redzone: fa
2018-07-30 11:03:16.683805+0200 test[8706:749777] Freed heap region: fd
2018-07-30 11:03:16.684006+0200 test[8706:749777] Stack left redzone: f1
2018-07-30 11:03:16.684197+0200 test[8706:749777] Stack mid redzone: f2
2018-07-30 11:03:16.684367+0200 test[8706:749777] Stack right redzone: f3
2018-07-30 11:03:16.684506+0200 test[8706:749777] Stack after return: f5
2018-07-30 11:03:16.684679+0200 test[8706:749777] Stack use after scope: f8
2018-07-30 11:03:16.684823+0200 test[8706:749777] Global redzone: f9
2018-07-30 11:03:16.684986+0200 test[8706:749777] Global init order: f6
2018-07-30 11:03:16.685159+0200 test[8706:749777] Poisoned by user: f7
2018-07-30 11:03:16.685316+0200 test[8706:749777] Container overflow: fc
2018-07-30 11:03:16.685470+0200 test[8706:749777] Array cookie: ac
2018-07-30 11:03:16.685632+0200 test[8706:749777] Intra object redzone: bb
2018-07-30 11:03:16.685775+0200 test[8706:749777] ASan internal: fe
2018-07-30 11:03:16.685965+0200 test[8706:749777] Left alloca redzone: ca
2018-07-30 11:03:16.686145+0200 test[8706:749777] Right alloca redzone: cb
2018-07-30 11:03:16.686331+0200 test[8706:749777]
==8706==ABORTING
Warning: hit breakpoint while running function, skipping commands and conditions to prevent recursion.AddressSanitizer report breakpoint hit. Use 'thread info -s' to get extended information about the report.
(lldb) thread info -s
thread #3: tid = 0xb70d1, 0x000000010b7ab810 libclang_rt.asan_iossim_dynamic.dylib`__asan::AsanDie(), queue = 'com.instacart.dns.host', stop reason = Heap buffer overflow
{
"access_size" : 1,
"access_type" : 0,
"address" : 106034152869424,
"description" : "heap-buffer-overflow",
"instrumentation_class" : "AddressSanitizer",
"pc" : 4507820081,
"stop_type" : "fatal_error"
}
(lldb)
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the SocketAddress storage initializer and HostResolver.connect, which the AddressSanitizer trace identifies. Reproduce the issue in an iOS project using TrueTime with Address Sanitizer enabled, then investigate the reported heap read. Done means the reproduction no longer reports a heap-buffer-overflow.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, swift
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100