Commit 080c1ec
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 default alignment NOPs needed
due to fixed 4-byte instruction size).
- Trap debugging through ESR (Exception Syndrome Register) encoding
in BRK instruction immediate values.
- Scratch register allocation using w16/w17 (x16/x17) following
AArch64 procedure call standard for intra-procedure-call registers.
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
Build and run tested with Linux kernel ARCH=arm64.
gcc/ChangeLog:
config/aarch64/aarch64-protos.h: Declare aarch64_indirect_branch_asm,
and KCFI helpers.
config/aarch64/aarch64.cc (aarch64_expand_call): Wrap CALLs in
KCFI, with clobbers.
(aarch64_indirect_branch_asm): New function, extract common
logic for branch asm, like existing call asm helper.
(aarch64_output_kcfi_insn): Emit KCFI assembly.
config/aarch64/aarch64.md: Add KCFI RTL patterns and replace
open-coded branch emission with aarch64_indirect_branch_asm.
doc/invoke.texi: Document aarch64 nuances.
Signed-off-by: Kees Cook <[email protected]>1 parent bb9f046 commit 080c1ec
File tree
4 files changed
+190
-8
lines changed- gcc
- config/aarch64
- doc
4 files changed
+190
-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 | + | |
1287 | 1292 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
| |||
11848 | 11849 | | |
11849 | 11850 | | |
11850 | 11851 | | |
| 11852 | + | |
| 11853 | + | |
| 11854 | + | |
| 11855 | + | |
| 11856 | + | |
| 11857 | + | |
| 11858 | + | |
| 11859 | + | |
| 11860 | + | |
11851 | 11861 | | |
11852 | 11862 | | |
11853 | 11863 | | |
| |||
11864 | 11874 | | |
11865 | 11875 | | |
11866 | 11876 | | |
| 11877 | + | |
| 11878 | + | |
| 11879 | + | |
| 11880 | + | |
| 11881 | + | |
| 11882 | + | |
| 11883 | + | |
| 11884 | + | |
| 11885 | + | |
| 11886 | + | |
11867 | 11887 | | |
11868 | 11888 | | |
11869 | 11889 | | |
| |||
30630 | 30650 | | |
30631 | 30651 | | |
30632 | 30652 | | |
| 30653 | + | |
| 30654 | + | |
| 30655 | + | |
| 30656 | + | |
| 30657 | + | |
| 30658 | + | |
| 30659 | + | |
| 30660 | + | |
30633 | 30661 | | |
30634 | 30662 | | |
30635 | 30663 | | |
| |||
32823 | 32851 | | |
32824 | 32852 | | |
32825 | 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 | + | |
32826 | 32941 | | |
32827 | 32942 | | |
32828 | 32943 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1483 | 1483 | | |
1484 | 1484 | | |
1485 | 1485 | | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
1486 | 1499 | | |
1487 | 1500 | | |
1488 | 1501 | | |
| |||
1510 | 1523 | | |
1511 | 1524 | | |
1512 | 1525 | | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
1513 | 1540 | | |
1514 | 1541 | | |
1515 | 1542 | | |
| |||
1550 | 1577 | | |
1551 | 1578 | | |
1552 | 1579 | | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
1553 | 1593 | | |
1554 | 1594 | | |
1555 | 1595 | | |
| |||
1558 | 1598 | | |
1559 | 1599 | | |
1560 | 1600 | | |
1561 | | - | |
1562 | | - | |
1563 | | - | |
1564 | | - | |
| 1601 | + | |
1565 | 1602 | | |
1566 | 1603 | | |
1567 | 1604 | | |
1568 | 1605 | | |
1569 | 1606 | | |
1570 | 1607 | | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
1571 | 1622 | | |
1572 | 1623 | | |
1573 | 1624 | | |
| |||
1578 | 1629 | | |
1579 | 1630 | | |
1580 | 1631 | | |
1581 | | - | |
1582 | | - | |
1583 | | - | |
1584 | | - | |
| 1632 | + | |
1585 | 1633 | | |
1586 | 1634 | | |
1587 | 1635 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18427 | 18427 | | |
18428 | 18428 | | |
18429 | 18429 | | |
| 18430 | + | |
| 18431 | + | |
| 18432 | + | |
| 18433 | + | |
| 18434 | + | |
| 18435 | + | |
| 18436 | + | |
| 18437 | + | |
| 18438 | + | |
| 18439 | + | |
| 18440 | + | |
| 18441 | + | |
| 18442 | + | |
| 18443 | + | |
18430 | 18444 | | |
18431 | 18445 | | |
18432 | 18446 | | |
| |||
0 commit comments