Skip to content

inout: fix Miri Stacked Borrows violation in PaddedInOutBuf - #1556

Merged
newpavlov merged 7 commits into
RustCrypto:masterfrom
TechnoPorg:push-klyklvnqmnzw
Oct 14, 2026
Merged

newpavlov merged 7 commits into
RustCrypto:masterfrom
TechnoPorg:push-klyklvnqmnzw

Conversation

@TechnoPorg

Copy link
Copy Markdown
Contributor

While setting up Miri for CI on a work project, I noticed that the tests which used padded AES encryption were failing due to a problem Miri detected in PaddedInOutBuf::into_out. Since tail_block contains a mutable borrow of out_ptr, creating a slice from out_ptr while tail_block is active is forbidden by Stacked Borrows.

The test added here passes with tree borrows on current master, but given that stacked borrows is stricter and less experimental, I'd prefer not to have to enable tree borrows, and so this change is required.

@newpavlov

newpavlov commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Thank you! I tweaked the code a bit to make it more straightforward.

I guess we also should improve test coverage for inout...

@newpavlov newpavlov changed the title Fix Miri Stacked Borrows violation in inout inout: fix Miri Stacked Borrows violation in PaddedInOutBuf Oct 14, 2026
@newpavlov
newpavlov merged commit b48d072 into RustCrypto:master Oct 14, 2026
12 checks passed
@TechnoPorg
TechnoPorg deleted the push-klyklvnqmnzw branch October 14, 2026 14:51
@newpavlov newpavlov mentioned this pull request Oct 14, 2026
newpavlov added a commit that referenced this pull request Oct 14, 2026
### Fixed
- List of safety pre-conditions in `InOutBufReserved::from_raw` docs
([#1502])
- Stacked Borrows violation in `PaddedInOutBuf` ([#1556])

[#1502]: #1502
[#1556]: #1556
newpavlov added a commit that referenced this pull request Oct 16, 2026
…ed_blocks` (#1560)

`InOutBufReserved` only guarantees that the output buffer is at least as
large as the input buffer. During the refactoring in #1556, the check
that ensured the output buffer had enough space for the tail block was
accidentally removed. Lack of the check allows to break the invariant
important for the unsafe code in `PaddedInOutBuf` methods.
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

Successfully merging this pull request may close these issues.

2 participants