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

Cannot increase untrusted memory size in hello-native example - kernel fault #480

Open
dzourn opened this issue Dec 13, 2024 · 0 comments
Open

Comments

@dzourn
Copy link

dzourn commented Dec 13, 2024

Describe the bug
Setting the params.setUntrustedSize(48 * 1024 * 1024) and including the malloc.h header I am presented with the error below. My CMakeLists.txt is almost also identical to the attestor.ke example which successfully manages to set the size.

My end goal is to allocate (malloc) a buffer of ~5mb inside the enclave.

Build Failure
CMakeLists.txt:

[...]

# eapp
add_executable(${eapp_bin} ${eapp_src})
target_link_libraries(${eapp_bin} ${KEYSTONE_LIB_EAPP} ${KEYSTONE_LIB_EDGE})

target_include_directories(${eapp_bin}
  PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc
  PUBLIC ${KEYSTONE_SDK_DIR}/include/app
  PUBLIC ${KEYSTONE_SDK_DIR}/include/edge)

set_target_properties(${eapp_bin} PROPERTIES LINK_FLAGS "-nostdlib -static -T ${CMAKE_CURRENT_SOURCE_DIR}/eapp/app.lds")

# host

add_executable(${host_bin} ${host_src})
target_link_libraries(${host_bin} ${KEYSTONE_LIB_HOST} ${KEYSTONE_LIB_EDGE})
# add -std=c++11 flag
set_target_properties(${host_bin}
  PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO
)

target_include_directories(${host_bin}
  PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/inc
  PUBLIC ${KEYSTONE_SDK_DIR}/include/common
  PUBLIC ${KEYSTONE_SDK_DIR}/include/host
  PUBLIC ${KEYSTONE_SDK_DIR}/include/edge
  PUBLIC ${KEYSTONE_SDK_DIR}/include/verifier)

# add target for Eyrie runtime (see keystone.cmake)

set(eyrie_files_to_copy .options_log eyrie-rt loader.bin)
add_eyrie_runtime(${eapp_bin}-eyrie
  ${eyrie_plugins}
  ${eyrie_files_to_copy})

# add target for packaging (see keystone.cmake)

add_keystone_package(${eapp_bin}-package
  ${package_name}
  ${package_script}
  ${eyrie_files_to_copy} ${eapp_bin} ${host_bin})

add_dependencies(${eapp_bin}-package ${eapp_bin}-eyrie)

# add package to the top-level target
add_dependencies(examples ${eapp_bin}-package)

Screenshots or Error Log

Verifying archive integrity... MD5 checksums are OK. All good.
Uncompressing Keystone Enclave Package
[   49.833962] ------------[ cut here ]------------
[   49.834410] WARNING: CPU: 3 PID: 202 at mm/page_alloc.c:5535 __alloc_pages+0x1e8/0xad2
[   49.835859] Modules linked in: keystone_driver(O)
[   49.837133] CPU: 3 PID: 202 Comm: rewire-runner Tainted: G           O       6.1.32 #1
[   49.838248] Hardware name: riscv-virtio,qemu (DT)
[   49.839036] epc : __alloc_pages+0x1e8/0xad2
[   49.839611]  ra : __get_free_pages+0x12/0x54
[   49.840139] epc : ffffffff80122484 ra : ffffffff8012324e sp : ff200000108c3a80
[   49.840893]  gp : ffffffff812ea838 tp : ff60000080ffeb80 t0 : 0000000000000040
[   49.841664]  t1 : 0000000000000000 t2 : 00aaaaaaab874bc8 s0 : ff200000108c3be0
[   49.842446]  s1 : ff60000080e8c400 a0 : 0000000000100cc0 a1 : 000000000000000e
[   49.843153]  a2 : 0000000000000000 a3 : 0000000000000000 a4 : 0000000000000001
[   49.843957]  a5 : ffffffff812d40f1 a6 : ff60000080442910 a7 : ff60000080442938
[   49.844792]  s2 : 0000000000000000 s3 : 0000000000004000 s4 : 000000000000000e
[   49.845907]  s5 : 00ffffffd7870900 s6 : 00ffffffd7870ee4 s7 : 00ffffffd78709b0
[   49.847263]  s8 : 00ffffffd78709e0 s9 : 00aaaaaacce2c0e0 s10: 00aaaaaacce2be60
[   49.848289]  s11: 0000000000000000 t3 : 0000000000000002 t4 : 0000000000000402
[   49.849089]  t5 : ffffffff01352090 t6 : ffffffff013520b0
[   49.849694] status: 0000000200000120 badaddr: 0000000000000000 cause: 0000000000000003
[   49.850836] [<ffffffff80122484>] __alloc_pages+0x1e8/0xad2
[   49.851718] [<ffffffff8012324e>] __get_free_pages+0x12/0x54
[   49.852630] [<ffffffff0135035e>] utm_init+0x82/0xd4 [keystone_driver]
[   49.853941] [<ffffffff013505b2>] utm_init_ioctl+0x4c/0xc4 [keystone_driver]
[   49.854732] [<ffffffff0135080c>] keystone_ioctl+0x104/0x1d0 [keystone_driver]
[   49.855501] [<ffffffff80150a10>] sys_ioctl+0x76/0x88
[   49.856090] [<ffffffff80003412>] ret_from_syscall+0x0/0x2
[   49.856972] ---[ end trace 0000000000000000 ]---
[   49.858404] keystone_enclave: failed to allocate UTM (size = 16384 bytes)
[Keystone SDK] Enclave.cpp:176 : failed to init untrusted memory - ioctl() failed
[   49.862413] keystone_enclave: fatal: cannot destroy enclave: SBI failed with error code 100005
ioctl error: Invalid argument
[Keystone SDK] KeystoneDevice.cpp:108 : Unknown SBI error (100016) returned by run_enclave

[Keystone SDK] Enclave.cpp:247 : failed to run enclave - ioctl() failed
[   49.870996] keystone_enclave: fatal: cannot destroy enclave: SBI failed with error code 100005
ioctl error: Invalid argument
[   49.872701] keystone_enclave: fatal: cannot destroy enclave: SBI failed with error code 100005
ioctl error: Invalid argument
[   49.887428] keystone_enclave: fatal: cannot destroy enclave: SBI failed with error code 100005

Additional context
Run on QEMU - end goal is to run it on the VisionFive Starfive 2

Moreover when trying to malloc a large buffer [e.g. char* pp = malloc(4913432)] inside the enclave I get

Verifying archive integrity... MD5 checksums are OK. All good.
Uncompressing Keystone Enclave Package
[runtime] page fault at 0x10c8 on 0x0 (scause: 0xd)

Do you have any idea/insight?

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

No branches or pull requests

1 participant