Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.
Sources: National Vulnerability Database, CISA KEV, Exploit-DB
CVE-2024-31852 Overview
CVE-2024-31852 affects LLVM versions prior to 18.1.3. The compiler's ARM backend generates code where the Link Register (LR) can be overwritten without the original value being saved to the stack. This miscompilation introduces a flow-of-control error that may expose a Jump-Oriented Programming (JOP) gadget in compiled binaries. The issue was reproduced with Clang targeting ARM.
The LLVM project acknowledged the report but noted that functions affected by the miscompile are likely to crash on most valid inputs. Routine testing should surface the defect before shipping. The vulnerability resides in the compiler, so impact depends on which downstream binaries were produced with the affected toolchain.
Critical Impact
ARM binaries produced by vulnerable LLVM versions may contain an exploitable control-flow error enabling a JOP gadget, potentially leading to availability loss or redirection of execution.
Affected Products
- LLVM versions prior to 18.1.3
- Clang compiler builds based on affected LLVM releases
- ARM target binaries produced by the affected LLVM ARM backend
Discovery Timeline
- 2024-04-05 - CVE-2024-31852 published to the National Vulnerability Database (NVD)
- 2026-06-17 - Last updated in NVD database
Technical Details for CVE-2024-31852
Vulnerability Analysis
The defect lives in LLVM's ARM frame lowering logic, specifically in how the IsRestored flag on the Link Register is computed. On ARM, the LR holds the return address for the current function. When the ARM backend incorrectly marks LR as restored, it omits the required spill or reload around a call site that clobbers LR.
The generated prologue and epilogue no longer preserve the caller's return address across inner calls. When the function reaches a return instruction, the processor branches to whatever value remains in LR. In the worst case, that value corresponds to an attacker-influenced address or an unintended code location, producing a Jump-Oriented Programming gadget.
Most functions exhibiting the miscompile crash on common inputs because the corrupted LR points nowhere valid. The exploitable window requires a path where control flow reaches the broken return with a value that resolves to executable memory.
Root Cause
The ARMFrameLowering pass set the IsRestored state for LR based on an incomplete view of the function's return instructions. If any return path left LR unrestored, the backend still treated it as safe and skipped the save or restore sequence. The patch introduces a dedicated helper, updateLRRestored, that recomputes the flag across every return in the function.
Attack Vector
Exploitation requires the attacker to influence inputs reaching a function compiled with the broken LLVM 18.x pre-release output. The attack vector is Network with High complexity, meaning that triggering the control-flow error demands precise conditions in the compiled program. There is no confidentiality or integrity impact, but a successful trigger impacts availability through crashes or control-flow redirection.
// Patch in llvm/lib/Target/ARM/ARMFrameLowering.cpp
// Refactors LR restoration tracking into a dedicated pass over all returns.
AFI->setLRIsSpilled(SavedRegs.test(ARM::LR));
}
-void ARMFrameLowering::processFunctionBeforeFrameFinalized(
- MachineFunction &MF, RegScavenger *RS) const {
- TargetFrameLowering::processFunctionBeforeFrameFinalized(MF, RS);
-
+void ARMFrameLowering::updateLRRestored(MachineFunction &MF) {
MachineFrameInfo &MFI = MF.getFrameInfo();
if (!MFI.isCalleeSavedInfoValid())
return;
// Source: https://github.com/llvmbot/llvm-project/commit/0e16af8e4cf3a66ad5d078d52744ae2776f9c4b2
// Header declaration added in llvm/lib/Target/ARM/ARMFrameLowering.h
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
RegScavenger *RS) const override;
+ /// Update the IsRestored flag on LR if it is spilled, based on the return
+ /// instructions.
+ static void updateLRRestored(MachineFunction &MF);
+
void processFunctionBeforeFrameFinalized(
MachineFunction &MF, RegScavenger *RS = nullptr) const override;
// Source: https://github.com/llvmbot/llvm-project/commit/0e16af8e4cf3a66ad5d078d52744ae2776f9c4b2
Detection Methods for CVE-2024-31852
Indicators of Compromise
- Unexpected crashes in ARM binaries at function return boundaries, often manifesting as segmentation faults with corrupted PC values after a BX LR or POP {..., PC} instruction.
- Binary artifacts whose build metadata records Clang or LLVM versions below 18.1.3 targeting ARM.
- Runtime traces where the Link Register content does not match any valid return address in the calling function.
Detection Strategies
- Inventory your toolchains and build systems. Flag any production ARM binary produced with LLVM or Clang versions earlier than 18.1.3.
- Run differential fuzzing against ARM builds compiled with the vulnerable release and a patched release. Divergent crashes or control-flow traces indicate affected code paths.
- Use binary diffing on prologue and epilogue sequences in ARM object files to locate functions missing the expected LR save and restore.
Monitoring Recommendations
- Monitor application telemetry for recurring crash signatures referencing invalid return addresses on ARM targets.
- Track CI/CD build logs and SBOM entries for the compiler version used to produce each ARM artifact.
- Review bug reports and crash dumps from embedded or mobile ARM deployments for stack traces that terminate at a corrupted LR.
How to Mitigate CVE-2024-31852
Immediate Actions Required
- Upgrade all LLVM and Clang toolchains used for ARM targets to version 18.1.3 or later.
- Rebuild any ARM binaries previously produced with vulnerable LLVM versions, especially those that process untrusted input.
- Validate rebuilt artifacts with the existing test suite to confirm that any previously latent crashes do not reappear.
Patch Information
The fix landed in the LLVM project through commit 0e16af8e4cf3a66ad5d078d52744ae2776f9c4b2, titled "[ARM] Update IsRestored for LR based on all returns (#82745)". The change was merged into the 18.1.3 release. See the GitHub LLVM Commit 0e16af8 and the tracking issue GitHub LLVM Issue #80287 for details. Review the LLVM Security Documentation for the project's handling policy.
Workarounds
- Pin production builds to a known-good non-ARM backend where feasible until the toolchain is updated.
- Expand functional and fuzz test coverage of ARM builds so the miscompile surfaces as a reproducible crash before deployment.
- Where upgrading immediately is not possible, selectively disable optimizations in the affected ARM frame lowering path or compile sensitive modules with a different trusted compiler.
# Verify installed LLVM/Clang version and upgrade if below 18.1.3
clang --version
# Example upgrade on Debian/Ubuntu after adding the LLVM apt repository
sudo apt-get update
sudo apt-get install --only-upgrade clang-18 llvm-18
# Rebuild ARM targets with the patched toolchain
make clean
CC=clang-18 CXX=clang++-18 make ARCH=arm
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.
Sources: National Vulnerability Database, CISA KEV, Exploit-DB

