-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Properly handle mmap calls without any protection mask: #9
Conversation
Newly created heap (alloc_new_heap) is created by glibc without any protection flags and they are adjusted by `mprotect` once the `mmap` succeeds: https://github.com/bminor/glibc/blob/master/malloc/arena.c#L404-L441 Fixes: fasterthanlime#8
// and they are adjusted by `mprotect` once the `mmap` succeeds: | ||
// https://github.com/bminor/glibc/blob/master/malloc/arena.c#L404-L441 | ||
// && prot_flags.contains(ProtFlags::PROT_READ | ProtFlags::PROT_WRITE) | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So my problem with the trivial fix here is that I feel like it'll over-track.
What I'd like instead is for mevi to keep track of these, but not as "allocated memory", just as something to keep an eye on, and when it is mprotect'd, then it should become "allocated memory". Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I'm not in favor of keeping track of separate memory ranges w/o a protection set as we would need to properly handle munmap
and mremap
as well.
To be honest, the Mevi tool focuses mainly on RSS memory usage and the Linux kernel should protect us, because nobody should cause a page fault (and allocation) for a range without PROT_READ
or PROT_WRITE
. An exception might be a mmap
without a protection flag with MAP_POPULATE
set. That would be correctly covered right now and handled by Mevi.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as we would need to properly handle
munmap
andmremap
as well.
Mevi does handle these properly though! Or do you mean there would need to be special handling re: ranges with no protection set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or do you mean there would need to be special handling re: ranges with no protection set?
Yes, I mean the special handling of these ranges.
For what it is worth, I made an experimental branch where I split the MemState
into 2 components:
https://github.com/marxin/mevi/tree/track-mapping-flags
pub struct MemState {
pub mapping: MemMapping,
pub flags: MemProtFlags,
}
pub enum MemMapping {
Resident,
NotResident,
Untracked,
}
pub struct MemProtFlags {
pub read: bool,
pub write: bool,
}
and the branch tries to properly manage the flags (MemProtFlags
). I've included mprotect
syscall and the information is only visible in the front-end if you hover over a range.
What do you think about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed many mprotect
calls for my https://github.com/marxin/debuginfod-rs test-case, where most of these are triggered for a single page (4 KiB). That being said, it might be a performance bottleneck.
Newly created heap (alloc_new_heap) is created by glibc without any protection flags and they are adjusted by
mprotect
once themmap
succeeds: https://github.com/bminor/glibc/blob/master/malloc/arena.c#L404-L441Fixes: #8