Skip to contentSkip to conversation

mprotect PROT_SIGNAL

DISCUSSION Soni "They/Them" L. 2 participants 3 messages Jul 9, 2024 – Jul 16, 2024 ABI/API

lore
Share & tools
lore
#0 lore raw

we'd like an mprotect PROT_SIGNAL flag for a compiler we're making

PROT_SIGNAL - marks the pages as unmapped while running signal handlers

this would be very useful, do you think you could provide it?

(not much more to say about it, it's supposed to do what it says on the tin, we want to unmap pages in signal handlers so as to catch bugs without causing memory corruption.)

#1 lore raw

* Soni L.:

Quoted 9 lines

we'd like an mprotect PROT_SIGNAL flag for a compiler we're making

PROT_SIGNAL - marks the pages as unmapped while running signal handlers

this would be very useful, do you think you could provide it?

(not much more to say about it, it's supposed to do what it says on the tin, we want to unmap pages in signal handlers so as to catch bugs without causing memory corruption.)

The challenge is going to be to detect abnormal exit from the signal handler.

You can already get some of this behavior to today with memory protection keys, on x86-64 at least. (I consider this a glitch in the implementation, it makes it less useful.) Access is revoked automatically when the hander is invoked. However, access is not restored if you jump out of the handler using longjmp or by throwing an exception.

Thanks,
Florian

#2 lore raw
Quoted 15 lines · Florian Weimer

* Soni L.:

Quoted 9 lines

we'd like an mprotect PROT_SIGNAL flag for a compiler we're making

PROT_SIGNAL - marks the pages as unmapped while running signal handlers

this would be very useful, do you think you could provide it?

(not much more to say about it, it's supposed to do what it says on the tin, we want to unmap pages in signal handlers so as to catch bugs without causing memory corruption.)

The challenge is going to be to detect abnormal exit from the signal handler.

Quoted 6 lines

You can already get some of this behavior to today with memory protection keys, on x86-64 at least. (I consider this a glitch in the implementation, it makes it less useful.) Access is revoked automatically when the hander is invoked. However, access is not restored if you jump out of the handler using longjmp or by throwing an exception.

As it should be - POSIX specifies that longjmping out of a handler remains in handler context, so you still can't call signal-unsafe functions.

Presumably, an API to manually map them back in would be necessary in the case of e.g. the JVM, which uses signal handlers for hardware-accelerated null checks.

Quoted 3 lines

Thanks,
Florian