std: simplify SGX's UnsafeList - #161060
Conversation
|
r? @clarfonthey rustbot has assigned @clarfonthey. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
This is a very intrusive change that changes a lot about the inner workings of the list as well as the list API. I don't really support making this kind of change. |
|
Given that both |
|
The problem is that this needs to be very carefully designed and reviewed because it can easily lead to fundamental concurrency issues if there are any bugs. I don't see a good reason for such an intrusive change given there are much simpler fixes. |
|
I consider the pointer provenance laundering stuff to be a very complicated fix, so I don't think the "there are much simpler fixes" argument really holds. |
|
The entire code can be reviewed and fully understood assuming launder is a no-op. |
Launder is a runtime no-op, but is very significant at compile time as any issues with it will lead to silent miscompilations. |
|
Gonna also r? nia-e since she's working on that PR, and can decide whether to prefer this one instead long-term. |
|
I ended up approving #161334 for the time being, since this is going to affect SGX only. I still want to land (something like) this in the future for bus factor reasons, but it's gonna be a more involved review as I need to familiarise myself with SGX internals a little. In the meantime, this is blocked on the above landing & then a rebase probably. @rustbot blocked |
Fix soundness issues in std::sys::pal::sgx::waitqueue::unsafe_list Replace invalid uses of references in `std::sys::pal::sgx::waitqueue::unsafe_list` internals with raw pointers. I tried to keep the code structure the same as much as possible. In addition to the use of references flagged in the original issue, it turns out the head/tail (raw) pointer stored in the linked list caused provenance issues in miri. Switched to using UnsafePinned for that. PR organization: * Commit 1: Main soundness fix. * Commit 2: Use pinning in the `pub(crate)` API for UnsafeList. This code predates pinning in Rust. I believe this change isn't strictly necessary as I believe it's valid to document pinning requirements in the unsafe methods on UnsafeList. However, I felt it's better to be explicit about this now that pinning is available in the language. * Commit 3: Move UnsafeList to a platform-agnostic location so miri can be run on the test suite. This also adds some tests. This PR was developed with Claude Fable 5 through extensive interactive use, where I directed a detailed plan for making the changes needed for this fix. My input includes keeping the structure the same and the new internal abstraction for dealing with raw pointers. I'm not familiar with miri, I used Claude to test the changes with miri. It said the test suite was failing before the changes (both stacked borrows and tree borrows) but passing after. The additional tests developed this way have been added in the third commit. The head/tail pointer provenance issue was found with Claude. I thoroughly reviewed all the code, including comments, and made manual changes/deletions where necessary/appropriate. The PR description was written by me. r? @nia-e Fixes rust-lang#114581 Fixes rust-lang#160603 Fixes rust-lang#161060 Supersedes rust-lang#160641
Fix soundness issues in std::sys::pal::sgx::waitqueue::unsafe_list Replace invalid uses of references in `std::sys::pal::sgx::waitqueue::unsafe_list` internals with raw pointers. I tried to keep the code structure the same as much as possible. In addition to the use of references flagged in the original issue, it turns out the head/tail (raw) pointer stored in the linked list caused provenance issues in miri. Switched to using UnsafePinned for that. PR organization: * Commit 1: Main soundness fix. * Commit 2: Use pinning in the `pub(crate)` API for UnsafeList. This code predates pinning in Rust. I believe this change isn't strictly necessary as I believe it's valid to document pinning requirements in the unsafe methods on UnsafeList. However, I felt it's better to be explicit about this now that pinning is available in the language. * Commit 3: Move UnsafeList to a platform-agnostic location so miri can be run on the test suite. This also adds some tests. This PR was developed with Claude Fable 5 through extensive interactive use, where I directed a detailed plan for making the changes needed for this fix. My input includes keeping the structure the same and the new internal abstraction for dealing with raw pointers. I'm not familiar with miri, I used Claude to test the changes with miri. It said the test suite was failing before the changes (both stacked borrows and tree borrows) but passing after. The additional tests developed this way have been added in the third commit. The head/tail pointer provenance issue was found with Claude. I thoroughly reviewed all the code, including comments, and made manual changes/deletions where necessary/appropriate. The PR description was written by me. r? @nia-e Fixes rust-lang#114581 Fixes rust-lang#160603 Fixes rust-lang#161060 Supersedes rust-lang#160641
Fix soundness issues in std::sys::pal::sgx::waitqueue::unsafe_list Replace invalid uses of references in `std::sys::pal::sgx::waitqueue::unsafe_list` internals with raw pointers. I tried to keep the code structure the same as much as possible. In addition to the use of references flagged in the original issue, it turns out the head/tail (raw) pointer stored in the linked list caused provenance issues in miri. Switched to using UnsafePinned for that. PR organization: * Commit 1: Main soundness fix. * Commit 2: Use pinning in the `pub(crate)` API for UnsafeList. This code predates pinning in Rust. I believe this change isn't strictly necessary as I believe it's valid to document pinning requirements in the unsafe methods on UnsafeList. However, I felt it's better to be explicit about this now that pinning is available in the language. * Commit 3: Move UnsafeList to a platform-agnostic location so miri can be run on the test suite. This also adds some tests. This PR was developed with Claude Fable 5 through extensive interactive use, where I directed a detailed plan for making the changes needed for this fix. My input includes keeping the structure the same and the new internal abstraction for dealing with raw pointers. I'm not familiar with miri, I used Claude to test the changes with miri. It said the test suite was failing before the changes (both stacked borrows and tree borrows) but passing after. The additional tests developed this way have been added in the third commit. The head/tail pointer provenance issue was found with Claude. I thoroughly reviewed all the code, including comments, and made manual changes/deletions where necessary/appropriate. The PR description was written by me. r? @nia-e Fixes #114581 Fixes #160603 Fixes #161060 Supersedes #160641
Fix soundness issues in std::sys::pal::sgx::waitqueue::unsafe_list Replace invalid uses of references in `std::sys::pal::sgx::waitqueue::unsafe_list` internals with raw pointers. I tried to keep the code structure the same as much as possible. In addition to the use of references flagged in the original issue, it turns out the head/tail (raw) pointer stored in the linked list caused provenance issues in miri. Switched to using UnsafePinned for that. PR organization: * Commit 1: Main soundness fix. * Commit 2: Use pinning in the `pub(crate)` API for UnsafeList. This code predates pinning in Rust. I believe this change isn't strictly necessary as I believe it's valid to document pinning requirements in the unsafe methods on UnsafeList. However, I felt it's better to be explicit about this now that pinning is available in the language. * Commit 3: Move UnsafeList to a platform-agnostic location so miri can be run on the test suite. This also adds some tests. This PR was developed with Claude Fable 5 through extensive interactive use, where I directed a detailed plan for making the changes needed for this fix. My input includes keeping the structure the same and the new internal abstraction for dealing with raw pointers. I'm not familiar with miri, I used Claude to test the changes with miri. It said the test suite was failing before the changes (both stacked borrows and tree borrows) but passing after. The additional tests developed this way have been added in the third commit. The head/tail pointer provenance issue was found with Claude. I thoroughly reviewed all the code, including comments, and made manual changes/deletions where necessary/appropriate. The PR description was written by me. r? @nia-e Fixes rust-lang#114581 Fixes rust-lang#160603 Fixes rust-lang#161060 Supersedes rust-lang#160641
Rollup merge of #161334 - jethrogb:fix-sgx-unsafe-list, r=nia-e Fix soundness issues in std::sys::pal::sgx::waitqueue::unsafe_list Replace invalid uses of references in `std::sys::pal::sgx::waitqueue::unsafe_list` internals with raw pointers. I tried to keep the code structure the same as much as possible. In addition to the use of references flagged in the original issue, it turns out the head/tail (raw) pointer stored in the linked list caused provenance issues in miri. Switched to using UnsafePinned for that. PR organization: * Commit 1: Main soundness fix. * Commit 2: Use pinning in the `pub(crate)` API for UnsafeList. This code predates pinning in Rust. I believe this change isn't strictly necessary as I believe it's valid to document pinning requirements in the unsafe methods on UnsafeList. However, I felt it's better to be explicit about this now that pinning is available in the language. * Commit 3: Move UnsafeList to a platform-agnostic location so miri can be run on the test suite. This also adds some tests. This PR was developed with Claude Fable 5 through extensive interactive use, where I directed a detailed plan for making the changes needed for this fix. My input includes keeping the structure the same and the new internal abstraction for dealing with raw pointers. I'm not familiar with miri, I used Claude to test the changes with miri. It said the test suite was failing before the changes (both stacked borrows and tree borrows) but passing after. The additional tests developed this way have been added in the third commit. The head/tail pointer provenance issue was found with Claude. I thoroughly reviewed all the code, including comments, and made manual changes/deletions where necessary/appropriate. The PR description was written by me. r? @nia-e Fixes #114581 Fixes #160603 Fixes #161060 Supersedes #160641
|
Fixes #160603
Fixes #114581
This fixes the soundness issues in SGX's
UnsafeListby removing the use of a dummy node in the doubly-linked list, which would have required eitherUnsafePinnedor pointer laundering tricks to make sound (c.f. #160641). In addition, the code is now much more careful when it comes to creating mutable references to whole entries to avoid invalidating any shared borrows of the values when modifying lists.CC @jethrogb