diff options
author | Micah Elizabeth Scott <beth@torproject.org> | 2023-08-25 10:31:33 -0700 |
---|---|---|
committer | Micah Elizabeth Scott <beth@torproject.org> | 2023-08-28 10:11:00 -0700 |
commit | 95e8ffa97e413c19c7257c9e6dc9511e98347b68 (patch) | |
tree | 7773b22b4e68586a3080781f03df020a06b7efdd /src | |
parent | ee4e9f7506d87be71fb85e0bce0a671f541ff059 (diff) | |
download | tor-95e8ffa97e413c19c7257c9e6dc9511e98347b68.tar.gz tor-95e8ffa97e413c19c7257c9e6dc9511e98347b68.zip |
hashx: Fix compiled hash function on NetBSD
NetBSD includes the idea of a 'maximum protection' per-region,
and an mprotect which exceeds the max protection will be denied.
If we explicitly ask for a maximum which includes execute permission, we
can successfully swap our code buffer's permissions between read-write
and read-execute when each hash program is compiled.
With this patch, the crypto/hashx tests pass on NetBSD 9.
This addresses bug #40844
Diffstat (limited to 'src')
-rw-r--r-- | src/ext/equix/hashx/src/virtual_memory.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/ext/equix/hashx/src/virtual_memory.c b/src/ext/equix/hashx/src/virtual_memory.c index a3a68f44b9..564325b641 100644 --- a/src/ext/equix/hashx/src/virtual_memory.c +++ b/src/ext/equix/hashx/src/virtual_memory.c @@ -18,6 +18,11 @@ #define PAGE_READWRITE (PROT_READ | PROT_WRITE) #define PAGE_EXECUTE_READ (PROT_READ | PROT_EXEC) #define PAGE_EXECUTE_READWRITE (PROT_READ | PROT_WRITE | PROT_EXEC) +#if defined(__NetBSD__) && defined(PROT_MPROTECT) +#define PAGE_MMAP_PROT (PAGE_READWRITE | PROT_MPROTECT(PROT_EXEC)) +#else +#define PAGE_MMAP_PROT PAGE_READWRITE +#endif #endif #ifdef HASHX_WIN @@ -57,7 +62,7 @@ void* hashx_vm_alloc(size_t bytes) { #ifdef HASHX_WIN mem = VirtualAlloc(NULL, bytes, MEM_COMMIT, PAGE_READWRITE); #else - mem = mmap(NULL, bytes, PAGE_READWRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + mem = mmap(NULL, bytes, PAGE_MMAP_PROT, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (mem == MAP_FAILED) return NULL; #endif |