-
Notifications
You must be signed in to change notification settings - Fork 201
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
Communication with devices (shared memory, ioctl) #353
Comments
Example with CUSE deviceSome more details on this sub-project. How CUSE worksThe Linux kernel exposes the Now another (client) application can open the The UMD program removes the Unfortunately, CUSE doesn't have the CI IssuesAs can be seen above, the CUSE UMD app must create a new device under This means that there is no possibility to start the CUSE UMD app inside a Docker container (i.e., use our current CI infrastructure). This app must be started with root privileges (to create There are two workarounds:
mmap issuesA large part of the proposed communication with devices is shared memory (allocated via device-backed Interestingly, classic FUSE supports This probably means that testing with a CUSE device is not an option for this use case. UPDATE: On the other hand, I couldn't find any other framework or existing device that would be simple to use and would support Misc referencesAbout FUSE and CUSE:
About creating VMs: |
Wouldn't it be enough to do
That will be a nightmare to maintain. Realistically we have to expect some bugs and submitting a new app version manually each time? Ugh.
I disagree it's complex, I've done it many times, it's super easy. The only hard thing here is SGX enabled QEMU, I don't know what's the state of that.
Yeah, isn't What about creating a normal kernel module and using a VM? There are 2 "hard" parts about it:
I can help you with this. |
Yes, I agree. With all the limititations of other approaches, it seems we should go for an obvious solution: a kernel module. Which leads to the usage of a VM to run it in. |
Can |
What is I took a quick look at I think these ioctls must be emulated by the following:
@mkow @boryspoplawski Does this sound right? |
@dimakuv We definitely don't want one address only, there are cases when you want to use multiple (not even mentioning multiple addresses on one interface). |
I added |
This describes the current state of my "communication with devices" project.
This project is in the context of the Linux-SGX PAL, though it should be applicable to other TEEs as well. This project is trivially implementable in the Linux PAL.
Legend:
✔️ Done (merged to master)
🚧 In progress (usually has a PR open)
⭐ Next (usually will be unlocked by current "in progress")
Rationale
Intel SGX is a CPU-only technology. This project proposes a generic way to enable communication with host devices from within the SGX (Gramine) enclave. There are two key interfaces in CPU–device communication: (1) the device-backed
mmap
system call and (2) theioctl
system call.Device-backed
mmap
system call allows to create memory regions that are shared between the SGX enclave and an arbitrary host device. Theioctl
system call provides a generic interface to send an arbitrary request to an arbitrary device, passing arbitrarily complex objects to the device’s memory and back to the CPU memory (RAM). Adding support for these two system calls – together with the standard and already-supportedopen
,read
,write
,close
system calls on devices – is sufficient to enable interactions between the trusted SGX enclave and the host device.The goal of this project is the enablement of communication between SGX enclaves and host devices. Protecting this communication from eavesdropping and other attacks is a non-goal of this project. Adding integrity checks, encryption, side-channel mitigations, etc. on top of the enabled insecure communication is the responsibility of the application.
This project was developed locally for about a year, with a particular focus on Direct Rendering Manager (DRM) workloads and interactions. Several interesting workloads were enabled and can run adequately. Now it's time to upstream this work (except for device-specific hacks). The branch with the latest snapshot is here: b12f340 (danger! some code there is terrible hacks).
TODO: Add a link to the whitepaper that contains explanations, diagrams and pseudo-code.UPDATE: The whitepaper: https://arxiv.org/abs/2203.01813Sub-projects
read()
/write()
(already implemented in Gramine)mmap()
-- done in [LibOS,PAL/Linux-SGX] Add shared untrusted memory support #827ioctl()
read
/write
/mmap
/ioctl
Below is the approximate split of these sub-projects into series of PRs.
Example with CUSE device
CI-Examples/cuse-device
open
,read
,write
,close
Shared untrusted memory via
mmap()
Introduce two non-overlapping address ranges: private range and shared range
mmap(MAP_PRIVATE)
, shared range is used formmap(MAP_SHARED)
g_pal_public_state.user_address
becomesprivate_range
, plus a newshared_range
0x0 - 1TB
and shared range is e.g.1TB - 2TB
1TB - 2TB
of untrusted memory (actually, a 1TB-sized region allocated with host'smmap()
to reserve this memory)sgx.insecure__enable_shared_range = "true"
shim_vma.c
,shim_mmap.c
, disallowingaddr = NULL
in PAL memory-alloc functionsAdd device-backed mmap:
mmap(..., <device-fd>, ...)
mmap()
,mprotect()
,munmap()
.mmap
callback to the "device" PAL handle.mmap
callback to the "device" PAL handleAugment CUSE device example with
mmap()
testsmmap(MAP_SHARED, <cuse-device-fd>)
mmap(MAP_PRIVATE, <cuse-device-fd>)
O_DIRECT
and then mmapping -- this is not supported by current in-Linux-kernel FUSE/CUSEDevice-specific I/O operations via
ioctl()
Add new PAL API:
DkDeviceIoControl(handle, cmd, arg)
shim_do_ioctl()
ioctl()
arg
, no-data-nesting)ocall_ioctl()
CUSE_UNRESTRICTED_IOCTL
andioctl(<dummy-cmd>, <flat-arg>)
Add first (simple) version of IOCTL struct definition to Linux-SGX PAL
sgx.ioctl_structs
andsgx.allowed_ioctls
onlyif
)ioctl(<dummy-cmd2>, <complex-arg>)
Add final version of IOCTL struct definition to Linux-SGX PAL
onlyif
)ioctl(<dummy-cmd3>, <onlyif-arg>)
Add caching of recently-used IOCTL structs to the final version of IOCTL struct definition to Linux-SGX PAL
Add documentation for
sgx.ioctl_structs
andsgx.allowed_ioctls
and the IOCTL struct definitions in the manifestThe text was updated successfully, but these errors were encountered: