rust-lang / rust-lang/rust

`rtabort!` can panic on xous

Open
#161,091 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-global-allocator-reentry C-bug I-unsound needs-triage O-xous P-high T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

We rely on rtabort to print an error message without calling untrusted code. If it is able to panic, several parts of the standard library become unsound due to disallowed reentrance into the global allocator.

Note that rtabort calls the platform's panic_output via rtprintpanic:

https://github.com/rust-lang/rust/blob/059bf4a660ddea5bd8302ecdd4f7e40dd7a04313/library/std/src/rt.rs#L40-L60

One of the panic_output implementations is in xous.rs:

https://github.com/rust-lang/rust/blob/059bf4a660ddea5bd8302ecdd4f7e40dd7a04313/library/std/src/sys/stdio/xous.rs#L111-L124

This calls into code with a lot of unwrap, expect, etc. calls in it, where it is unclear if they are meant to catch logic bugs or real failures from the environment. One concrete example that is probably from the latter category is std::os::xous::services::log::log_server unwrapping the result from std::os::xous::ffi::connect.
Note that its call literally has a comment on it saying it is "likely to succeed". That's not enough if failure causes unsoundness!

This should arguably never be touching unwrap or expect, since in this context they are equivalent to unwrap_unchecked, except without safety comments.

@rustbot label T-libs I-unsound A-global-allocator-reentry O-xous

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in library/std/src/rt.rs at rtabort and rtprintpanic, then read library/std/src/sys/stdio/xous.rs at the panic_output implementation. Trace the unwrap and expect calls reached there, especially std::os::xous::services::log::log_server and its std::os::xous::ffi::connect call. Done means rtabort cannot panic when this platform output path encounters an environmental failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.