Re: [PATCH 0/6] Memory Mapping (VMA) protection using PKU - set 1

Dave Hansen
2023-05-17T15:32:14Z

On 5/17/23 08:21, Jeff Xu wrote:
>>> I’m not sure I follow the details, can you give an example of an asynchronous
>>> mechanism to do this? E.g. would this be the kernel writing to the memory in a
>>> syscall for example?
>> I was thinking of all of the IORING_OP_*'s that can write to memory or
>> aio(7).
> IORING is challenging from security perspectives, for now, it is
> disabled in ChromeOS. Though I'm not sure how aio is related ?

Let's say you're the attacking thread and you're the *only* attacking
thread. You have three things at your disposal:

1. A benign thread doing aio_read()
2. An arbitrary write primitive
3. You can send signals to yourself
4. You can calculate where your signal stack will be

You calculate the address of PKRU on the future signal stack. You then
leverage the otherwise benign aio_write() to write a 0 to that PKRU
location. Then, send a signal to yourself. The attacker's PKRU value
will be written to the stack. If you can time it right, the AIO will
complete while the signal handler is in progress and PKRU is on the
stack. On sigreturn, the kernel restores the aio_read()-placed,
attacker-provided PKRU value. Now the attacker has PKRU==0. It
effectively build a WRPKRU primitive out of those other pieces.