Skip to content

Conversation

devnexen
Copy link
Member

Aim is to discard an address content to appear in a core dump with
systems supporting (Linux/FreeBSD for now), with a concealed usage
in the openssl ext for now.

Aim is to discard an address content to appear in a core dump with
systems supporting (Linux/FreeBSD for now), with a concealed usage
 in the openssl ext for now.
static zend_always_inline void zend_mm_nodump(void* ptr, size_t size)
{
#if defined(MADV_DONTDUMP)
(void)madvise(ptr, size, MADV_DONTDUMP);
Copy link
Member

Choose a reason for hiding this comment

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

From https://linux.die.net/man/2/madvise:

MADV_DONTDUMP (since Linux 3.4)
Exclude from a core dump those pages in the range specified by addr and length. This is useful in applications that have large areas of memory that are known not to be useful in a core dump.

And https://stackoverflow.com/a/46663007/1320374:

You can't and even if you could do it in certain cases with certain flags (and the flags you're trying to use here should be relatively harmless), you shouldn't. madvise operates on memory from lower level allocations than malloc gives you and messing with the memory from malloc will likely break malloc.

If you want some block of memory that you can call madvise on, you should obtain it using mmap.

So, for Linux, the memory passed to madvise should be page aligned and probably provided by mmap. I'm not sure if this is different on FreeBSD.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes will try to think of something else.

@devnexen devnexen closed this Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants