mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2025-11-23 05:00:28 -05:00
Merge 96836f463b into a000fd4b5e
This commit is contained in:
commit
622b2fbb4a
3 changed files with 24 additions and 0 deletions
18
memory.c
18
memory.c
|
|
@ -1,6 +1,8 @@
|
|||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#ifdef LABEL_MEMORY
|
||||
#include <sys/prctl.h>
|
||||
|
|
@ -91,6 +93,22 @@ bool memory_protect_rw_metadata(void *ptr, size_t size) {
|
|||
return memory_protect_prot(ptr, size, PROT_READ|PROT_WRITE, get_metadata_key());
|
||||
}
|
||||
|
||||
COLD bool memory_protect_seal(void *ptr, size_t size) {
|
||||
#if defined(__linux__) && defined(__NR_mseal)
|
||||
/* supported since Linux 6.10 */
|
||||
int ret = syscall(__NR_mseal, ptr, size, 0);
|
||||
if (ret == 0)
|
||||
return false;
|
||||
if (unlikely(errno == ENOMEM))
|
||||
return true;
|
||||
if (errno == ENOSYS)
|
||||
return memory_protect_ro(ptr, size);
|
||||
fatal_error("non-ENOMEM and non-ENOSYS mseal failure");
|
||||
#else
|
||||
return memory_protect_ro(ptr, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_COMPATIBLE_MREMAP
|
||||
bool memory_remap(void *old, size_t old_size, size_t new_size) {
|
||||
void *ptr = mremap(old, old_size, new_size, 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue