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

detail::exec_op::info memory not freed before completion #140

Open
anarthal opened this issue Aug 15, 2023 · 2 comments
Open

detail::exec_op::info memory not freed before completion #140

anarthal opened this issue Aug 15, 2023 · 2 comments

Comments

@anarthal
Copy link
Collaborator

Memory for req_info_type in exec_op is being allocated using the handler's associated allocator, but is not being freed before calling complete. This is a violation of one of Asio's composed ops principles.

This has been caught by ubsan when using Boost.Redis together with Boost.Async (I'm exercising the library by rewriting BoostServerTech). Boost.Async uses an internal, per-operation allocator. That is, when you call conn.async_exec(whatever, use_op), a stack-based memory pool of 2kb is created. All allocations for this async_exec will use these 2kb of memory first. Once this async_exec operation is done, the pool is destroyed. However, the call self.complete within async_exec resumes and keeps executing the coroutine that called async_exec. At this point, async_exec has a req_info_type object pointing to memory that has been freed (or re-used). When the shared_ptr<req_info_type> destructor runs, it will be accessing freed memory.

It's likely that this can be used to build exploits leading to arbitrary code execution.

@mzimbres
Copy link
Collaborator

This could be fixed after my last merge on develop where I remove the use of associated allocator.

@anarthal
Copy link
Collaborator Author

Even if you use the standard allocator, I'd say you should free any temporary memory acquired by the operation before calling complete, unless there is a strong reason not to do so, so that allocations don't stack up. But probably Klemens can give you a better understanding of the subject.

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

No branches or pull requests

2 participants