CTSRD-CHERI / cheribsd

FreeBSD adapted for CHERI-RISC-V and Arm Morello.
http://cheribsd.org
Other
161 stars 59 forks source link

mmap() can't be called via (__)syscall #2034

Open arichardson opened 6 months ago

arichardson commented 6 months ago

This is used e.g. by the sanitizer runtimes, but since unistd.h declares syscall/__syscall with an integer return value it's not possible to actually call mmap() successfully:

https://github.com/CTSRD-CHERI/cheribsd/blob/698d1636dd1fe2322e5bc7029e415928c80b76b1/include/unistd.h#L582-L583

Should these be changed to intptr_t for purecap?

brooksdavis commented 6 months ago

I suspect we should leave syscall alone (it can't be used for mmap except by accident), but likely __syscall should be int64ptr_t.

jrtc27 commented 6 months ago

Using it for mmap has two problems:

  1. off_t is 64-bit, so on a 32-bit system you need to use __syscall so the arguments are aligned correctly
  2. Pointers get truncated on a 64-bit system even absent CHERI

There's also shmat which suffers from 2 but not 1.