{"id":"CVE-2021-45695","aliases":["CVE-2021-45695","GHSA-2gxj-qrp2-53jv","GHSA-8mv5-7x95-7wcf","RUSTSEC-2021-0095"],"related":[],"kind":"vulnerability","state":"published","title":"Incorrect reliance on Trait memory layout in mopa","summary":"An issue was discovered in the mopa crate through 2021-06-01 for Rust. It incorrectly relies on Trait memory layout, possibly leading to future occurrences of arbitrary code execution or ASLR bypass.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"An issue was discovered in the mopa crate through 2021-06-01 for Rust. It incorrectly relies on Trait memory layout, possibly leading to future occurrences of arbitrary code execution or ASLR bypass.","source":"cvelist"},{"lang":"en","text":"The mopa crate redefines the deprecated TraitObject struct from core::raw. This is done to then transmute a reference to a trait object (&dyn Trait for any trait Trait) into this struct and retrieve the data field for the purpose of downcasting. This is used to implement downcast_ref_unchecked(), in terms of which downcast_ref() is also implemented. Same goes for mutable reference downcasting and Box downcasting.\n\nThe Rust compiler explicitly reserves the right to change the memory layout of &dyn Trait for any trait Trait. The worst case scenario is that it swaps data and vtable, making an executable location breach and compromisation of ASLR possible, since reads from data would read vtable instead. Likewise, arbitrary code execution is also theoretically possible if reads of vtable generated by the compiler read data instead.","format":"markdown","source":"ghsa"},{"lang":"en","text":"The `mopa` crate redefines the deprecated `TraitObject` struct from `core::raw` like so:\n```rust\n#[repr(C)]\n#[derive(Copy, Clone)]\n#[doc(hidden)]\npub struct TraitObject {\n    pub data: *mut (),\n    pub vtable: *mut (),\n}\n```\nThis is done to then transmute a reference to a trait object (`&dyn Trait` for any trait `Trait`) into this struct and retrieve the `data` field for the purpose of downcasting. This is used to implement `downcast_ref_unchecked()`, in terms of which `downcast_ref()` is also implemented. Same goes for mutable reference downcasting and `Box` downcasting.\n\nThe Rust compiler explicitly reserves the right to change the memory layout of `&dyn Trait` for any trait `Trait`. The worst case scenario is that it swaps `data` and `vtable`, making an executable location breach and compromisation of ASLR possible, since reads from `data` would read `vtable` instead. Likewise, arbitrary code execution is also theoretically possible if reads of `vtable` generated by the compiler read `data` instead.\n\nWhile, as of Rust 1.52, this unsound assumption still holds true, updating the compiler may silently create UB in a crate which previously compiled and run without issues, compromising the security of builds which are believed to be reproducible.\n\nA potential strategy to resolve this has already been suggested in an issue on the GitHub repository of the crate.","format":"markdown","source":"ghsa"},{"lang":"es","text":"Se ha detectado un problema en la crate mopa versiones hasta 01-06-2021 para Rust. Se basa incorrectamente en la disposición de la memoria de Trait, conllevando posiblemente a futuras ocurrencias de ejecución de código arbitrario o omisión de ASLR","source":"nvd"}],"published":"2021-06-01T12:00:00.000Z","modified":"2026-06-17T04:13:57.867Z","severity":{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","score":9.8,"rating":"CRITICAL"},"severities":[{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","score":9.8,"rating":"CRITICAL"},{"scorer":"GitHub","scheme":"rating","rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","score":9.8,"rating":"CRITICAL"},{"scorer":"NVD","scheme":"CVSS:2.0","vector":"AV:N/AC:L/Au:N/C:P/I:P/A:P","score":7.5,"rating":"HIGH"}],"cwes":[],"affected":[{"ranges":[{"version":"n/a","status":"affected"}],"source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","lastAffected":"0.2.2"}],"ecosystem":"crates.io","package":"mopa","purl":"pkg:cargo/mopa","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","lastAffected":"0.2.2"}],"ecosystem":"crates.io","package":"mopa","purl":"pkg:cargo/mopa","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0.0.0-0","status":"affected"}],"ecosystem":"crates.io","package":"mopa","purl":"pkg:cargo/mopa","source":"rustsec"},{"ranges":[{"status":"affected","lastAffected":"0.2.2"}],"vendor":"mopa_project","product":"mopa","cpe":"cpe:2.3:a:mopa_project:mopa:*:*:*:*:*:rust:*:*","source":"nvd"}],"references":[{"url":"https://rustsec.org/advisories/RUSTSEC-2021-0095.html","tags":["advisory","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","rustsec","nvd"]},{"url":"https://raw.githubusercontent.com/rustsec/advisory-db/main/crates/mopa/RUSTSEC-2021-0095.md","tags":["third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2021-45695","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/chris-morgan/mopa/issues/13","tags":["report","web"],"sources":["ghsa","rustsec"]},{"url":"https://github.com/chris-morgan/mopa","tags":["package"],"sources":["ghsa"]},{"url":"https://crates.io/crates/mopa","tags":["package"],"sources":["rustsec"]}],"credits":[],"assigner":"mitre","sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2021-45695","url":"https://www.cve.org/CVERecord?id=CVE-2021-45695","licence":"CVE Terms of Use","modified":"2024-08-04T04:47:02.088Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-2gxj-qrp2-53jv","url":"https://github.com/advisories/GHSA-2gxj-qrp2-53jv","licence":"CC-BY-4.0","modified":"2023-11-08T04:07:22.377Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-8mv5-7x95-7wcf","url":"https://github.com/advisories/GHSA-8mv5-7x95-7wcf","licence":"CC-BY-4.0","modified":"2023-11-08T04:07:22.377Z"},{"source":"rustsec","name":"RustSec Advisory Database","id":"RUSTSEC-2021-0095","url":"https://rustsec.org/advisories/RUSTSEC-2021-0095.html","licence":"CC0-1.0","modified":"2023-11-08T04:07:22.377Z"},{"source":"nvd","name":"NVD","id":"CVE-2021-45695","url":"https://nvd.nist.gov/vuln/detail/CVE-2021-45695","licence":"Public domain","modified":"2026-06-17T04:13:57.867Z"}],"updatedAt":"2026-11-25T22:58:06.265Z","epss":{"score":0.01701,"percentile":0.77909,"date":"2026-12-01T12:00:22.000Z"}}