Skip to content

Why does teeos panic during exit? #162847

Open

Description

@maxdexh

I was reading the platform sources for the runtime and I found this peculiar sys::cleanup implementation on teeos (aarch64-unknown-teeos):

pub unsafe fn cleanup() {
unimplemented!()
// We do NOT have stack overflow handler, because TEE OS will kill TA when it happens.
// So cleanup is commented
// stack_overflow::cleanup();
}

This function is always invoked after main. The unsupported.rs implementation is to just do nothing, but this is panicking instead. Even if it is somehow intentional, an rtabort call would surely be much more appropriate in this context, given that unimplemented involves a call to the global allocator and panic hook.

It just looks wrong. Am I missing something?

@rustbot label T-libs O-teeos

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    O-teeosTarget: Arm's secure enclave that code isn't supposed to be able to jailbreak
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    on Sep 16, 2026
  2. RalfJung commented on Sep 16, 2026

    @RalfJung
    Member
  3. bjorn3 commented on Sep 16, 2026

    @bjorn3
    Member

    The comment above that says that Teeos uses dylibs rather than executables for "trusted applications", so cleanup() should in fact be unreachable. Using unreachable!() in init and cleanup would make sense in that case.

  4. maxdexh commented on Sep 16, 2026

    @maxdexh
    MemberAuthor

    Interesting. However, the function is also called in std::process::exit (although IIRC that can panic anyway on multiple platforms). So it is reachable. Edit: nvm, it panics before that. Edit: nvm my nvm, cleanup is called first

    In any case, this should not panic IMO.

  5. maxdexh commented on Sep 16, 2026

    @maxdexh
    MemberAuthor

    And teeos is apparently one of these ^^

    pub fn exit(code: i32) -> ! {
    cfg_select! {
    target_os = "hermit" => unsafe { hermit_abi::exit(code) },
    target_os = "linux" => unsafe {
    unique_thread_exit();
    libc::exit(code)
    },
    target_os = "motor" => moto_rt::process::exit(code),
    all(target_vendor = "fortanix", target_env = "sgx") => {
    crate::sys::pal::abi::exit_with_code(code as _)
    }
    target_os = "solid_asp3" => {
    rtabort!("exit({}) called", code)
    }
    target_os = "teeos" => {
    let _ = code;
    panic!("TA should not call `exit`")
    }

    IMO, an unconditional panic for std::process::exit is also inappropriate and should be replaced with rtabort.

  6. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-teeosTarget: Arm's secure enclave that code isn't supposed to be able to jailbreakT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions