Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Member access within misaligned address for type 'UTPSocketKeyData', which requires 8 byte alignment #6

Closed
Coeur opened this issue Jun 19, 2023 · 2 comments · Fixed by #7
Assignees

Comments

@Coeur
Copy link

Coeur commented Jun 19, 2023

What is the issue?

Undefined Behavior Runtime error in libutp, on that line:

conn->ctx->utp_sockets->Add(UTPSocketKey(conn->addr, conn->conn_id_recv))->socket = conn;

Thread 6: Misaligned pointer use
Member access within misaligned address 0x0001570734ec for type 'UTPSocketKeyData', which requires 8 byte alignment

It's not a crash, but as it says, it's undefined behavior.
The Xcode documentation to attempt to resolve that is at https://developer.apple.com/documentation/xcode/misaligned-pointer.

Historically, that piece of code is from 2013 (3652544). We kind of branched off libutp from a commit of July 2017 (https://github.com/transmission/libutp/tree/d7daf7f36f64da975fc1b42772f774cbd5ffbbf1), but the official bittorrent repo has been abandoned since then, so no one else is maintaining libutp officially. I still opened an issue at bittorrent#136 some time ago.

Capture d’écran 2023-06-18 à 00 21 02
Thread 6#0	0x0000000104f08eb4 in __ubsan_on_report ()
#1	0x0000000104f08f68 in __ubsan::UndefinedBehaviorReport::UndefinedBehaviorReport(char const*, __ubsan::Location&, __sanitizer::InternalScopedString&) ()
#2	0x0000000104f048f8 in __ubsan::Diag::~Diag() ()
#3	0x0000000104f06234 in handleTypeMismatchImpl(__ubsan::TypeMismatchData*, unsigned long, __ubsan::ReportOptions) ()
#4	0x0000000104f05ebc in __ubsan_handle_type_mismatch_v1 ()
#5	0x00000001033a44d8 in utp_initialize_socket(UTPSocket*, sockaddr const*, unsigned int, bool, unsigned int, unsigned int, unsigned int) at /Users/User/Developer/transmission/third-party/libutp/utp_internal.cpp:2574
#6	0x00000001033a7cfc in ::utp_connect(utp_socket *, const sockaddr *, socklen_t) at /Users/User/Developer/transmission/third-party/libutp/utp_internal.cpp:2748
#7	0x0000000102bcbfe8 in tr_peerIo::new_outgoing(tr_session*, tr_bandwidth*, tr_address const&, tr_port, std::__1::array<std::byte, 20ul> const&, bool, bool) at /Users/User/Developer/transmission/libtransmission/peer-io.cc:142
#8	0x0000000102bf647c in (anonymous namespace)::connect_helpers::initiateConnection(tr_peerMgr*, tr_swarm*, peer_atom&) at /Users/User/Developer/transmission/libtransmission/peer-mgr.cc:2451
#9	0x0000000102bf3608 in tr_peerMgr::makeNewPeerConnections(unsigned long) at /Users/User/Developer/transmission/libtransmission/peer-mgr.cc:2490
#10	0x0000000102bf2598 in tr_peerMgr::reconnectPulse() at /Users/User/Developer/transmission/libtransmission/peer-mgr.cc:2156
#11	0x0000000102bf39b8 in tr_peerMgr::bandwidthPulse() at /Users/User/Developer/transmission/libtransmission/peer-mgr.cc:2221
#12	0x0000000102bfeac4 in tr_peerMgr::tr_peerMgr(tr_session*)::'lambda'()::operator()() const at /Users/User/Developer/transmission/libtransmission/peer-mgr.cc:689
#13	0x0000000102bfea6c in decltype(std::declval<tr_peerMgr::tr_peerMgr(tr_session*)::'lambda'()&>()()) std::__1::__invoke[abi:v160002]<tr_peerMgr::tr_peerMgr(tr_session*)::'lambda'()&>(tr_peerMgr::tr_peerMgr(tr_session*)::'lambda'()&) at /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__functional/invoke.h:394
#14	0x0000000102bfe8dc in void std::__1::__invoke_void_return_wrapper<void, true>::__call<tr_peerMgr::tr_peerMgr(tr_session*)::'lambda'()&>(tr_peerMgr::tr_peerMgr(tr_session*)::'lambda'()&) at /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__functional/invoke.h:487
#15	0x0000000102bfe870 in std::__1::__function::__alloc_func<tr_peerMgr::tr_peerMgr(tr_session*)::'lambda'(), std::__1::allocator<tr_peerMgr::tr_peerMgr(tr_session*)::'lambda'()>, void ()>::operator()[abi:v160002]() at /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__functional/function.h:185
#16	0x0000000102bfa778 in std::__1::__function::__func<tr_peerMgr::tr_peerMgr(tr_session*)::'lambda'(), std::__1::allocator<tr_peerMgr::tr_peerMgr(tr_session*)::'lambda'()>, void ()>::operator()() at /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__functional/function.h:356
#17	0x0000000102b81754 in std::__1::__function::__value_func<void ()>::operator()[abi:v160002]() const at /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__functional/function.h:510
#18	0x0000000102b7ff90 in std::__1::function<void ()>::operator()() const at /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__functional/function.h:1156
#19	0x00000001030e0ab0 in libtransmission::EvTimer::handleTimer() at /Users/User/Developer/transmission/libtransmission/timer-ev.cc:145
#20	0x00000001030dfd40 in libtransmission::EvTimer::onTimer(int, short, void*) at /Users/User/Developer/transmission/libtransmission/timer-ev.cc:137
#21	0x0000000103286868 in event_persist_closure at /Users/User/Developer/transmission/third-party/libevent/event.c:1623
#22	0x000000010328255c in event_process_active_single_queue at /Users/User/Developer/transmission/third-party/libevent/event.c:1682
#23	0x00000001032621d8 in event_process_active at /Users/User/Developer/transmission/third-party/libevent/event.c:1783
#24	0x000000010325b600 in event_base_loop at /Users/User/Developer/transmission/third-party/libevent/event.c:2006
#25	0x0000000102b7e790 in tr_session_thread_impl::sessionThreadFunc(event_base*) at /Users/User/Developer/transmission/libtransmission/session-thread.cc:245
#26	0x0000000102b83980 in decltype(*std::declval<tr_session_thread_impl*>().*std::declval<void (tr_session_thread_impl::*)(event_base*)>()(std::declval<event_base*>())) std::__1::__invoke[abi:v160002]<void (tr_session_thread_impl::*)(event_base*), tr_session_thread_impl*, event_base*, void>(void (tr_session_thread_impl::*&&)(event_base*), tr_session_thread_impl*&&, event_base*&&) at /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__functional/invoke.h:359
#27	0x0000000102b838ac in void std::__1::__thread_execute[abi:v160002]<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (tr_session_thread_impl::*)(event_base*), tr_session_thread_impl*, event_base*, 2ul, 3ul>(std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (tr_session_thread_impl::*)(event_base*), tr_session_thread_impl*, event_base*>&, std::__1::__tuple_indices<2ul, 3ul>) at /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/thread:288
#28	0x0000000102b82770 in void* std::__1::__thread_proxy[abi:v160002]<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct>>, void (tr_session_thread_impl::*)(event_base*), tr_session_thread_impl*, event_base*>>(void*) at /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/thread:299
#29	0x0000000104b61628 in _pthread_start ()

Which application of Transmission?

macOS app

Which version of Transmission?

4.1.0-dev (76166d8fa7)

@ckerr
Copy link
Member

ckerr commented Nov 3, 2023

@Coeur, @mikedld, @tearfur PR is up @ #13

This is largish diff and the libutp repo has no tests. If / when we merge this and start using in Transmission, we will want a decent amount of time for nightly build users to test it out.

@Coeur
Copy link
Author

Coeur commented Nov 11, 2023

So, that issue was easily reproducible in current Transmission main (transmission/transmission@a575be7), which is based on c95738b.
Trying with newer libutp now (4ed4d43)... and the misaligned address undefined behavior is gone. 👍 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants