Advisory: Miscompilation in cortex-m-rt 0.7.1 and 0.7.2 #469
adamgreig
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Advisory Notice:
cortex-m-rtSummary
Version 0.7.1 of the
cortex-m-rtcrate introduced a regression causing the stack to NOT be eight-byte aligned prior to callingmain(or any other specified entrypoint), violating the stack ABI of AAPCS32, the default ABI used by all Cortex-M targets. This regression is also present in version 0.7.2 of thecortex-m-rtcrate.This regression can cause certain compiler optimizations (which assume the eight-byte alignment) to produce incorrect behavior at runtime. This incorrect behavior has been observed in real-world applications.
It is advised that ALL users of
v0.7.1andv0.7.2of thecortex-m-rtcrate update to the latest version (v0.7.3), AS SOON AS POSSIBLE. Users ofv0.7.0and prior versions ofcortex-m-rtare not affected by this regression.It will be necessary to rebuild all affected firmware binaries, and flash or deploy the new firmware binaries to affected devices.
Users of
probe-runv0.3.6 and earlier will see a warning reported when stack unwinding goes past the main function, see here for details. This is due toprobe-runrelying on behavior ofcortex-m-rtthat has been changed to fix this issue. Unwinding and otherprobe-runfunctionality is unaffected apart from the new warning message.Technical details
Details regarding the requirements of AAPCS32 can be found at Arm's documentation site.
Details on the changes can be found in the cortex-m-rt#467 PR, with more discussion in cortex-m-rt#463.
The regression was introduced in this commit.
Potentially Affected Configurations
rustc, including stable and nightly releasesthumbv6m-none-eabithumbv7m-none-eabithumbv7em-none-eabithumbv7em-none-eabihfthumbv8m.base-none-eabithumbv8m.main-none-eabithumbv8m.main-none-eabihfcortex-m-rt:v0.7.1v0.7.2For miscompilation to occur, specific compiler optimisations must have taken place. It is not trivial to determine if they have, so if you have a potentially affected configuration you are strongly advised to upgrade to 0.7.3.
Any other configuration, including other CPU architectures (e.g. RISC-V, MSP430, AVR) and firmware projects not using the
cortex-m-rtcrate are NOT affected.Determining if you may be affected
Run the following command in your embedded project:
Affected users will see one of the following outputs:
If present, the
Cargo.lockfile may also be inspected to verify:grep -i --after=1 'name = "cortex-m-rt"' ./Cargo.lockAffected users will see one of the following outputs:
Applying the update
The
cortex-m-rtpackage can be updated using thecargo-updatecommand.cargo update -p cortex-m-rt Updating crates.io index Updating cortex-m-rt v0.7.2 -> v0.7.3You can also manually edit your
Cargo.tomlto apply this update:After updating, verify that version 0.7.3 (or later) of
cortex-m-rtcrate is now in use, using the procedure described in the "Determining if you are affected" section above.It will be necessary to rebuild all affected firmware binaries, and flash or deploy the new firmware binaries to affected devices.
Contact
If you have any questions regarding this notice, including how to check if you are affected, or how to apply the update, please start a discussion.
Credits
Thanks to @jamesmunns for writing this advisory and helping research the impact and solutions, @Dirbaio for developing the fix, @peter9477 for first discovering it, and everyone else on the Rust Embedded Matrix who helped investigate.
Beta Was this translation helpful? Give feedback.
All reactions