os-wrappers-test.c: Correctly forward arguments to fcntl
authorAlex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Thu, 18 Mar 2021 10:45:50 +0000 (10:45 +0000)
committerSimon Ser <contact@emersion.fr>
Thu, 15 Apr 2021 07:34:53 +0000 (07:34 +0000)
commite88193492771f6d3c9f6d9d7b9b2b21b1a04e92d
tree07fb2ca42ea1cb0bd23e733c8bf5d15e58e56eaf
parente4659ffbf5ee32cb55a045bf63ae1e81c0c2938c
os-wrappers-test.c: Correctly forward arguments to fcntl

We can't just unconditionally read the optional arguments (and also read
it as a void* despite actually being an int).
While this happens to work on most architectures because the first few
variadic arguments are passed in registers, this is non-portable and
causes a crash on architectures that set bounds on variadic function
arguments (for example CHERI-enabled architectures). It could also cause
problems on big-endian architectures that pass variadic arguments on the
stack rather than in registers.

For CHERI-MIPS, reading sizeof(void*) causes a read of 16 bytes from the
bounded varargs capability. This always crashes since even calls with the
optional argument only have 4 bytes available.

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Reviewed-by: Simon Ser <contact@emersion.fr>
tests/os-wrappers-test.c