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

Deallocate at least #3819

Merged
merged 3 commits into from Jun 23, 2023
Merged

Conversation

CaseyCarter
Copy link
Member

@CaseyCarter CaseyCarter commented Jun 21, 2023

#3712 broke BitCoin in Microsoft's internal Real World Code (RWC) test suite. They publicly derive an allocator from std::allocate, implementing allocate and deallocate but not allocate_at_least
(https://github.com/bitcoin/bitcoin/blob/f1b4975461364d5d40d2bfafc6b165dd5d7eec30/src/support/allocators/secure.h#L19-L56).
When vector allocates memory with std::allocator::allocate_at_least and tries to free it with secure_allocator::deallocate, terrible things happen.

We suspect this pattern is widespread, so we're reverting the change for now.

There's a second commit here to reapply the basic_string drive-by fix which we don't want to revert. (We want to merge these commits separately to make it easier to revert the revert in the future.)

Fixes VSO-1839141 / AB#1839141.

This reverts commit e37227e.

This broke BitCoin in Microsoft's internal Real World Code (RWC) test
suite. They publicy derive an allocator from `std::allocate`,
implementing `allocate` and `deallocate` but not `allocate_at_least`
(https://github.com/bitcoin/bitcoin/blob/f1b4975461364d5d40d2bfafc6b165dd5d7eec30/src/support/allocators/secure.h#L19-L56).
When `vector` allocates memory with `std::allocator::allocate_at_least`
and tries to free it with `secure_allocator::deallocate`, terrible
things happen.

We suspect this pattern is widespread, so we're reverting the change for now.
@CaseyCarter CaseyCarter added the bug Something isn't working label Jun 21, 2023
@CaseyCarter CaseyCarter requested a review from a team as a code owner June 21, 2023 23:23
@CaseyCarter CaseyCarter added the high priority Important! label Jun 21, 2023
@github-actions github-actions bot added this to Initial Review in Code Reviews Jun 21, 2023
@StephanTLavavej StephanTLavavej moved this from Initial Review to Ready To Merge in Code Reviews Jun 22, 2023
@StephanTLavavej StephanTLavavej self-assigned this Jun 22, 2023
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej
Copy link
Member

I've pushed a merge with main to resolve a trivial adjacent add/remove conflict in tests/std/test.lst.

@StephanTLavavej StephanTLavavej merged commit 40640c6 into microsoft:main Jun 23, 2023
35 checks passed
Code Reviews automation moved this from Ready To Merge to Done Jun 23, 2023
@StephanTLavavej
Copy link
Member

Thanks for finding the root cause of this major regression and fixing it so fast! 🌲 🎯 🛠️

@CaseyCarter CaseyCarter deleted the deallocate_at_least branch June 23, 2023 14:41
@CaseyCarter CaseyCarter mentioned this pull request Jul 11, 2023
achow101 added a commit to bitcoin-core/gui that referenced this pull request Jul 25, 2023
… std::allocator

07c59ed Don't derive secure_allocator from std::allocator (Casey Carter)

Pull request description:

  Giving the C++ Standard Committee control of the public interface of your type means they will break it. C++23 adds a new `allocate_at_least` member to `std::allocator`. Very bad things happen when, say, `std::vector` uses `allocate_at_least` from `secure_allocator`'s base to allocate memory which it then tries to free with `secure_allocator::deallocate`.

  (Discovered by microsoft/STL#3712, which will be reverted by microsoft/STL#3819 before it ships.)

ACKs for top commit:
  jonatack:
    re-ACK 07c59ed no change since my previous ACK apart from squashing the commits
  achow101:
    ACK 07c59ed
  john-moffett:
    ACK 07c59ed Reviewed and tested. Performance appears unaffected in my environment.

Tree-SHA512: 23606c40414d325f5605a9244d4dd50907fdf5f2fbf70f336accb3a2cb98baa8acd2972f46eab1b7fdec1d28a843a96b06083cd2d09791cda7c90ee218e5bbd5
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 9, 2023
…locator

07c59ed Don't derive secure_allocator from std::allocator (Casey Carter)

Pull request description:

  Giving the C++ Standard Committee control of the public interface of your type means they will break it. C++23 adds a new `allocate_at_least` member to `std::allocator`. Very bad things happen when, say, `std::vector` uses `allocate_at_least` from `secure_allocator`'s base to allocate memory which it then tries to free with `secure_allocator::deallocate`.

  (Discovered by microsoft/STL#3712, which will be reverted by microsoft/STL#3819 before it ships.)

ACKs for top commit:
  jonatack:
    re-ACK 07c59ed no change since my previous ACK apart from squashing the commits
  achow101:
    ACK 07c59ed
  john-moffett:
    ACK 07c59ed Reviewed and tested. Performance appears unaffected in my environment.

Tree-SHA512: 23606c40414d325f5605a9244d4dd50907fdf5f2fbf70f336accb3a2cb98baa8acd2972f46eab1b7fdec1d28a843a96b06083cd2d09791cda7c90ee218e5bbd5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working high priority Important!
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants