kv: Set finished before the stdin handler removes itself #216
Reference in New Issue
Block a user
No description provided.
Delete Branch "koolkhel/vitastor:epoll-handler-copy"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
vitastor-kv's interactive stdin handler (src/kv/kv_cli.cpp:197-201) removes its own FD handler on EPOLLRDHUP and then sets
finished = true.set_fd_handler(0, false, NULL)erases the handler's std::function fromepoll_handlerswhile the lambda is still running, sofinishedis reached through the capturedthisin the freed closure. Set the flag first; the removal is then the last thing the handler does.Found: by reading the code, then reproduced: vitastor-kv built with ASAN, against a local etcd, with stdin a socket whose peer closes. Practical impact is small: it needs stdin to be a socket, and the process is about to exit anyway.
Tested: that run reports heap-use-after-free at kv_cli.cpp:200 on master (4 of 4 runs) and exits cleanly with the fix (3 of 3).
Contributor Name
Yury Luneff (MIND Software LLC, https://mindsw.io)
CLA
epoll_manager: Call FD handlers through a copyto kv: Set finished before the stdin handler removes itselfc7db8d4b06to4f9a123dceReworked as asked: the fix is now on the kv side (set
finishedbefore the stdin handler removes itself), epoll_manager is unchanged and test_epoll_manager is dropped.