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

tidb_query_vec_executors: Fixed stack-borrowing undefined-behavior (#7709) #7714

Merged
merged 2 commits into from
May 11, 2020

Conversation

sre-bot
Copy link
Contributor

@sre-bot sre-bot commented Apr 30, 2020

cherry-pick #7709 to release-4.0


What problem does this PR solve?

This fixes undefined behavior in tidb_query_vec_executors. Miri reports a stacked borrowing error as described below.

Note that stacked borrowing is a way to model Rust's use of unsafe pointers, but is not officially part of Rust's memory model. Thus, this is not truly undefined behavior today, but could be eventually.

I don't understand the stacked borrowing rules enough to understand why the
existing code is a violation. It is creating a mutable unsafe pointer; then
taking some immutable borrows to the same data while doing nothing with that
pointer; then later using the pointer.

Simply moving the creation of the unsafe pointer to immediately before it
is used removes the error.

cc @RalfJung not sure if you like being tagged on miri stacked borrow reports. If you have time though maybe you could explain what's going on here.

Found with miri, which reports:

error: Undefined Behavior: trying to reborrow for SharedReadOnly, but parent tag <1121039> does not have an appropriate item in the borrow sta
ck
   --> components/tidb_query_vec_executors/src/slow_hash_aggr_executor.rs:281:32
    |
281 |             let offset_begin = self.group_key_buffer.len();
    |                                ^^^^^^^^^^^^^^^^^^^^^ trying to reborrow for SharedReadOnly, but parent tag <1121039> does not have an ap
propriate item in the borrow stack
    |
    = help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
    = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

Signed-off-by: Brian Anderson [email protected]

Release note

  • Fixed an undefined behaviour in Coprocessor.

@sre-bot
Copy link
Contributor Author

sre-bot commented Apr 30, 2020

/run-all-tests

@MyonKeminta
Copy link
Contributor

/merge

@sre-bot sre-bot added the status/can-merge Status: Can merge to base branch label May 11, 2020
@sre-bot
Copy link
Contributor Author

sre-bot commented May 11, 2020

Your auto merge job has been accepted, waiting for:

  • 7739
  • 7719

@sre-bot
Copy link
Contributor Author

sre-bot commented May 11, 2020

@sre-bot
Copy link
Contributor Author

sre-bot commented May 11, 2020

@sre-bot
Copy link
Contributor Author

sre-bot commented May 11, 2020

/run-all-tests

@sre-bot
Copy link
Contributor Author

sre-bot commented May 11, 2020

@sre-bot merge failed.

@MyonKeminta
Copy link
Contributor

/merge

@sre-bot
Copy link
Contributor Author

sre-bot commented May 11, 2020

/run-all-tests

@sre-bot
Copy link
Contributor Author

sre-bot commented May 11, 2020

@sre-bot merge failed.

@MyonKeminta
Copy link
Contributor

/rebuild

@MyonKeminta MyonKeminta reopened this May 11, 2020
@MyonKeminta MyonKeminta merged commit 19690cb into tikv:release-4.0 May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/can-merge Status: Can merge to base branch type/cherry-pick Type: PR - Cherry pick
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants