Skip to content

Commit f716fde

Browse files
committed
test: add CFI test for unaligned lpad and update existing tests
1 parent aea1887 commit f716fde

File tree

8 files changed

+39
-7
lines changed

8 files changed

+39
-7
lines changed

tests/programs/_build_cfi_native.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ build cfi_lpad_func_sig_zero.S cfi_lpad_func_sig_zero
2525
build cfi_lpad_func_sig_failed.S cfi_lpad_func_sig_failed
2626
build cfi_ss_only_pop.S cfi_ss_only_pop
2727
build cfi_ss_popchk_failed.S cfi_ss_popchk_failed
28+
build cfi_lpad_align_failed.S cfi_lpad_align_failed
2829

1.12 KB
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
3+
.include "cfi_macro.h"
4+
5+
gnu_property_cfi_ss 1
6+
7+
.text
8+
.global _start
9+
_start:
10+
la t1, func
11+
c.jalr t1
12+
13+
.globl func
14+
.type func,@function
15+
# no alignment
16+
# .balign 4
17+
func:
18+
lpad 0
19+
ret

tests/programs/cfi_lpad_unlabeled

24 Bytes
Binary file not shown.

tests/programs/cfi_lpad_unlabeled.S

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ _start:
1313

1414
la t1, exit
1515
c.jr t1
16-
16+
1717
exit_imm 1
1818

1919
.globl func
@@ -29,5 +29,11 @@ func:
2929
# lpad checks alignment with 4
3030
.balign 4
3131
exit:
32+
lpad 0
33+
# dummy lpad == no-op
34+
lpad 0
35+
li t0, 100
36+
lpad 0
37+
li t0, 200
3238
lpad 0
3339
exit_imm 0

tests/programs/cfi_ss_success

16 Bytes
Binary file not shown.

tests/programs/cfi_ss_success.S

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ _start:
2525
sspush t0
2626
sspopchk t0
2727

28+
c.sspush ra
29+
sspopchk ra
30+
31+
sspush t0
32+
c.sspopchk t0
33+
2834
li t0, 42
2935
beq ra, t0, 1f
3036
exit_imm 2

tests/test_cfi.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ pub fn test_cfi_ss_not_active() {
3939
#[test]
4040
pub fn test_cfi_ss_stack_downto_zero() {
4141
let ret = run("tests/programs/cfi_ss_stack_downto_zero");
42-
assert!(ret.is_err());
4342
assert!(matches!(ret, Err(Error::CFIShadowStackOutOfStack)));
4443
}
4544

@@ -64,7 +63,6 @@ pub fn test_cfi_lpad_not_active() {
6463
#[test]
6564
pub fn test_cfi_lpad_unlabeled_failed() {
6665
let ret = run("tests/programs/cfi_lpad_unlabeled_failed");
67-
assert!(ret.is_err());
6866
assert!(matches!(ret, Err(Error::CFILpadNotFound)));
6967
}
7068

@@ -83,21 +81,23 @@ pub fn test_cfi_lpad_func_sig_zero() {
8381
#[test]
8482
pub fn test_cfi_lpad_func_sig_failed() {
8583
let ret = run("tests/programs/cfi_lpad_func_sig_failed");
86-
assert!(ret.is_err());
8784
assert!(matches!(ret, Err(Error::CFILpadLabelMismatched)));
8885
}
8986

9087
#[test]
9188
pub fn test_cfi_ss_only_pop() {
9289
let ret = run("tests/programs/cfi_ss_only_pop");
93-
print!("err {:?}", ret);
94-
assert!(ret.is_err());
9590
assert!(matches!(ret, Err(Error::CFIShadowStackOutOfStack)));
9691
}
9792

9893
#[test]
9994
pub fn test_cfi_ss_popchk_failed() {
10095
let ret = run("tests/programs/cfi_ss_popchk_failed");
101-
assert!(ret.is_err());
10296
assert!(matches!(ret, Err(Error::CFIShadowStackValueFault)));
10397
}
98+
99+
#[test]
100+
pub fn test_cfi_lpad_align_failed() {
101+
let ret = run("tests/programs/cfi_lpad_align_failed");
102+
assert!(matches!(ret, Err(Error::CFILpadNot4ByteAligned)));
103+
}

0 commit comments

Comments
 (0)