use-after-free in tracing
The implementation of the [Instrumented::into_inner] method in affected versions of this crate contains undefined behavior due to incorrect use of [std::mem::forget] The function creates *const pointers to self, calls [mem::forget(self)][std::mem::forget], and then moves values out of those pointers using [std::ptr::read].
```rust
// To manually destructure Instrumented without Drop, we
// move it into a ManuallyDrop and use pointers to its fields
let span: *const Span = &this.span;
let inner: *const ManuallyDrop<T> = &this.inner;
mem::forget(self);
// SAFETY: Those pointers are valid for reads, because Drop didn't
// run, and properly aligned, because Instrumented isn't
// #[repr(packed)].
let _span = unsafe { span.read() };
let inner = unsafe { inner.read() };
```
However, the [mem::forget documentation][std::mem::forget] states:
> Any resources the value manages, such as heap memory or a file handle, will
> linger forever in an unreachable state. **However, it does not guarantee that
> pointers to this memory will remain valid.**
This means that these pointers are no longer valid. This could result in a stack use-after-free if LLVM chooses to reuse self's stack slot for a rebinding after the call to [std::mem::forget].
This undefined behavior has not been observed to cause miscompilation as of Rust 1.73.0. However, any use of this method with the affected versions of tracing are unsound.
The flaw was corrected in commit [20a1762] ([PR #2765]) by replacing the use of [std::mem::forget] with std::mem::ManuallyDrop, ensuring that the stack slot is not reused and the pointers remain valid when they are read. The fix is
published in tracing [v0.1.40]. Affected versions have been yanked from crates.io.
Thanks to [Taylor Cramer] and [Manish Goregaokar] for finding and correcting
this issue!
[Instrumented::into_inner]:
https://docs.rs/tracing/latest/tracing/instrument/struct.Instrumented.html#method.into_inner
[std::mem::forget]: https://doc.rust-lang.org/std/mem/fn.forget.html
[std::ptr::read]:
https://doc.rust-lang.org/std/primitive.pointer.html#method.read-1
[20a1762]:
https://github.com/tokio-rs/tracing/commit/20a1762b3fd5f1fafead198fd18e469c68683721
[PR #2765]: https://github.com/tokio-rs/tracing/pull/2765
[v0.1.40]: https://crates.io/crates/tracing/0.1.40
[Taylor Cramer]: https://github.com/cramertj
[Manish Goregaokar]: https://github.com/manishearth
GHSA-8f24-6m29-wm2r is classified as CWE-416: Use After Free. Memory is used after being released, so its contents may already belong to something else.
GHSA-8f24-6m29-wm2r is recorded against 1 package.
Published on 17 January 2024 and last revised on 10 February 2024. No public exploit is currently recorded for this entry. Record sourced from OSV.
github.com (Web)
github.com (Web)
github.com (Package)
github.com (Web)
rustsec.org (Web)
tracing has other advisories on record. If you are patching this one, these are worth checking on the same host:
These advisories are the same class of weakness (CWE-416: Use After Free) in other software:
Details
Affected Packages
| Software | From version | Fixed in |
|---|---|---|
| tracing | — | — |
References
Similar Threats
Free Vulnerability Check
BotEraser helps you identify potentially vulnerable plugins and themes by checking your installation against GHSA-8f24-6m29-wm2r and other known CVE records.
Scan My Site Free →No credit card required · Results in minutes
ⓘ Data Notice: The information presented above has been compiled from publicly available internet sources. Boteraser aggregates this data solely for informational purposes and does not independently classify, evaluate, or endorse any findings about the vulnerabilities listed. The accuracy and completeness of this information is the sole responsibility of the original publishers. Boteraser and its operators accept no liability for any decisions made based on this data.
Stay up to date with the latest from Boteraser.
We use cookies to improve your experience on our site. By using our site, you consent to cookies.
Manage your cookie preferences below:
Essential cookies enable basic functions and are necessary for the proper function of the website.
CloudFlare provides web performance and security solutions, enhancing site speed and protecting against threats.
Service URL: developers.cloudflare.com (opens in a new window)
These cookies are needed for adding comments on this website.
These cookies are used for managing login functionality on this website.
Statistics cookies collect information anonymously. This information helps us understand how visitors use our website.
Google Analytics is a powerful tool that tracks and analyzes website traffic for informed marketing decisions.
Service URL: policies.google.com (opens in a new window)
You can find more information in our Cookie Policy and Privacy Policy.