Skip to content

Use memfd for hybrid QR code#179

Open
iinuwa wants to merge 2 commits into
mainfrom
hybrid-qr-code-memfd
Open

Use memfd for hybrid QR code#179
iinuwa wants to merge 2 commits into
mainfrom
hybrid-qr-code-memfd

Conversation

@iinuwa

@iinuwa iinuwa commented Jun 22, 2026

Copy link
Copy Markdown
Member

Pass hybrid secret establishment key over memfd_secret. Uses unwraps for now.

@iinuwa iinuwa force-pushed the hybrid-qr-code-memfd branch from d14b650 to 8c4dfc5 Compare June 22, 2026 04:52

@AlfioEmanueleFresta AlfioEmanueleFresta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaks fd. Could you wrap fd in OwnedFd::from_raw_fd early on, so it's safe to drop at any point?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can still use owned_fd.as_raw_fd() where you need it.

}

let ptr = unsafe {
let ptr = mmap(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Ideally wrap in a struct with Drop so we can add more early exit branches safely here

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