Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for CheriBSD #36

Closed
wants to merge 7 commits into from

Conversation

arichardson
Copy link
Contributor

I tried running the tests on my Morello board and noticed that most of them were failing. This patch series makes epoll-shim work correctly when running on CheriBSD (a fork of FreeBSD that adds support for CHERI-enabled architectures such as CHERI-RISC-V and Arm Morello).

With this patch series all but two tests pass for me and the last remaining failures will go away once CTSRD-CHERI/cheribsd#1424 has been fixed.

arichardson added a commit to CTSRD-CHERI/cheribuild that referenced this pull request Jun 19, 2022
The current version of epoll-shim does not work as a purecap library.
Use my fork until jiixyj/epoll-shim#36 has
been merged.
@jiixyj
Copy link
Owner

jiixyj commented Jun 19, 2022

Thank you for this! Those changes look reasonable to me at a first glance.

CheriBSD looks like a cool project! Is there a way for me to test it without a dev board? Is https://www.cl.cam.ac.uk/research/security/ctsrd/cheri/cheri-qemu.html the way to go?

@arichardson
Copy link
Contributor Author

Thank you for this! Those changes look reasonable to me at a first glance.

CheriBSD looks like a cool project! Is there a way for me to test it without a dev board? Is https://www.cl.cam.ac.uk/research/security/ctsrd/cheri/cheri-qemu.html the way to go?

Yes, QEMU is the best way to get started. If you clone cheribuild, running cheribuild.py run-morello-purecap -d will build all the dependencies and spawn a cheribsd instance in qemu (might take a while since you have to build LLVM and FreeBSD).

@arichardson
Copy link
Contributor Author

And there is of course a target to build epoll-shim as well, cheribuild.py epoll-shim-morello-purecap -d. However, due to microatf not being particularly friendly to cross-compiling, the easiest way to build the tests right now is if you have real hardware. Qemu probably works, but running clang inside qemu is pretty slow...

@arichardson
Copy link
Contributor Author

Friendly ping :)

@arichardson
Copy link
Contributor Author

ping?

@arichardson
Copy link
Contributor Author

Sorry to ping again, but would it be possible to merge this?

@arichardson
Copy link
Contributor Author

ping?

@arichardson
Copy link
Contributor Author

rebased on latest master, @jiixyj any chance this could be merged?

@arichardson
Copy link
Contributor Author

ping?

@arichardson
Copy link
Contributor Author

ping? It would be nice if we could drop the local patch from CheriBSD ports

@arichardson
Copy link
Contributor Author

@jiixyj Any chance this could be merged?

@jiixyj
Copy link
Owner

jiixyj commented Feb 5, 2023

Thanks for your patience -- I haven't forgotten about this! Some thoughts:

  • Are the POLLRDHUP changes essential? I'd like to fix this separately, if possible (see also Add support for FreeBSD's POLLRDHUP #33).
  • Duplicating that much fcntl logic doesn't bode well for maintenance... It would be much nicer if there was an "official" way to interpose fnctl.

When running the tests on a CheriBSD system on Arm Morello, pointers are
16 bytes, so the implicit size of 8192 bytes is not large enough to hold
all of struct atf_tc_impl_s_ and running the tests fails with a bounds
violation. To fix this issue, this commit explicitly sizes the array
instead of relying on the alignment and adds a static assertion to the
source file to ensure this invariant holds. I've also reordered
struct atf_tc_impl_s_ to avoid padding on CHERI systems.
…ents

`fcntl()` abuses C variadic arguments to implement optional parameters.
We want to forward this argument to the real `fcntl()` call, but doing
so is non-portable. On most architectures, we can just read an
`intptr_t`/`void*` and this will give us a (semi-)valid result even if
no argument/an int was passed instead since `va_arg()` will generally
read the next argument register or arbitrary data from the stack.

On CHERI-enabled architectures, variadic arguments are tightly
bounded, which means that reading a `void*` if an `int` was passed will
result in a runtime trap. This commit adds a switch ensures that we read
the correct number of bytes from the variadic arguments.
This ugly workaround would not be needed if a vfcntl() call taking
a va_list existed, or if fcntl just took an intptr_t argument.

This reduces the number of test failures on CheriBSD Morello from 210
to 8.
Some systems such as 64-bit CHERI-RISC-V or Arm Morello have 128-bit
pointers, so for them the sizeof(event) assertion needs to be updated.
This avoids a warning when building for CheriBSD (Morello purecap).
Trying to run the test executables during the build to get the list of
test cases causes my cross-compilation to fail. Skip adding the test cases
to CTest in that case (but still build them we can run them manually).
Due to a bug in CheriBSD, errno was set non-zero when starting this test,
but without these checks the test confusingly failed in the later check
which made me think something was wrong in timerfd_create. Check errno on
startup to make this more obvious.

See CTSRD-CHERI/cheribsd#1424
@arichardson
Copy link
Contributor Author

Sorry for the delay - I've rebased the changes. Unfortunately there is currently no way to interpose fcntl more easily...

@arichardson
Copy link
Contributor Author

No longer the most recent version, see #55 as well as #54 #53 #52 #51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants