Details
-
Bug
-
Status: Closed (View Workflow)
-
Minor
-
Resolution: Fixed
-
6.4.14, 22.08.11, 23.02.8, 23.08.4
-
None
Description
This is only really possible by artificially introducing a sequence of events that ends up closing and opening a Endpoint before a dcall() from a router or filter resolves. This should also only be possible in a multi-level configuration where one service routes to another service.
The following is detected by ASAN with the artificial code.
=================================================================
|
==1097273==ERROR: AddressSanitizer: heap-use-after-free on address 0x61a000070fc0 at pc 0x7fffdfbcea27 bp 0x7fffe35fb920 sp 0x7fffe35fb918
|
READ of size 8 at 0x61a000070fc0 thread T7
|
#0 0x7fffdfbcea26 in std::operator==(std::_Deque_iterator<maxscale::Buffer, maxscale::Buffer&, maxscale::Buffer*> const&, std::_Deque_iterator<maxscale::Buffer, maxscale::Buffer&, maxscale::Buffer*> const&) /usr/include/c++/13/bits/stl_deque.h:273
|
#1 0x7fffdfbc2b42 in std::deque<maxscale::Buffer, std::allocator<maxscale::Buffer> >::empty() const /usr/include/c++/13/bits/stl_deque.h:1348
|
#2 0x7fffdfb92b00 in operator() ../../../../../MaxScale/server/modules/routing/readwritesplit/rwsplitsession.cc:103
|
#3 0x7fffdfba972a in __invoke_impl<bool, RWSplitSession::routeQuery(GWBUF*)::<lambda(GWBUF*)>&, GWBUF*> /usr/include/c++/13/bits/invoke.h:61
|
#4 0x7fffdfba897f in __invoke_r<bool, RWSplitSession::routeQuery(GWBUF*)::<lambda(GWBUF*)>&, GWBUF*> /usr/include/c++/13/bits/invoke.h:114
|
#5 0x7fffdfba793a in _M_invoke /usr/include/c++/13/bits/std_function.h:290
|
#6 0x7ffff539dead in std::function<bool (GWBUF*)>::operator()(GWBUF*) const /usr/include/c++/13/bits/std_function.h:591
|
#7 0x7ffff5372367 in operator() ../../../MaxScale/server/core/session.cc:659
|
#8 0x7ffff539623a in __invoke_impl<bool, MXS_SESSION::delay_routing(maxscale::Routable*, GWBUF*, int, std::function<bool(GWBUF*)>&&)::<lambda(maxbase::Worker::Callable::Action)>&, maxbase::Worker::Callable::Action> /usr/include/c++/13/bits/invoke.h:61
|
#9 0x7ffff5393f03 in __invoke_r<bool, MXS_SESSION::delay_routing(maxscale::Routable*, GWBUF*, int, std::function<bool(GWBUF*)>&&)::<lambda(maxbase::Worker::Callable::Action)>&, maxbase::Worker::Callable::Action> /usr/include/c++/13/bits/invoke.h:114
|
#10 0x7ffff53924b6 in _M_invoke /usr/include/c++/13/bits/std_function.h:290
|
#11 0x7ffff5035787 in std::function<bool (maxbase::Worker::Callable::Action)>::operator()(maxbase::Worker::Callable::Action) const /usr/include/c++/13/bits/std_function.h:591
|
#12 0x7ffff503434a in maxbase::Worker::DCallFunctorWithCancel::do_call(maxbase::Worker::Callable::Action) ../../../MaxScale/maxutils/maxbase/include/maxbase/worker.hh:1099
|
#13 0x7ffff574b03f in maxbase::Worker::DCall::call(maxbase::Worker::Callable::Action) ../../../../MaxScale/maxutils/maxbase/include/maxbase/worker.hh:939
|
#14 0x7ffff574520c in maxbase::Worker::tick() ../../../../MaxScale/maxutils/maxbase/src/worker.cc:1262
|
#15 0x7ffff576ac49 in maxbase::Worker::DelegatingTimer<maxbase::Worker>::tick() ../../../../MaxScale/maxutils/maxbase/include/maxbase/worker.hh:469
|
#16 0x7ffff5734aad in maxbase::WorkerTimer::handle_poll_events(maxbase::Worker*, unsigned int, maxbase::Pollable::Context) ../../../../MaxScale/maxutils/maxbase/src/worker.cc:336
|
#17 0x7ffff5740857 in maxbase::Worker::deliver_events(unsigned long, std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > >, maxbase::Pollable*, unsigned int, maxbase::Pollable::Context) ../../../../MaxScale/maxutils/maxbase/src/worker.cc:1074
|
#18 0x7ffff5743a2d in maxbase::Worker::poll_waitevents() ../../../../MaxScale/maxutils/maxbase/src/worker.cc:1203
|
#19 0x7ffff573df4c in maxbase::Worker::run(maxbase::Semaphore*) ../../../../MaxScale/maxutils/maxbase/src/worker.cc:851
|
#20 0x7ffff573fb83 in maxbase::Worker::thread_main(maxbase::Worker*, maxbase::Semaphore*) ../../../../MaxScale/maxutils/maxbase/src/worker.cc:965
|
#21 0x7ffff576b3d7 in void std::__invoke_impl<void, void (*)(maxbase::Worker*, maxbase::Semaphore*), maxbase::Worker*, maxbase::Semaphore*>(std::__invoke_other, void (*&&)(maxbase::Worker*, maxbase::Semaphore*), maxbase::Worker*&&, maxbase::Semaphore*&&) /usr/include/c++/13/bits/invoke.h:61
|
#22 0x7ffff576b1eb in std::__invoke_result<void (*)(maxbase::Worker*, maxbase::Semaphore*), maxbase::Worker*, maxbase::Semaphore*>::type std::__invoke<void (*)(maxbase::Worker*, maxbase::Semaphore*), maxbase::Worker*, maxbase::Semaphore*>(void (*&&)(maxbase::Worker*, maxbase::Semaphore*), maxbase::Worker*&&, maxbase::Semaphore*&&) /usr/include/c++/13/bits/invoke.h:96
|
#23 0x7ffff576aeb5 in void std::thread::_Invoker<std::tuple<void (*)(maxbase::Worker*, maxbase::Semaphore*), maxbase::Worker*, maxbase::Semaphore*> >::_M_invoke<0ul, 1ul, 2ul>(std::_Index_tuple<0ul, 1ul, 2ul>) /usr/include/c++/13/bits/std_thread.h:292
|
#24 0x7ffff576ac8d in std::thread::_Invoker<std::tuple<void (*)(maxbase::Worker*, maxbase::Semaphore*), maxbase::Worker*, maxbase::Semaphore*> >::operator()() /usr/include/c++/13/bits/std_thread.h:299
|
#25 0x7ffff576a790 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(maxbase::Worker*, maxbase::Semaphore*), maxbase::Worker*, maxbase::Semaphore*> > >::_M_run() /usr/include/c++/13/bits/std_thread.h:244
|
#26 0x7ffff1ae31e2 in execute_native_thread_routine ../../../../../libstdc++-v3/src/c++11/thread.cc:104
|
#27 0x7ffff14ac896 in start_thread /usr/src/debug/glibc-2.38-16.fc39.x86_64/nptl/pthread_create.c:444
|
#28 0x7ffff153380b in clone3 ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
|
|
0x61a000070fc0 is located 320 bytes inside of 1360-byte region [0x61a000070e80,0x61a0000713d0)
|
freed by thread T7 here:
|
#0 0x7ffff78dad28 in operator delete(void*, unsigned long) (/lib64/libasan.so.8+0xdad28) (BuildId: 7fcb7759bc17ef47f9682414b6d99732d6a6ab0c)
|
#1 0x7fffdfb92a20 in RWSplitSession::~RWSplitSession() ../../../../../MaxScale/server/modules/routing/readwritesplit/rwsplitsession.cc:91
|
#2 0x7ffff52dc663 in ServiceEndpoint::close() ../../../MaxScale/server/core/service.cc:1563
|
#3 0x7ffff4b91ea3 in maxscale::Backend::close(maxscale::Backend::close_type) ../../../MaxScale/server/core/backend.cc:61
|
#4 0x7ffff55ea39a in maxscale::RWBackend::close(maxscale::Backend::close_type) ../../../../../MaxScale/server/modules/protocol/MariaDB/rwbackend.cc:51
|
#5 0x7fffdfba2d8e in RWSplitSession::handleError(maxscale::ErrorType, GWBUF*, maxscale::Endpoint*, maxscale::Reply const&) ../../../../../MaxScale/server/modules/routing/readwritesplit/rwsplitsession.cc:993
|
#6 0x7ffff52de85c in ServiceEndpoint::handleError(maxscale::ErrorType, GWBUF*, maxscale::Endpoint*, maxscale::Reply const&) ../../../MaxScale/server/core/service.cc:1615
|
#7 0x7ffff52deade in ServiceEndpoint::handleError(maxscale::ErrorType, GWBUF*, maxscale::Endpoint*, maxscale::Reply const&) ../../../MaxScale/server/core/service.cc:1619
|
#8 0x7ffff525bcc7 in ServerEndpoint::handleError(maxscale::ErrorType, GWBUF*, maxscale::Endpoint*, maxscale::Reply const&) ../../../MaxScale/server/core/server.cc:1260
|
#9 0x7ffff546858b in MariaDBBackendConnection::do_handle_error(DCB*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, maxscale::ErrorType) ../../../../../MaxScale/server/modules/protocol/MariaDB/mariadb_backend.cc:638
|
#10 0x7ffff54773fe in MariaDBBackendConnection::hangup(DCB*) ../../../../../MaxScale/server/modules/protocol/MariaDB/mariadb_backend.cc:1451
|
#11 0x7ffff4e0bc43 in BackendDCB::hangup_cb(SERVER const*) ../../../MaxScale/server/core/dcb.cc:2058
|
#12 0x7ffff4e0be87 in operator() ../../../MaxScale/server/core/dcb.cc:2076
|
#13 0x7ffff4e1000b in __invoke_impl<void, BackendDCB::hangup(const SERVER*)::<lambda()>&> /usr/include/c++/13/bits/invoke.h:61
|
#14 0x7ffff4e0fd01 in __invoke_r<void, BackendDCB::hangup(const SERVER*)::<lambda()>&> /usr/include/c++/13/bits/invoke.h:111
|
#15 0x7ffff4e0f9c0 in _M_invoke /usr/include/c++/13/bits/std_function.h:290
|
#16 0x7ffff51eef15 in std::function<void ()>::operator()() const /usr/include/c++/13/bits/std_function.h:591
|
#17 0x7ffff573d088 in execute ../../../../MaxScale/maxutils/maxbase/src/worker.cc:785
|
#18 0x7ffff573f8f5 in maxbase::Worker::handle_message(maxbase::MessageQueue&, maxbase::MessageQueueMessage const&) ../../../../MaxScale/maxutils/maxbase/src/worker.cc:935
|
#19 0x7ffff56d2785 in maxbase::EventMessageQueue::handle_poll_events(maxbase::Worker*, unsigned int, maxbase::Pollable::Context) ../../../../MaxScale/maxutils/maxbase/src/messagequeue.cc:224
|
#20 0x7ffff5740857 in maxbase::Worker::deliver_events(unsigned long, std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > >, maxbase::Pollable*, unsigned int, maxbase::Pollable::Context) ../../../../MaxScale/maxutils/maxbase/src/worker.cc:1074
|
#21 0x7ffff5743a2d in maxbase::Worker::poll_waitevents() ../../../../MaxScale/maxutils/maxbase/src/worker.cc:1203
|
#22 0x7ffff573df4c in maxbase::Worker::run(maxbase::Semaphore*) ../../../../MaxScale/maxutils/maxbase/src/worker.cc:851
|
#23 0x7ffff573fb83 in maxbase::Worker::thread_main(maxbase::Worker*, maxbase::Semaphore*) ../../../../MaxScale/maxutils/maxbase/src/worker.cc:965
|
#24 0x7ffff576b3d7 in void std::__invoke_impl<void, void (*)(maxbase::Worker*, maxbase::Semaphore*), maxbase::Worker*, maxbase::Semaphore*>(std::__invoke_other, void (*&&)(maxbase::Worker*, maxbase::Semaphore*), maxbase::Worker*&&, maxbase::Semaphore*&&) /usr/include/c++/13/bits/invoke.h:61
|
#25 0x7ffff576b1eb in std::__invoke_result<void (*)(maxbase::Worker*, maxbase::Semaphore*), maxbase::Worker*, maxbase::Semaphore*>::type std::__invoke<void (*)(maxbase::Worker*, maxbase::Semaphore*), maxbase::Worker*, maxbase::Semaphore*>(void (*&&)(maxbase::Worker*, maxbase::Semaphore*), maxbase::Worker*&&, maxbase::Semaphore*&&) /usr/include/c++/13/bits/invoke.h:96
|
#26 0x7ffff576aeb5 in void std::thread::_Invoker<std::tuple<void (*)(maxbase::Worker*, maxbase::Semaphore*), maxbase::Worker*, maxbase::Semaphore*> >::_M_invoke<0ul, 1ul, 2ul>(std::_Index_tuple<0ul, 1ul, 2ul>) /usr/include/c++/13/bits/std_thread.h:292
|
#27 0x7ffff576ac8d in std::thread::_Invoker<std::tuple<void (*)(maxbase::Worker*, maxbase::Semaphore*), maxbase::Worker*, maxbase::Semaphore*> >::operator()() /usr/include/c++/13/bits/std_thread.h:299
|
#28 0x7ffff576a790 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(maxbase::Worker*, maxbase::Semaphore*), maxbase::Worker*, maxbase::Semaphore*> > >::_M_run() /usr/include/c++/13/bits/std_thread.h:244
|
#29 0x7ffff1ae31e2 in execute_native_thread_routine ../../../../../libstdc++-v3/src/c++11/thread.cc:104
|
|
previously allocated by thread T7 here:
|
#0 0x7ffff78da0e0 in operator new(unsigned long, std::nothrow_t const&) (/lib64/libasan.so.8+0xda0e0) (BuildId: 7fcb7759bc17ef47f9682414b6d99732d6a6ab0c)
|
#1 0x7fffdfb910ba in RWSplitSession::create(RWSplit*, MXS_SESSION*, std::vector<maxscale::Endpoint*, std::allocator<maxscale::Endpoint*> > const&) ../../../../../MaxScale/server/modules/routing/readwritesplit/rwsplitsession.cc:52
|
#2 0x7fffdfb02050 in RWSplit::newSession(MXS_SESSION*, std::vector<maxscale::Endpoint*, std::allocator<maxscale::Endpoint*> > const&) ../../../../../MaxScale/server/modules/routing/readwritesplit/readwritesplit.cc:360
|
#3 0x7ffff52d9a9c in ServiceEndpoint::connect() ../../../MaxScale/server/core/service.cc:1483
|
#4 0x7ffff4b92489 in maxscale::Backend::connect() ../../../MaxScale/server/core/backend.cc:85
|
#5 0x7fffdfbf2b4d in RWSplitSession::prepare_connection(maxscale::RWBackend*) ../../../../../MaxScale/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc:47
|
#6 0x7fffdfbf3391 in RWSplitSession::prepare_target(maxscale::RWBackend*, unsigned int) ../../../../../MaxScale/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc:67
|
#7 0x7fffdfbf8b5d in RWSplitSession::route_single_stmt(maxscale::Buffer&&, RWSplitSession::RoutingPlan const&) ../../../../../MaxScale/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc:373
|
#8 0x7fffdfbf8496 in RWSplitSession::route_stmt(maxscale::Buffer&&, RWSplitSession::RoutingPlan const&) ../../../../../MaxScale/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc:339
|
#9 0x7fffdfb93d94 in RWSplitSession::route_query(maxscale::Buffer&&) ../../../../../MaxScale/server/modules/routing/readwritesplit/rwsplitsession.cc:141
|
#10 0x7fffdfbf37ea in operator() ../../../../../MaxScale/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc:83
|
#11 0x7fffdfc05ef8 in __invoke_impl<bool, RWSplitSession::retry_query(GWBUF*, int)::<lambda(GWBUF*)>&, GWBUF*> /usr/include/c++/13/bits/invoke.h:61
|
#12 0x7fffdfc05a06 in __invoke_r<bool, RWSplitSession::retry_query(GWBUF*, int)::<lambda(GWBUF*)>&, GWBUF*> /usr/include/c++/13/bits/invoke.h:114
|
#13 0x7fffdfc0550a in _M_invoke /usr/include/c++/13/bits/std_function.h:290
|
#14 0x7ffff539dead in std::function<bool (GWBUF*)>::operator()(GWBUF*) const /usr/include/c++/13/bits/std_function.h:591
|
#15 0x7ffff5372367 in operator() ../../../MaxScale/server/core/session.cc:659
|
#16 0x7ffff539623a in __invoke_impl<bool, MXS_SESSION::delay_routing(maxscale::Routable*, GWBUF*, int, std::function<bool(GWBUF*)>&&)::<lambda(maxbase::Worker::Callable::Action)>&, maxbase::Worker::Callable::Action> /usr/include/c++/13/bits/invoke.h:61
|
#17 0x7ffff5393f03 in __invoke_r<bool, MXS_SESSION::delay_routing(maxscale::Routable*, GWBUF*, int, std::function<bool(GWBUF*)>&&)::<lambda(maxbase::Worker::Callable::Action)>&, maxbase::Worker::Callable::Action> /usr/include/c++/13/bits/invoke.h:114
|
#18 0x7ffff53924b6 in _M_invoke /usr/include/c++/13/bits/std_function.h:290
|
#19 0x7ffff5035787 in std::function<bool (maxbase::Worker::Callable::Action)>::operator()(maxbase::Worker::Callable::Action) const /usr/include/c++/13/bits/std_function.h:591
|
#20 0x7ffff503434a in maxbase::Worker::DCallFunctorWithCancel::do_call(maxbase::Worker::Callable::Action) ../../../MaxScale/maxutils/maxbase/include/maxbase/worker.hh:1099
|
#21 0x7ffff574b03f in maxbase::Worker::DCall::call(maxbase::Worker::Callable::Action) ../../../../MaxScale/maxutils/maxbase/include/maxbase/worker.hh:939
|
#22 0x7ffff574520c in maxbase::Worker::tick() ../../../../MaxScale/maxutils/maxbase/src/worker.cc:1262
|
#23 0x7ffff576ac49 in maxbase::Worker::DelegatingTimer<maxbase::Worker>::tick() ../../../../MaxScale/maxutils/maxbase/include/maxbase/worker.hh:469
|
#24 0x7ffff5734aad in maxbase::WorkerTimer::handle_poll_events(maxbase::Worker*, unsigned int, maxbase::Pollable::Context) ../../../../MaxScale/maxutils/maxbase/src/worker.cc:336
|
#25 0x7ffff5740857 in maxbase::Worker::deliver_events(unsigned long, std::chrono::time_point<std::chrono::_V2::steady_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > >, maxbase::Pollable*, unsigned int, maxbase::Pollable::Context) ../../../../MaxScale/maxutils/maxbase/src/worker.cc:1074
|
#26 0x7ffff5743a2d in maxbase::Worker::poll_waitevents() ../../../../MaxScale/maxutils/maxbase/src/worker.cc:1203
|
#27 0x7ffff573df4c in maxbase::Worker::run(maxbase::Semaphore*) ../../../../MaxScale/maxutils/maxbase/src/worker.cc:851
|
#28 0x7ffff573fb83 in maxbase::Worker::thread_main(maxbase::Worker*, maxbase::Semaphore*) ../../../../MaxScale/maxutils/maxbase/src/worker.cc:965
|
#29 0x7ffff576b3d7 in void std::__invoke_impl<void, void (*)(maxbase::Worker*, maxbase::Semaphore*), maxbase::Worker*, maxbase::Semaphore*>(std::__invoke_other, void (*&&)(maxbase::Worker*, maxbase::Semaphore*), maxbase::Worker*&&, maxbase::Semaphore*&&) /usr/include/c++/13/bits/invoke.h:61
|
|
Thread T7 created by T0 here:
|
#0 0x7ffff7848956 in pthread_create (/lib64/libasan.so.8+0x48956) (BuildId: 7fcb7759bc17ef47f9682414b6d99732d6a6ab0c)
|
#1 0x7ffff1ae32b8 in std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) /usr/src/debug/gcc-13.2.1-6.fc39.x86_64/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/x86_64-redhat-linux/bits/gthr-default.h:663
|
#2 0x7ffff573e8fa in maxbase::Worker::start(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ../../../../MaxScale/maxutils/maxbase/src/worker.cc:878
|
#3 0x7ffff51c23a7 in maxscale::RoutingWorker::start_workers() ../../../MaxScale/server/core/routingworker.cc:390
|
#4 0x2491bd in main ../../../MaxScale/server/core/gateway.cc:2230
|
#5 0x7ffff1446149 in __libc_start_call_main (/lib64/libc.so.6+0x28149) (BuildId: 7ea8d85df0e89b90c63ac7ed2b3578b2e7728756)
|
#6 0x7ffff144620a in __libc_start_main_impl (/lib64/libc.so.6+0x2820a) (BuildId: 7ea8d85df0e89b90c63ac7ed2b3578b2e7728756)
|
#7 0x23ba54 in _start (/home/markusjm/build-develop/bin/maxscale+0x23ba54) (BuildId: 0a49c1705bc7dd1d38654a9195d54d0cf9bc49a3)
|
|
SUMMARY: AddressSanitizer: heap-use-after-free /usr/include/c++/13/bits/stl_deque.h:273 in std::operator==(std::_Deque_iterator<maxscale::Buffer, maxscale::Buffer&, maxscale::Buffer*> const&, std::_Deque_iterator<maxscale::Buffer, maxscale::Buffer&, maxscale::Buffer*> const&)
|
Shadow bytes around the buggy address:
|
0x61a000070d00: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
|
0x61a000070d80: fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa fa
|
0x61a000070e00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
|
0x61a000070e80: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
|
0x61a000070f00: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
|
=>0x61a000070f80: fd fd fd fd fd fd fd fd[fd]fd fd fd fd fd fd fd
|
0x61a000071000: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
|
0x61a000071080: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
|
0x61a000071100: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
|
0x61a000071180: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
|
0x61a000071200: fd fd fd fd fd fd fd fd fd fd fd fd fd fd 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
|
==1097273==ABORTING
|