Skip to content

Commit 3465589

Browse files
momchil-velikovcuviper
authored andcommitted
[ARM][CMSE] Issue an error if passing arguments through memory across
security boundary It was never supported and that part was accidentally omitted when upstreaming D76518. Differential Revision: https://reviews.llvm.org/D86478 Change-Id: If6ba9506eb0431c87a1d42a38aa60e47ce263039
1 parent c511304 commit 3465589

File tree

2 files changed

+90
-3
lines changed

2 files changed

+90
-3
lines changed

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4423,13 +4423,26 @@ SDValue ARMTargetLowering::LowerFormalArguments(
44234423
}
44244424

44254425
// varargs
4426-
if (isVarArg && MFI.hasVAStart())
4427-
VarArgStyleRegisters(CCInfo, DAG, dl, Chain,
4428-
CCInfo.getNextStackOffset(),
4426+
if (isVarArg && MFI.hasVAStart()) {
4427+
VarArgStyleRegisters(CCInfo, DAG, dl, Chain, CCInfo.getNextStackOffset(),
44294428
TotalArgRegsSaveSize);
4429+
if (AFI->isCmseNSEntryFunction()) {
4430+
DiagnosticInfoUnsupported Diag(
4431+
DAG.getMachineFunction().getFunction(),
4432+
"secure entry function must not be variadic", dl.getDebugLoc());
4433+
DAG.getContext()->diagnose(Diag);
4434+
}
4435+
}
44304436

44314437
AFI->setArgumentStackSize(CCInfo.getNextStackOffset());
44324438

4439+
if (CCInfo.getNextStackOffset() > 0 && AFI->isCmseNSEntryFunction()) {
4440+
DiagnosticInfoUnsupported Diag(
4441+
DAG.getMachineFunction().getFunction(),
4442+
"secure entry function requires arguments on stack", dl.getDebugLoc());
4443+
DAG.getContext()->diagnose(Diag);
4444+
}
4445+
44334446
return Chain;
44344447
}
44354448

llvm/test/CodeGen/ARM/cmse-errors.ll

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
; RUN: not llc -mtriple=thumbv8m.main-eabi %s -o - 2>&1 | FileCheck %s
2+
3+
%struct.two_ints = type { i32, i32 }
4+
%struct.__va_list = type { i8* }
5+
6+
define void @test1(%struct.two_ints* noalias nocapture sret align 4 %agg.result) "cmse_nonsecure_entry" {
7+
entry:
8+
%0 = bitcast %struct.two_ints* %agg.result to i64*
9+
store i64 8589934593, i64* %0, align 4
10+
ret void
11+
}
12+
; CHECK: error: {{.*}}test1{{.*}}: secure entry function would return value through pointer
13+
14+
define void @test2(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) "cmse_nonsecure_entry" {
15+
entry:
16+
ret void
17+
}
18+
; CHECK: error: {{.*}}test2{{.*}}: secure entry function requires arguments on stack
19+
20+
define void @test3(void (i32, i32, i32, i32, i32)* nocapture %p) {
21+
entry:
22+
tail call void %p(i32 1, i32 2, i32 3, i32 4, i32 5) "cmse_nonsecure_call"
23+
ret void
24+
}
25+
; CHECK: error: {{.*}}test3{{.*}}: call to non-secure function would require passing arguments on stack
26+
27+
28+
define void @test4(void (%struct.two_ints*)* nocapture %p) {
29+
entry:
30+
%r = alloca %struct.two_ints, align 4
31+
%0 = bitcast %struct.two_ints* %r to i8*
32+
call void %p(%struct.two_ints* nonnull sret align 4 %r) "cmse_nonsecure_call"
33+
ret void
34+
}
35+
; CHECK: error: {{.*}}test4{{.*}}: call to non-secure function would return value through pointer
36+
37+
declare void @llvm.va_start(i8*) "nounwind"
38+
39+
declare void @llvm.va_end(i8*) "nounwind"
40+
41+
define i32 @test5(i32 %a, ...) "cmse_nonsecure_entry" {
42+
entry:
43+
%vl = alloca %struct.__va_list, align 4
44+
%0 = bitcast %struct.__va_list* %vl to i8*
45+
call void @llvm.va_start(i8* nonnull %0)
46+
%1 = getelementptr inbounds %struct.__va_list, %struct.__va_list* %vl, i32 0, i32 0
47+
%argp.cur = load i8*, i8** %1, align 4
48+
%argp.next = getelementptr inbounds i8, i8* %argp.cur, i32 4
49+
store i8* %argp.next, i8** %1, align 4
50+
%2 = bitcast i8* %argp.cur to i32*
51+
%3 = load i32, i32* %2, align 4
52+
call void @llvm.va_end(i8* nonnull %0)
53+
ret i32 %3
54+
}
55+
; CHECK: error: {{.*}}test5{{.*}}: secure entry function must not be variadic
56+
57+
define void @test6(void (i32, ...)* nocapture %p) {
58+
entry:
59+
tail call void (i32, ...) %p(i32 1, i32 2, i32 3, i32 4, i32 5) "cmse_nonsecure_call"
60+
ret void
61+
}
62+
; CHECK: error: {{.*}}test6{{.*}}: call to non-secure function would require passing arguments on stack
63+
64+
define void @neg_test1(void (i32, ...)* nocapture %p) {
65+
entry:
66+
tail call void (i32, ...) %p(i32 1, i32 2, i32 3, i32 4) "cmse_nonsecure_call"
67+
ret void
68+
}
69+
70+
define void @neg_test2(i32 %a, ...) "cmse_nonsecure_entry" {
71+
entry:
72+
ret void
73+
}
74+
; CHECK-NOT: error:

0 commit comments

Comments
 (0)