Commit ad9b6ee
committed
aarch64: Add AArch64 Kernel Control Flow Integrity implementation
Implement AArch64-specific KCFI backend.
- Function preamble generation using .word directives for type ID storage
at offset from function entry point (no prefix NOPs needed due to
4-byte instruction alignment).
- Trap debugging through ESR (Exception Syndrome Register) encoding
in BRK instruction immediate values for precise failure analysis.
- Scratch register allocation using w16/w17 (x16/x17) following
AArch64 procedure call standard for intra-procedure-call registers.
- Support for both regular calls (BLR) and sibling calls (BR) with
appropriate register usage and jump instructions.
- Atomic bundled KCFI check + call/branch sequences using UNSPECV_KCFI_CHECK
to prevent optimizer separation and maintain security properties.
Assembly Code Pattern for AArch64:
ldur w16, [target, #-4] ; Load actual type ID from preamble
mov w17, #type_id_low ; Load expected type (lower 16 bits)
movk w17, #type_id_high, lsl gcc-mirror#16 ; Load upper 16 bits if needed
cmp w16, w17 ; Compare type IDs directly
b.eq .Lpass ; Branch if types match
.Ltrap: brk #esr_value ; Enhanced trap with register info
.Lpass: blr/br target ; Execute validated indirect transfer
ESR (Exception Syndrome Register) Integration:
- BRK instruction immediate encoding format:
0x8000 | ((TypeIndex & 31) << 5) | (AddrIndex & 31)
- TypeIndex indicates which W register contains expected type (W17 = 17)
- AddrIndex indicates which X register contains target address (0-30)
- Example: brk #33313 (0x8221) = expected type in W17, target address in X1
Like x86, the callback initialization in aarch64_override_options()
seem hacky. Is there a better place for this?
Build and run tested with Linux kernel ARCH=arm64.
Signed-off-by: Kees Cook <[email protected]>1 parent bf9c9d2 commit ad9b6ee
File tree
4 files changed
+234
-8
lines changed- gcc
- config/aarch64
- doc
4 files changed
+234
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1261 | 1261 | | |
1262 | 1262 | | |
1263 | 1263 | | |
| 1264 | + | |
1264 | 1265 | | |
1265 | 1266 | | |
1266 | 1267 | | |
| |||
1284 | 1285 | | |
1285 | 1286 | | |
1286 | 1287 | | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
1287 | 1293 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| |||
25590 | 25591 | | |
25591 | 25592 | | |
25592 | 25593 | | |
| 25594 | + | |
| 25595 | + | |
| 25596 | + | |
25593 | 25597 | | |
25594 | 25598 | | |
25595 | 25599 | | |
| |||
30630 | 30634 | | |
30631 | 30635 | | |
30632 | 30636 | | |
| 30637 | + | |
| 30638 | + | |
| 30639 | + | |
| 30640 | + | |
| 30641 | + | |
| 30642 | + | |
| 30643 | + | |
| 30644 | + | |
30633 | 30645 | | |
30634 | 30646 | | |
30635 | 30647 | | |
| |||
32823 | 32835 | | |
32824 | 32836 | | |
32825 | 32837 | | |
| 32838 | + | |
| 32839 | + | |
| 32840 | + | |
| 32841 | + | |
| 32842 | + | |
| 32843 | + | |
| 32844 | + | |
| 32845 | + | |
| 32846 | + | |
| 32847 | + | |
| 32848 | + | |
| 32849 | + | |
| 32850 | + | |
| 32851 | + | |
| 32852 | + | |
| 32853 | + | |
| 32854 | + | |
| 32855 | + | |
| 32856 | + | |
| 32857 | + | |
| 32858 | + | |
| 32859 | + | |
| 32860 | + | |
| 32861 | + | |
| 32862 | + | |
| 32863 | + | |
| 32864 | + | |
| 32865 | + | |
| 32866 | + | |
| 32867 | + | |
| 32868 | + | |
| 32869 | + | |
| 32870 | + | |
| 32871 | + | |
| 32872 | + | |
| 32873 | + | |
| 32874 | + | |
| 32875 | + | |
| 32876 | + | |
| 32877 | + | |
| 32878 | + | |
| 32879 | + | |
| 32880 | + | |
| 32881 | + | |
| 32882 | + | |
| 32883 | + | |
| 32884 | + | |
| 32885 | + | |
| 32886 | + | |
| 32887 | + | |
| 32888 | + | |
| 32889 | + | |
| 32890 | + | |
| 32891 | + | |
| 32892 | + | |
| 32893 | + | |
| 32894 | + | |
| 32895 | + | |
| 32896 | + | |
| 32897 | + | |
| 32898 | + | |
| 32899 | + | |
| 32900 | + | |
| 32901 | + | |
| 32902 | + | |
| 32903 | + | |
| 32904 | + | |
| 32905 | + | |
| 32906 | + | |
| 32907 | + | |
| 32908 | + | |
| 32909 | + | |
| 32910 | + | |
| 32911 | + | |
| 32912 | + | |
| 32913 | + | |
| 32914 | + | |
| 32915 | + | |
| 32916 | + | |
| 32917 | + | |
| 32918 | + | |
| 32919 | + | |
| 32920 | + | |
| 32921 | + | |
| 32922 | + | |
| 32923 | + | |
| 32924 | + | |
| 32925 | + | |
| 32926 | + | |
| 32927 | + | |
| 32928 | + | |
| 32929 | + | |
| 32930 | + | |
| 32931 | + | |
| 32932 | + | |
| 32933 | + | |
| 32934 | + | |
| 32935 | + | |
| 32936 | + | |
| 32937 | + | |
| 32938 | + | |
| 32939 | + | |
| 32940 | + | |
| 32941 | + | |
| 32942 | + | |
| 32943 | + | |
| 32944 | + | |
| 32945 | + | |
| 32946 | + | |
| 32947 | + | |
| 32948 | + | |
| 32949 | + | |
| 32950 | + | |
| 32951 | + | |
| 32952 | + | |
| 32953 | + | |
| 32954 | + | |
| 32955 | + | |
| 32956 | + | |
| 32957 | + | |
| 32958 | + | |
| 32959 | + | |
| 32960 | + | |
| 32961 | + | |
| 32962 | + | |
| 32963 | + | |
| 32964 | + | |
| 32965 | + | |
| 32966 | + | |
| 32967 | + | |
| 32968 | + | |
| 32969 | + | |
| 32970 | + | |
| 32971 | + | |
| 32972 | + | |
| 32973 | + | |
| 32974 | + | |
| 32975 | + | |
| 32976 | + | |
| 32977 | + | |
| 32978 | + | |
| 32979 | + | |
| 32980 | + | |
| 32981 | + | |
| 32982 | + | |
| 32983 | + | |
| 32984 | + | |
| 32985 | + | |
| 32986 | + | |
| 32987 | + | |
| 32988 | + | |
| 32989 | + | |
| 32990 | + | |
| 32991 | + | |
| 32992 | + | |
| 32993 | + | |
| 32994 | + | |
| 32995 | + | |
| 32996 | + | |
| 32997 | + | |
| 32998 | + | |
| 32999 | + | |
| 33000 | + | |
| 33001 | + | |
| 33002 | + | |
| 33003 | + | |
32826 | 33004 | | |
32827 | 33005 | | |
32828 | 33006 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
| 420 | + | |
420 | 421 | | |
421 | 422 | | |
422 | 423 | | |
| |||
1326 | 1327 | | |
1327 | 1328 | | |
1328 | 1329 | | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
1329 | 1363 | | |
1330 | 1364 | | |
1331 | 1365 | | |
| |||
1558 | 1592 | | |
1559 | 1593 | | |
1560 | 1594 | | |
1561 | | - | |
1562 | | - | |
1563 | | - | |
1564 | | - | |
| 1595 | + | |
1565 | 1596 | | |
1566 | 1597 | | |
1567 | 1598 | | |
| |||
1578 | 1609 | | |
1579 | 1610 | | |
1580 | 1611 | | |
1581 | | - | |
1582 | | - | |
1583 | | - | |
1584 | | - | |
| 1612 | + | |
1585 | 1613 | | |
1586 | 1614 | | |
1587 | 1615 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18424 | 18424 | | |
18425 | 18425 | | |
18426 | 18426 | | |
| 18427 | + | |
| 18428 | + | |
| 18429 | + | |
| 18430 | + | |
| 18431 | + | |
| 18432 | + | |
| 18433 | + | |
| 18434 | + | |
| 18435 | + | |
| 18436 | + | |
| 18437 | + | |
| 18438 | + | |
| 18439 | + | |
| 18440 | + | |
18427 | 18441 | | |
18428 | 18442 | | |
18429 | 18443 | | |
| |||
0 commit comments