-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ARM] Mitigate the cve-2021-35465 security vulnurability.
Recently a vulnerability issue is found in the implementation of VLLDM instruction in the Arm Cortex-M33, Cortex-M35P and Cortex-M55. If the VLLDM instruction is abandoned due to an exception when it is partially completed, it is possible for subsequent non-secure handler to access and modify the partial restored register values. This vulnerability is identified as CVE-2021-35465. The mitigation sequence varies between v8-m and v8.1-m as follows: v8-m.main --------- mrs r5, control tst r5, #8 /* CONTROL_S.SFPA */ it ne .inst.w 0xeeb00a40 /* vmovne s0, s0 */ 1: vlldm sp /* Lazy restore of d0-d16 and FPSCR. */ v8.1-m.main ----------- vscclrm {vpr} /* Clear VPR. */ vlldm sp /* Lazy restore of d0-d16 and FPSCR. */ More details on developer.arm.com/support/arm-security-updates/vlldm-instruction-security-vulnerability Differential Revision: https://reviews.llvm.org/D109157
- Loading branch information
Showing
10 changed files
with
323 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Disable the fix | ||
// | ||
// RUN: %clang --target=arm-arm-none-eabi -march=armv8-m.main %s -### \ | ||
// RUN: -mcmse -mno-fix-cmse-cve-2021-35465 2>&1 |\ | ||
// RUN: FileCheck %s --check-prefix=CHECK-NOFIX | ||
// | ||
// RUN: %clang --target=arm-arm-none-eabi -march=armv8.1-m.main %s -### \ | ||
// RUN: -mcmse -mno-fix-cmse-cve-2021-35465 2>&1 |\ | ||
// RUN: FileCheck %s --check-prefix=CHECK-NOFIX | ||
// | ||
// RUN: %clang --target=arm-arm-none-eabi -march=armv8-m.main %s -### \ | ||
// RUN: -mcmse -mfix-cmse-cve-2021-35465 -mno-fix-cmse-cve-2021-35465 2>&1 |\ | ||
// RUN: FileCheck %s --check-prefix=CHECK-NOFIX | ||
// | ||
// CHECK-NOFIX: "-target-feature" "-fix-cmse-cve-2021-35465" | ||
|
||
|
||
// Enable the fix | ||
// | ||
// RUN: %clang --target=arm-arm-none-eabi -march=armv8-m.main %s -### \ | ||
// RUN: -mcmse -mfix-cmse-cve-2021-35465 2>&1 |\ | ||
// RUN: FileCheck %s --check-prefix=CHECK-FIX | ||
// | ||
// RUN: %clang --target=arm-arm-none-eabi -march=armv8.1-m.main %s -### \ | ||
// RUN: -mcmse -mfix-cmse-cve-2021-35465 2>&1 |\ | ||
// RUN: FileCheck %s --check-prefix=CHECK-FIX | ||
// | ||
// RUN: %clang --target=arm-arm-none-eabi -march=armv8-m.main %s -### \ | ||
// RUN: -mcmse -mno-fix-cmse-cve-2021-35465 -mfix-cmse-cve-2021-35465 2>&1 |\ | ||
// RUN: FileCheck %s --check-prefix=CHECK-FIX | ||
// | ||
// CHECK-FIX: "-target-feature" "+fix-cmse-cve-2021-35465" | ||
|
||
|
||
// Diagnose the option when used without -mcmse | ||
// | ||
// RUN: %clang --target=arm-arm-none-eabi -march=armv8-m.main %s -### \ | ||
// RUN: -mfix-cmse-cve-2021-35465 2>&1 |\ | ||
// RUN: FileCheck %s --check-prefix=CHECK-DIAG | ||
// | ||
// RUN: %clang --target=arm-arm-none-eabi -march=armv8.1-m.main %s -### \ | ||
// RUN: -mno-fix-cmse-cve-2021-35465 2>&1 |\ | ||
// RUN: FileCheck %s --check-prefix=CHECK-DIAG | ||
// | ||
// CHECK-DIAG: error: option 'm{{.*}}fix-cmse-cve-2021-35465' cannot be specified without '-mcmse' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
; | ||
; RUN: llc %s -o - -mtriple=thumbv8m.main -verify-machineinstrs \ | ||
; RUN: -mattr=+fp-armv8d16sp,+fix-cmse-cve-2021-35465 -float-abi=hard | \ | ||
; RUN: FileCheck %s --check-prefix=CHECK-8M-FP-CVE-2021-35465 | ||
|
||
%indirect = type { double, double, double, double, double, double, double, double } | ||
|
||
define %indirect @func(%indirect (float, i32, double, i32, float, i32, float, i32, double, double, double, double, float, float)* %fu, float %a, i32 %b, double %c, i32 %d, float %e, i32 %f, float %g, i32 %h, double %i, double %j, double %k, double %l, float %m, float %n) { | ||
; CHECK-8M-FP-CVE-2021-35465-LABEL: func: | ||
; CHECK-8M-FP-CVE-2021-35465: @ %bb.0: @ %entry | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: push {r7, lr} | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: mov lr, r3 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: mov r12, r0 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: mov r0, r1 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: mov r1, r2 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: ldr r3, [sp, #8] | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: mov r2, lr | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: push.w {r4, r5, r6, r7, r8, r9, r10, r11} | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: bic r12, r12, #1 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: sub sp, #136 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmov r4, s5 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmov r11, s0 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmov r9, r10, d1 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmov r8, s1 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmov r7, s4 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmov r5, r6, d3 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vlstm sp | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmov s0, r11 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmov d1, r9, r10 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmov s1, r8 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmov s4, r7 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmov d3, r5, r6 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmov s5, r4 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vldr d4, [sp, #32] | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vldr d5, [sp, #40] | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vldr d6, [sp, #48] | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vldr s14, [sp, #56] | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: ldr r4, [sp, #64] | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: bic r4, r4, #159 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: bic r4, r4, #4026531840 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmsr fpscr, r4 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: msr apsr_nzcvq, r12 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: blxns r12 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmov r9, r10, d0 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vstr d3, [sp, #24] | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmov r7, r8, d1 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vstr d4, [sp, #32] | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmov r5, r6, d2 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vstr d5, [sp, #40] | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vstr d6, [sp, #48] | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vstr d7, [sp, #56] | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: mrs r11, control | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: tst.w r11, #8 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: it ne | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmovne.f32 s0, s0 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vlldm sp | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmov d0, r9, r10 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmov d1, r7, r8 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: vmov d2, r5, r6 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: add sp, #136 | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: pop.w {r4, r5, r6, r7, r8, r9, r10, r11} | ||
; CHECK-8M-FP-CVE-2021-35465-NEXT: pop {r7, pc} | ||
entry: | ||
%res = call %indirect %fu(float %a, i32 %b, double %c, i32 %d, float %e, i32 %f, float %g, i32 %h, double %i, double %j, double %k, double %l, float %m, float %n) #0 | ||
ret %indirect %res | ||
} | ||
|
||
attributes #0 = { "cmse_nonsecure_call" } |
Oops, something went wrong.