Skip to content

Improve memfd-secret guard page allocation - #18

Open
prabhpreet wants to merge 7 commits into
quininer:masterfrom
rosenpass:memfd-secret-anon-guards
Open

Improve memfd-secret guard page allocation#18
prabhpreet wants to merge 7 commits into
quininer:masterfrom
rosenpass:memfd-secret-anon-guards

Conversation

@prabhpreet

Copy link
Copy Markdown
Contributor

Improve memfd-secret guard page allocation by using combination of mmap to map allocation area, and nest memfd-secret mapping and meta information with different permissions within the area

Ideated by @koraa

prabhpreet and others added 3 commits June 12, 2024 17:02
… page

Co-authored-by: Prabhpreet Dua <615318+prabhpreet@users.noreply.github.com>
Co-authored-by: Karolin Varner <karo@cupdev.net>
prabhpreet added a commit to rosenpass/rosenpass that referenced this pull request Jun 13, 2024
Improve memfd-secret guard page allocation by using combination of mmap to map allocation area, and nest memfd-secret mapping and meta information with different permissions within the area

Implemented in quininer/memsec#18 

Co-authored-by: Prabhpreet Dua <615318+prabhpreet@users.noreply.github.com>
Co-authored-by: Karolin Varner <karo@cupdev.net>
Comment thread src/alloc/allocext/linux.rs Outdated

let ptr = libc::mmap(
ptr::null_mut(),
if ptr.is_some() {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
if ptr.is_some() {
ptr.unwrap_or_else(ptr::null_mut)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you, changed

Comment thread src/alloc/allocext/linux.rs Outdated
let total_size = front_guard_size + unprotected_size + back_guard_size;

let base_ptr = libc::mmap(
null_mut(),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
null_mut(),
ptr::null_mut(),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you, changed

Comment thread src/alloc/allocext/linux.rs Outdated
pub unsafe fn alloc_memfd_secret(size: usize) -> Option<(NonNull<u8>, libc::c_int)> {
pub unsafe fn alloc_memfd_secret(
size: usize,
ptr: Option<*mut libc::c_void>,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It seems that no call is None?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That is just for added flexibility, under cases a user directly wants to use alloc_memfd_secret and doesn't want to set a specific address for the mapping

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is an internal function and no user will call it directly. we don't have to keep Option.

Comment thread src/alloc/allocext/linux.rs Outdated

#[inline]
pub unsafe fn alloc_memfd_secret(size: usize) -> Option<(NonNull<u8>, libc::c_int)> {
pub unsafe fn alloc_memfd_secret(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

maybe name change is needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed to alloc_memfd_secret_at_ptr

Comment thread src/alloc/allocext/linux.rs Outdated
pub unsafe fn alloc_memfd_secret(size: usize) -> Option<(NonNull<u8>, libc::c_int)> {
pub unsafe fn alloc_memfd_secret(
size: usize,
ptr: Option<*mut libc::c_void>,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is an internal function and no user will call it directly. we don't have to keep Option.

@prabhpreet

Copy link
Copy Markdown
Contributor Author

@quininer seems like the Github action is running forever. Is it possible to restart it?

@prabhpreet prabhpreet closed this Jun 14, 2024
@prabhpreet prabhpreet reopened this Jun 14, 2024
@prabhpreet

Copy link
Copy Markdown
Contributor Author

It looks like procspawn has some issue in the process spawned- I'll be able to attend to this only after next week

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