-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x86: Add support for CONFIG_CFI_CLANG
With CONFIG_CFI_CLANG, the compiler injects a type preamble immediately before each function and a check to validate the target function type before indirect calls: ; type preamble __cfi_function: mov <id>, %eax function: ... ; indirect call check mov -<id>,%r10d add -0x4(%r11),%r10d je .Ltmp1 ud2 .Ltmp1: call __x86_indirect_thunk_r11 Add error handling code for the ud2 traps emitted for the checks, and allow CONFIG_CFI_CLANG to be selected on x86_64. This produces the following oops on CFI failure (generated using lkdtm): [ 21.441706] CFI failure at lkdtm_indirect_call+0x16/0x20 [lkdtm] (target: lkdtm_increment_int+0x0/0x10 [lkdtm]; expected type: 0x7e0c52a) [ 21.444579] invalid opcode: 0000 [#1] PREEMPT SMP NOPTI [ 21.445296] CPU: 0 PID: 132 Comm: sh Not tainted 5.19.0-rc8-00020-g9f27360e674c #1 [ 21.445296] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014 [ 21.445296] RIP: 0010:lkdtm_indirect_call+0x16/0x20 [lkdtm] [ 21.445296] Code: 52 1c c0 48 c7 c1 c5 50 1c c0 e9 25 48 2a cc 0f 1f 44 00 00 49 89 fb 48 c7 c7 50 b4 1c c0 41 ba 5b ad f3 81 45 03 53 f8 [ 21.445296] RSP: 0018:ffffa9f9c02ffdc0 EFLAGS: 00000292 [ 21.445296] RAX: 0000000000000027 RBX: ffffffffc01cb300 RCX: 385cbbd2e070a700 [ 21.445296] RDX: 0000000000000000 RSI: c0000000ffffdfff RDI: ffffffffc01cb450 [ 21.445296] RBP: 0000000000000006 R08: 0000000000000000 R09: ffffffff8d081610 [ 21.445296] R10: 00000000bcc90825 R11: ffffffffc01c2fc0 R12: 0000000000000000 [ 21.445296] R13: ffffa31b827a6000 R14: 0000000000000000 R15: 0000000000000002 [ 21.445296] FS: 00007f08b42216a0(0000) GS:ffffa31b9f400000(0000) knlGS:0000000000000000 [ 21.445296] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 21.445296] CR2: 0000000000c76678 CR3: 0000000001940000 CR4: 00000000000006f0 [ 21.445296] Call Trace: [ 21.445296] <TASK> [ 21.445296] lkdtm_CFI_FORWARD_PROTO+0x30/0x50 [lkdtm] [ 21.445296] direct_entry+0x12d/0x140 [lkdtm] [ 21.445296] full_proxy_write+0x5d/0xb0 [ 21.445296] vfs_write+0x144/0x460 [ 21.445296] ? __x64_sys_wait4+0x5a/0xc0 [ 21.445296] ksys_write+0x69/0xd0 [ 21.445296] do_syscall_64+0x51/0xa0 [ 21.445296] entry_SYSCALL_64_after_hwframe+0x63/0xcd [ 21.445296] RIP: 0033:0x7f08b41a6fe1 [ 21.445296] Code: be 07 00 00 00 41 89 c0 e8 7e ff ff ff 44 89 c7 89 04 24 e8 91 c6 02 00 8b 04 24 48 83 c4 68 c3 48 63 ff b8 01 00 00 03 [ 21.445296] RSP: 002b:00007ffcdf65c2e8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001 [ 21.445296] RAX: ffffffffffffffda RBX: 00007f08b4221690 RCX: 00007f08b41a6fe1 [ 21.445296] RDX: 0000000000000012 RSI: 0000000000c738f0 RDI: 0000000000000001 [ 21.445296] RBP: 0000000000000001 R08: fefefefefefefeff R09: fefefefeffc5ff4e [ 21.445296] R10: 00007f08b42222b0 R11: 0000000000000246 R12: 0000000000c738f0 [ 21.445296] R13: 0000000000000012 R14: 00007ffcdf65c401 R15: 0000000000c70450 [ 21.445296] </TASK> [ 21.445296] Modules linked in: lkdtm [ 21.445296] Dumping ftrace buffer: [ 21.445296] (ftrace buffer empty) [ 21.471442] ---[ end trace 0000000000000000 ]--- [ 21.471811] RIP: 0010:lkdtm_indirect_call+0x16/0x20 [lkdtm] [ 21.472467] Code: 52 1c c0 48 c7 c1 c5 50 1c c0 e9 25 48 2a cc 0f 1f 44 00 00 49 89 fb 48 c7 c7 50 b4 1c c0 41 ba 5b ad f3 81 45 03 53 f8 [ 21.474400] RSP: 0018:ffffa9f9c02ffdc0 EFLAGS: 00000292 [ 21.474735] RAX: 0000000000000027 RBX: ffffffffc01cb300 RCX: 385cbbd2e070a700 [ 21.475664] RDX: 0000000000000000 RSI: c0000000ffffdfff RDI: ffffffffc01cb450 [ 21.476471] RBP: 0000000000000006 R08: 0000000000000000 R09: ffffffff8d081610 [ 21.477127] R10: 00000000bcc90825 R11: ffffffffc01c2fc0 R12: 0000000000000000 [ 21.477959] R13: ffffa31b827a6000 R14: 0000000000000000 R15: 0000000000000002 [ 21.478657] FS: 00007f08b42216a0(0000) GS:ffffa31b9f400000(0000) knlGS:0000000000000000 [ 21.479577] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 21.480307] CR2: 0000000000c76678 CR3: 0000000001940000 CR4: 00000000000006f0 [ 21.481460] Kernel panic - not syncing: Fatal exception Signed-off-by: Sami Tolvanen <samitolvanen@google.com> Reviewed-by: Kees Cook <keescook@chromium.org> Tested-by: Kees Cook <keescook@chromium.org> Tested-by: Nathan Chancellor <nathan@kernel.org> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20220908215504.3686827-23-samitolvanen@google.com
- x86_vdso_for_v6.3_rc1
- x86_urgent_for_6.4-rc4
- x86_urgent_for_v6.4_rc6
- x86_urgent_for_v6.4_rc2
- x86_urgent_for_v6.3
- x86_urgent_for_v6.3_rc7
- x86_urgent_for_v6.3_rc6
- x86_urgent_for_v6.3_rc4
- x86_urgent_for_v6.3_rc3
- x86_urgent_for_v6.3_rc2
- x86_urgent_for_v6.2_rc7
- x86_urgent_for_v6.2_rc6
- x86_urgent_for_v6.2_rc4
- x86_urgent_for_v6.2_rc2
- x86_urgent_for_v6.1_rc7
- x86_urgent_for_v6.1_rc6
- x86_urgent_for_v6.1_rc4
- x86_urgent_for_v6.0_rc2
- x86_tdx_for_6.4
- x86_tdx_for_6.3
- x86_tdx_for_6.2
- x86_splitlock_for_6.2
- x86_shstk_for_6.4
- x86_sgx_for_6.2
- x86_sev_for_v6.4_rc1
- x86_sev_for_v6.2
- x86_paravirt_for_v6.4_rc1
- x86_paravirt_for_v6.2
- x86_mm_for_6.4
- x86_mm_for_6.2_v2
- x86_misc_for_v6.4_rc1
- x86_microcode_for_v6.3_rc1
- x86_microcode_for_v6.2
- x86_fpu_for_6.4
- x86_fpu_for_6.2
- x86_cpu_for_v6.4_rc1
- x86_cpu_for_v6.3_rc1
- x86_cpu_for_v6.2
- x86_core_for_v6.2
- x86_cleanups_for_v6.4_rc1
- x86_cache_for_6.4
- x86_cache_for_6.2
- x86_cache_for_v6.3_rc1
- x86_boot_for_v6.2
- x86_asm_for_v6.2
- x86_alternatives_for_v6.3_rc1
- x86_alternatives_for_v6.2
- x86_acpi_for_v6.4_rc1
- x86-urgent-2023-05-28
- x86-urgent-2023-03-05
- x86-urgent-2023-02-19
- x86-urgent-2023-02-11
- x86-urgent-2023-01-04
- x86-urgent-2022-12-12
- x86-platform-2023-02-20
- x86-mm-2023-02-20
- x86-misc-2022-12-10
- x86-fpu-2023-02-20
- x86-core-2023-02-20
- x86-cleanups-2023-02-20
- x86-cleanups-2022-12-10
- x86-build-2023-02-20
- x86-boot-2023-02-20
- x86-asm-2023-02-20
- x86-apic-2023-04-24
- x86-apic-2022-12-10
- v6.9-rc4
- v6.9-rc3
- v6.9-rc2
- v6.9-rc1
- v6.8.6
- v6.8.5
- v6.8.4
- v6.8.3
- v6.8.2
- v6.8.1
- v6.8
- v6.8-rc7
- v6.8-rc6
- v6.8-rc5
- v6.8-rc4
- v6.8-rc3
- v6.8-rc2
- v6.8-rc1
- v6.7.12
- v6.7.11
- v6.7.10
- v6.7.9
- v6.7.8
- v6.7.7
- v6.7.6
- v6.7.5
- v6.7.4
- v6.7.3
- v6.7.2
- v6.7.1
- v6.7
- v6.7-rc8
- v6.7-rc7
- v6.7-rc6
- v6.7-rc5
- v6.7-rc4
- v6.7-rc3
- v6.7-rc2
- v6.7-rc1
- v6.6.27
- v6.6.26
- v6.6.25
- v6.6.24
- v6.6.23
- v6.6.22
- v6.6.21
- v6.6.20
- v6.6.19
- v6.6.18
- v6.6.17
- v6.6.16
- v6.6.15
- v6.6.14
- v6.6.13
- v6.6.12
- v6.6.11
- v6.6.10
- v6.6.9
- v6.6.8
- v6.6.7
- v6.6.6
- v6.6.5
- v6.6.4
- v6.6.3
- v6.6.2
- v6.6.1
- v6.6
- v6.6-rc7
- v6.6-rc6
- v6.6-rc5
- v6.6-rc4
- v6.6-rc3
- v6.6-rc2
- v6.6-rc1
- v6.5.13
- v6.5.12
- v6.5.11
- v6.5.10
- v6.5.9
- v6.5.8
- v6.5.7
- v6.5.6
- v6.5.5
- v6.5.4
- v6.5.3
- v6.5.2
- v6.5.1
- v6.5
- v6.5-rc7
- v6.5-rc6
- v6.5-rc5
- v6.5-rc4
- v6.5-rc3
- v6.5-rc2
- v6.5-rc1
- v6.4.16
- v6.4.15
- v6.4.14
- v6.4.13
- v6.4.12
- v6.4.11
- v6.4.10
- v6.4.9
- v6.4.8
- v6.4.7
- v6.4.6
- v6.4.5
- v6.4.4
- v6.4.3
- v6.4.2
- v6.4.1
- v6.4
- v6.4-rc7
- v6.4-rc6
- v6.4-rc5
- v6.4-rc4
- v6.4-rc3
- v6.4-rc2
- v6.4-rc1
- v6.3.13
- v6.3.12
- v6.3.11
- v6.3.10
- v6.3.9
- v6.3.8
- v6.3.7
- v6.3.6
- v6.3.5
- v6.3.4
- v6.3.3
- v6.3.2
- v6.3.1
- v6.3
- v6.3-rc7
- v6.3-rc6
- v6.3-rc5
- v6.3-rc4
- v6.3-rc3
- v6.3-rc2
- v6.3-rc1
- v6.2.16
- v6.2.15
- v6.2.14
- v6.2.13
- v6.2.12
- v6.2.11
- v6.2.10
- v6.2.9
- v6.2.8
- v6.2.7
- v6.2.6
- v6.2.5
- v6.2.4
- v6.2.3
- v6.2.2
- v6.2.1
- v6.2
- v6.2-rc8
- v6.2-rc7
- v6.2-rc6
- v6.2-rc5
- v6.2-rc4
- v6.2-rc3
- v6.2-rc2
- v6.2-rc1
- v6.1.86
- v6.1.85
- v6.1.84
- v6.1.83
- v6.1.82
- v6.1.81
- v6.1.80
- v6.1.79
- v6.1.78
- v6.1.77
- v6.1.76
- v6.1.75
- v6.1.74
- v6.1.73
- v6.1.72
- v6.1.71
- v6.1.70
- v6.1.69
- v6.1.68
- v6.1.67
- v6.1.66
- v6.1.65
- v6.1.64
- v6.1.63
- v6.1.62
- v6.1.61
- v6.1.60
- v6.1.59
- v6.1.58
- v6.1.57
- v6.1.56
- v6.1.55
- v6.1.54
- v6.1.53
- v6.1.52
- v6.1.51
- v6.1.50
- v6.1.49
- v6.1.48
- v6.1.47
- v6.1.46
- v6.1.45
- v6.1.44
- v6.1.43
- v6.1.42
- v6.1.41
- v6.1.40
- v6.1.39
- v6.1.38
- v6.1.37
- v6.1.36
- v6.1.35
- v6.1.34
- v6.1.33
- v6.1.32
- v6.1.31
- v6.1.30
- v6.1.29
- v6.1.28
- v6.1.27
- v6.1.26
- v6.1.25
- v6.1.24
- v6.1.23
- v6.1.22
- v6.1.21
- v6.1.20
- v6.1.19
- v6.1.18
- v6.1.17
- v6.1.16
- v6.1.15
- v6.1.14
- v6.1.13
- v6.1.12
- v6.1.11
- v6.1.10
- v6.1.9
- v6.1.8
- v6.1.7
- v6.1.6
- v6.1.5
- v6.1.4
- v6.1.3
- v6.1.2
- v6.1.1
- v6.1
- v6.1-rc8
- v6.1-rc7
- v6.1-rc6
- v6.1-rc5
- v6.1-rc4
- v6.1-rc3
- v6.1-rc2
- v6.1-rc1
- unmap-fix-20230629
- timers-urgent-2023-02-19
- timers-urgent-2023-01-12
- timers-core-2023-04-28
- timers-core-2023-04-24
- timers-core-2023-02-20
- timers-core-2022-12-10
- timers_urgent_for_v6.4_rc2
- timers_urgent_for_v6.1_rc8
- timers_urgent_for_v6.1_rc7
- thermal-6.6-rc1
- thermal-6.6-rc1-3
- thermal-6.6-rc1-2
- thermal-6.5-rc4
- thermal-6.5-rc1
- thermal-6.4-rc8
- thermal-6.4-rc4
- thermal-6.4-rc1
- thermal-6.4-rc1-3
- thermal-6.4-rc1-2
- thermal-6.3-rc7
- thermal-6.3-rc5
- thermal-6.3-rc4
- thermal-6.3-rc2
- thermal-6.3-rc1
- thermal-6.3-rc1-2
- thermal-6.2-rc6
- thermal-6.2-rc5
- thermal-6.2-rc3
- thermal-6.2-rc1
- thermal-6.2-rc1-2
- thermal-6.1-rc2
- tags/kvm-6.2-2
- tags/kvm-6.2-1
- smp-core-2023-04-27
- smp-core-2022-12-10
- sched-urgent-2023-02-17
- sched-urgent-2023-01-12
- sched-core-2023-04-27
- sched-core-2023-02-20
- sched-core-2022-12-12
- sched_urgent_for_v6.4_rc2
- sched_urgent_for_v6.3_rc7
- sched_urgent_for_v6.3_rc4
- sched_urgent_for_v6.2_rc6
- sched_urgent_for_v6.1_rc6
- sched_urgent_for_v6.1_rc2
- ras_urgent_for_v6.3_rc3
- ras_core_for_v6.4_rc1
- ras_core_for_v6.3_rc1
- ras_core_for_v6.2
- pm-6.6-rc1
- pm-6.6-rc1-3
- pm-6.6-rc1-2
- pm-6.5-rc6
- pm-6.5-rc5
- pm-6.5-rc4
- pm-6.5-rc3
- pm-6.5-rc2
- pm-6.5-rc1
- pm-6.5-rc1-2
- pm-6.4-rc4
- pm-6.4-rc3
- pm-6.4-rc1
- pm-6.4-rc1-2
- pm-6.3-rc7
- pm-6.3-rc3
- pm-6.3-rc1
- pm-6.3-rc1-2
- pm-6.2-rc9
- pm-6.2-rc8
- pm-6.2-rc4
- pm-6.2-rc1
- pm-6.1-rc7
- pm-6.1-rc3
- pm-6.1-rc2
- perf-urgent-2023-05-28
- perf-urgent-2023-01-12
- perf-urgent-2023-01-06
- perf-core-2023-04-27
- perf-core-2023-02-20
- perf-core-2022-12-12
- perf_urgent_for_v6.4_rc2
- perf_urgent_for_v6.3_rc6
- perf_urgent_for_v6.3_rc4
- perf_urgent_for_v6.3_rc3
- perf_urgent_for_v6.2_rc7
- perf_urgent_for_v6.2_rc6
- perf_urgent_for_v6.2_rc4
- perf_urgent_for_v6.2_rc2
- perf_urgent_for_v6.1_rc8
- perf_urgent_for_v6.1_rc7
- perf_urgent_for_v6.1_rc6
- perf_urgent_for_v6.1_rc4
- perf_urgent_for_v6.1_rc3
- perf_urgent_for_v6.1_rc2
- objtool-urgent-2023-05-28
- objtool-core-2023-04-27
- objtool-core-2023-03-02
- objtool_urgent_for_v6.1_rc7
- objtool_urgent_for_v6.1_rc2
- next-20230912
- next-20230809
- next-20230803
- next-20230801
- next-20230724
- next-20230721
- next-20230718
- next-20230717
- next-20230714
- next-20230706
- next-20230620
- next-20230608
- next-20230512
- next-20230511
- next-20230508
- next-20230504
- next-20230426
- next-20230419
- next-20230411
- next-20230405
- next-20230324
- next-20230320
- next-20230302
- next-20230228
- next-20230217
- next-20230208
- next-20230206
- next-20230203
- next-20230123
- next-20230105
- next-20221226
- next-20221220
- next-20221202
- next-20221129
- next-20221014
- next-20221013
- next-20220930
- next-20220927
- md-next-20230825
- md-next-20230817
- md-next-20230814-resend
- md-next-20230729
- md-next-20230623
- md-next-20230613
- md-next-2023-04-28
- md-fixes-20230630
- md-fixes-2023-05-24
- md-fixes-2023-03-29
- mariux-6.12.29-483
- mariux-6.12.27-482
- mariux-6.12.23-481
- mariux-6.12.23-480
- mariux-6.12.11-479
- mariux-6.6.35-477
- mariux-6.6.27-472
- mariux-6.6.26-471
- mariux-6.6.25-470
- mariux-6.6.24-469
- mariux-6.6.23-468
- mariux-6.6.22-467
- mariux-6.6.22-466
- mariux-6.6.22-465
- mariux-6.6.21-464
- mariux-6.6.20-463
- mariux-6.6.19-462
- mariux-6.6.12-461
- mariux-6.6.11-460
- mariux-6.5.2-455
- mariux-6.5.2-452
- mariux-6.5.2-451
- mariux-6.1.53-458
- mariux-6.1.52-456
- mariux-6.1.39-450
- mariux-6.1.7-446
- locking-urgent-2023-02-11
- locking-core-2023-05-05
- locking-core-2023-02-20
- locking-core-2022-12-12
- locking_urgent_for_v6.4_rc2
- locking_urgent_for_v6.2_rc2
- locking_urgent_for_v6.1_rc6
- irq-urgent-2023-05-28
- irq-urgent-2023-03-05
- irq-urgent-2023-02-19
- irq-core-2023-04-24
- irq-core-2023-02-20
- irq-core-2022-12-10
- irq_urgent_for_v6.4_rc5
- irq_urgent_for_v6.3
- irq_urgent_for_v6.2_rc6
- hwmon-for-v6.3
- hwmon-for-v6.3-rc4
- hwmon-for-v6.3-rc3
- hwmon-for-v6.2
- hwmon-for-v6.2-rc1
- hwmon-for-v6.1-rc8
- hwmon-for-v6.1-rc4
- hwmon-for-v6.1-rc2
- core-urgent-2023-01-12
- core-entry-2023-04-24
- core-debugobjects-2023-05-28
- core-debugobjects-2023-05-06
- core-debugobjects-2023-04-24
- core-debugobjects-2022-12-10
- core_urgent_for_v6.3_rc4
- core_urgent_for_v6.2_rc4
- ata-6.6-rc1
- ata-6.5-rc5
- ata-6.5-rc4
- ata-6.5-rc3
- ata-6.5-rc1
- ata-6.4-rc7
- ata-6.4-rc5
- ata-6.4-rc3
- ata-6.4-rc1
- ata-6.3-rc7
- ata-6.3-rc3
- ata-6.3-rc1
- ata-6.3-fix
- ata-6.2-rc8
- ata-6.2-rc7
- ata-6.2-rc4
- ata-6.2-rc2
- ata-6.2-rc1
- ata-6.1-rc8
- ata-6.1-rc5
- ata-6.1-rc4
- ata-6.1-rc2
- amd-drm-next-6.4-2023-03-31
- amd-drm-next-6.4-2023-03-17
- amd-drm-next-6.3-2023-02-17
- amd-drm-next-6.3-2023-02-03
- amd-drm-next-6.3-2023-01-27
- amd-drm-next-6.3-2023-01-20
- amd-drm-next-6.3-2023-01-13
- amd-drm-next-6.3-2023-01-06
- amd-drm-next-6.2-2022-12-07
- amd-drm-next-6.2-2022-12-02
- amd-drm-next-6.2-2022-11-25
- amd-drm-next-6.2-2022-11-18
- amd-drm-next-6.2-2022-11-11
- amd-drm-next-6.2-2022-11-04
- amd-drm-fixes-6.3-2023-03-30
- amd-drm-fixes-6.3-2023-03-29
- amd-drm-fixes-6.3-2023-03-23
- amd-drm-fixes-6.3-2023-03-15
- amd-drm-fixes-6.3-2023-03-09
- amd-drm-fixes-6.3-2023-03-02
- amd-drm-fixes-6.2-2023-02-15
- amd-drm-fixes-6.2-2023-02-09
- amd-drm-fixes-6.2-2023-02-08
- amd-drm-fixes-6.2-2023-02-01
- amd-drm-fixes-6.2-2023-01-25
- amd-drm-fixes-6.2-2023-01-19
- amd-drm-fixes-6.2-2023-01-11
- amd-drm-fixes-6.2-2023-01-04
- amd-drm-fixes-6.2-2022-12-21
- amd-drm-fixes-6.2-2022-12-15
- amd-drm-fixes-6.1-2022-12-07
- amd-drm-fixes-6.1-2022-12-01
- amd-drm-fixes-6.1-2022-11-23
- amd-drm-fixes-6.1-2022-11-16
- amd-drm-fixes-6.1-2022-11-09
- amd-drm-fixes-6.1-2022-11-02
- amd-drm-fixes-6.1-2022-10-26-1
- amd-drm-fixes-6.1-2022-10-20
- amd-drm-fixes-6.1-2022-10-19
- acpi-6.6-rc1
- acpi-6.5-rc8
- acpi-6.5-rc6
- acpi-6.5-rc1
- acpi-6.5-rc1-3
- acpi-6.5-rc1-2
- acpi-6.4-rc8
- acpi-6.4-rc3
- acpi-6.4-rc1
- acpi-6.4-rc1-3
- acpi-6.4-rc1-2
- acpi-6.3-rc7
- acpi-6.3-rc6
- acpi-6.3-rc5
- acpi-6.3-rc4
- acpi-6.3-rc3
- acpi-6.3-rc1
- acpi-6.3-rc1-2
- acpi-6.2-rc6
- acpi-6.2-rc5
- acpi-6.2-rc4
- acpi-6.2-rc2
- acpi-6.2-rc1
- acpi-6.2-rc1-2
- acpi-6.1-rc4
- acpi-6.1-rc3
- acpi-6.1-rc2
- Ubuntu-unstable-6.5.0-4.4
- Ubuntu-unstable-6.5.0-2.2
- Ubuntu-unstable-6.5.0-1.1
- Ubuntu-unstable-6.4.0-8.8
- Ubuntu-unstable-6.4.0-5.5
- Ubuntu-unstable-6.3.0-2.2
- Ubuntu-unstable-6.3.0-1.1
- Ubuntu-unstable-6.1.0-9.9
- Ubuntu-lowlatency-6.2.0-1014.14
- Ubuntu-lowlatency-6.2.0-1010.10
- Ubuntu-lowlatency-6.2.0-1009.9
- Ubuntu-lowlatency-6.2.0-1008.8
- Ubuntu-lowlatency-6.2.0-1005.5
- Ubuntu-lowlatency-6.2.0-1004.4
- Ubuntu-lowlatency-6.2.0-1003.3
- Ubuntu-lowlatency-6.2.0-1002.2
- Ubuntu-lowlatency-6.2.0-1001.1
- Ubuntu-lowlatency-6.1.0-1001.1
- Ubuntu-6.2.0-34.34
- Ubuntu-6.2.0-32.32
- Ubuntu-6.2.0-30.30
- Ubuntu-6.2.0-27.28
- Ubuntu-6.2.0-26.26
- Ubuntu-6.2.0-25.25
- Ubuntu-6.2.0-23.23
- Ubuntu-6.2.0-21.21
- Ubuntu-6.2.0-20.20
- Ubuntu-6.2.0-19.19
- Ubuntu-6.2.0-18.18
- Ubuntu-6.2.0-17.17
- Ubuntu-6.1.0-16.16
- Ubuntu-6.1.0-15.15
- Ubuntu-6.1.0-14.14
- Ubuntu-6.1.0-13.13
- Ubuntu-6.1.0-12.12
Sami Tolvanen
authored and
Kees Cook
committed
Sep 26, 2022
1 parent
a4b7a12
commit 3c516f8
Showing
5 changed files
with
115 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
#ifndef _ASM_X86_CFI_H | ||
#define _ASM_X86_CFI_H | ||
|
||
/* | ||
* Clang Control Flow Integrity (CFI) support. | ||
* | ||
* Copyright (C) 2022 Google LLC | ||
*/ | ||
|
||
#include <linux/cfi.h> | ||
|
||
#ifdef CONFIG_CFI_CLANG | ||
enum bug_trap_type handle_cfi_failure(struct pt_regs *regs); | ||
#else | ||
static inline enum bug_trap_type handle_cfi_failure(struct pt_regs *regs) | ||
{ | ||
return BUG_TRAP_TYPE_NONE; | ||
} | ||
#endif /* CONFIG_CFI_CLANG */ | ||
|
||
#endif /* _ASM_X86_CFI_H */ |
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,86 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* Clang Control Flow Integrity (CFI) support. | ||
* | ||
* Copyright (C) 2022 Google LLC | ||
*/ | ||
#include <asm/cfi.h> | ||
#include <asm/insn.h> | ||
#include <asm/insn-eval.h> | ||
#include <linux/string.h> | ||
|
||
/* | ||
* Returns the target address and the expected type when regs->ip points | ||
* to a compiler-generated CFI trap. | ||
*/ | ||
static bool decode_cfi_insn(struct pt_regs *regs, unsigned long *target, | ||
u32 *type) | ||
{ | ||
char buffer[MAX_INSN_SIZE]; | ||
struct insn insn; | ||
int offset = 0; | ||
|
||
*target = *type = 0; | ||
|
||
/* | ||
* The compiler generates the following instruction sequence | ||
* for indirect call checks: | ||
* | ||
* movl -<id>, %r10d ; 6 bytes | ||
* addl -4(%reg), %r10d ; 4 bytes | ||
* je .Ltmp1 ; 2 bytes | ||
* ud2 ; <- regs->ip | ||
* .Ltmp1: | ||
* | ||
* We can decode the expected type and the target address from the | ||
* movl/addl instructions. | ||
*/ | ||
if (copy_from_kernel_nofault(buffer, (void *)regs->ip - 12, MAX_INSN_SIZE)) | ||
return false; | ||
if (insn_decode_kernel(&insn, &buffer[offset])) | ||
return false; | ||
if (insn.opcode.value != 0xBA) | ||
return false; | ||
|
||
*type = -(u32)insn.immediate.value; | ||
|
||
if (copy_from_kernel_nofault(buffer, (void *)regs->ip - 6, MAX_INSN_SIZE)) | ||
return false; | ||
if (insn_decode_kernel(&insn, &buffer[offset])) | ||
return false; | ||
if (insn.opcode.value != 0x3) | ||
return false; | ||
|
||
/* Read the target address from the register. */ | ||
offset = insn_get_modrm_rm_off(&insn, regs); | ||
if (offset < 0) | ||
return false; | ||
|
||
*target = *(unsigned long *)((void *)regs + offset); | ||
|
||
return true; | ||
} | ||
|
||
/* | ||
* Checks if a ud2 trap is because of a CFI failure, and handles the trap | ||
* if needed. Returns a bug_trap_type value similarly to report_bug. | ||
*/ | ||
enum bug_trap_type handle_cfi_failure(struct pt_regs *regs) | ||
{ | ||
unsigned long target; | ||
u32 type; | ||
|
||
if (!is_cfi_trap(regs->ip)) | ||
return BUG_TRAP_TYPE_NONE; | ||
|
||
if (!decode_cfi_insn(regs, &target, &type)) | ||
return report_cfi_failure_noaddr(regs, regs->ip); | ||
|
||
return report_cfi_failure(regs, regs->ip, &target, type); | ||
} | ||
|
||
/* | ||
* Ensure that __kcfi_typeid_ symbols are emitted for functions that may | ||
* not be indirectly called with all configurations. | ||
*/ | ||
__ADDRESSABLE(__memcpy) |
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