Skip all MappedMemoryTest variants that rely on memory pages being
mapped for MF_WRITE|MF_EXEC when MPROTECT is enabled on NetBSD. W^X
protection causes all those mmap() calls to fail, causing the tests
to fail.
Details
Diff Detail
Event Timeline
unittests/Support/MemoryTest.cpp | ||
---|---|---|
18 | sys/param.h before sys/types.h according to the NetBSD style. Please decorate this include section with | |
38 | Using assert() might have a negative impact on functionality... because under some conditions this code might not be compiled at all and sysctl(3) won't be called. I propose to go for: if (sysctl(mib, 3, &paxflags, &len, NULL, 0) != 0) err(EXIT_FAILURE, "sysctl"); (and include <err.h>) | |
91 | I would drop : \ here. Some compilers will complain about redundant ;. | |
223 | Flags & Memory::MF_EXEC? |
unittests/Support/MemoryTest.cpp | ||
---|---|---|
86 | I would further refactor this into: // MPROTECT prevents W+X mmaps #define CHECK_UNSUPPORTED(f) \ do { \ if ((f & (Memory::MF_WRITE | Memory::MF_EXEC)) && \ IsMPROTECT()) \ return; \ } while (0) And use CHECK_UNSUPPORTED(Flags) or CHECK_UNSUPPORTED(Flags | Memory::MF_WRITE) for EnabledWrite. |
unittests/Support/MemoryTest.cpp | ||
---|---|---|
86 | Nah, that's too smart. Would go against KISS. |
unittests/Support/MemoryTest.cpp | ||
---|---|---|
86 | How about? #define CHECK_UNSUPPORTED_RAW(f) \ do { \ if ((f & (Memory::MF_WRITE | Memory::MF_EXEC)) && \ IsMPROTECT()) \ return; \ } while (0) and #define CHECK_UNSUPPORTED() CHECK_UNSUPPORTED_RAW(Flag) I would like to get rid of open-coding check in EnabledWrite. In EnableWrite it would be: CHECK_UNSUPPORTED_RAW(Flags | Memory::MF_WRITE). |
unittests/Support/MemoryTest.cpp | ||
---|---|---|
86 | Same problem — it says 'write' when it checks for 'exec'. We could get away by making an extra function with RHS specified via parameter with a default but I don't think it's worth the hassle. The purpose of the macro is to avoid repeating the most common version, not solve all the problems. Note that some functions have additional 'skip conditions' which we leave intact. |
unittests/Support/MemoryTest.cpp | ||
---|---|---|
86 | OK, I defer this to others in review. |
@hfinkel I would still like to drop W|X support from MemoryBlock for everybody, restricting this class to swapping between RW and RX in JIT code. For those who need RWX allocations it's more convenient to add a dedicated allocator (and NetBSD can support it). It's just a matter of time when new features on security hardened OSes will break and lose feature parity.
sys/param.h before sys/types.h according to the NetBSD style.
Please decorate this include section with
// clang-format off
and
// clang-format on