-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
ASAN stack-use-after-scope in soci::use with rvalues (Version: [1.12.0-rc1]) #4675
Comments
7 tasks
florent-uzio
pushed a commit
to florent-uzio/rippled
that referenced
this issue
Oct 6, 2023
Address a stack-use-after-scope issue when using rvalues with `soci::use`. Replace rvalues with lvalues to ensure the scope extends beyond the end of the expression. The issue arises from `soci` taking a reference to the rvalue without copying its value or extending its lifetime. `soci` references rvalues in `soci::use_container` and then the address in `soci_use_type`. For types like `int`, memory access post-lifetime is unlikely to cause issues. However, for `std::string`, the backing heap memory can be freed and potentially reused, leading to a potential segmentation fault. This was detected on x86_64 using clang-15 with asan. asan confirms resolution of the issue. Fix XRPLF#4675
sophiax851
pushed a commit
to sophiax851/rippled
that referenced
this issue
Jun 12, 2024
Address a stack-use-after-scope issue when using rvalues with `soci::use`. Replace rvalues with lvalues to ensure the scope extends beyond the end of the expression. The issue arises from `soci` taking a reference to the rvalue without copying its value or extending its lifetime. `soci` references rvalues in `soci::use_container` and then the address in `soci_use_type`. For types like `int`, memory access post-lifetime is unlikely to cause issues. However, for `std::string`, the backing heap memory can be freed and potentially reused, leading to a potential segmentation fault. This was detected on x86_64 using clang-15 with asan. asan confirms resolution of the issue. Fix XRPLF#4675
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue Description
We have stack-use-after-scope bugs since we're using ravlues with
soci::use
Steps to Reproduce
Build rippled with -Dsan=address, start a fresh Ledger server and trigger e.g. peer_reservations_add from a second instance. You may need to use a rather recent compiler for asan to catch most stack-use-after-scope errors.
Actual Result
ASAN detects stack use after scope which at least for
insertPeerReservation
anddeletePeerReservation
means we are accessing a std::string which already has been deleted. InupdateLedgerDBs
this may be more of an academic issue. But for the peer reservations we could actually get the nodeId overwritten by a different thread while we're reading it since the actual string content is on the heap.Environment
My Dockerfile:
Supporting Files
See also https://github.com/SOCI/soci/blob/master/docs/binding.md#object-lifetime-and-immutability and SOCI/soci#1070
server log with ASAN error
My rippled.cfg equals rippled-example.cfg and validators.txt equals validators-example.txt
The text was updated successfully, but these errors were encountered: