Use memfd for hybrid QR code#179
Open
iinuwa wants to merge 2 commits into
Open
Conversation
d14b650 to
8c4dfc5
Compare
AlfioEmanueleFresta
approved these changes
Jun 22, 2026
AlfioEmanueleFresta
left a comment
Member
There was a problem hiding this comment.
LGTM! Two comments.
|
|
||
| pub fn write_secret(mut secret: Vec<u8>, max_len: usize) -> Result<OwnedFd, std::io::Error> { | ||
| let bytes_len = if secret.len() <= max_len { | ||
| secret.len() as u8 |
Member
There was a problem hiding this comment.
max_len here is CTAP_HYBRID_QR_CODE_MAX_LEN (4k). Won't fit in u8.
usize?
Alternatively we could reduce CTAP_HYBRID_QR_CODE_MAX_LEN until PQ, I think we're comfortably below 255 right now.
| } | ||
| let fd = i32::try_from(ret).map_err(|_| std::io::Error::other("invalid file descriptor"))?; | ||
| if unsafe { ftruncate(fd, bytes_len as off_t) } == -1 { | ||
| return Err(std::io::Error::last_os_error()); |
Member
There was a problem hiding this comment.
Leaks fd. Could you wrap fd in OwnedFd::from_raw_fd early on, so it's safe to drop at any point?
Member
There was a problem hiding this comment.
You can still use owned_fd.as_raw_fd() where you need it.
| } | ||
|
|
||
| let ptr = unsafe { | ||
| let ptr = mmap( |
Member
There was a problem hiding this comment.
Nit: Ideally wrap in a struct with Drop so we can add more early exit branches safely here
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pass hybrid secret establishment key over memfd_secret. Uses unwraps for now.