xref: /linux/tools/objtool/tests/x86/test-kcfi.sh (revision 5b6dca02b3e2254d2fd5706d76d7ab4610a67296)
1*62ef2041SSong Liu#!/bin/bash
2*62ef2041SSong Liu# SPDX-License-Identifier: GPL-2.0
3*62ef2041SSong Liu#
4*62ef2041SSong Liu# Under kCFI an indirect call checks a type hash before jumping, and traps on a
5*62ef2041SSong Liu# mismatch.  Two things belong to the calling function and must come with it
6*62ef2041SSong Liu# into a patch:
7*62ef2041SSong Liu#
8*62ef2041SSong Liu#   - the __cfi_<func> prefix symbol holding the hash.  Lose it and the patched
9*62ef2041SSong Liu#     function has no type identity, so indirect calls to it trap.
10*62ef2041SSong Liu#   - its .kcfi_traps entry.  Lose that and the trap is not recognised as a
11*62ef2041SSong Liu#     CFI failure, so what should be a clean report becomes an oops.
12*62ef2041SSong Liu#
13*62ef2041SSong Liu# Neither shows up at build time.
14*62ef2041SSong Liu
15*62ef2041SSong Liu. "$(dirname "$0")/../lib.sh"
16*62ef2041SSong Liu
17*62ef2041SSong Liuclang_only "kCFI is a Clang feature"
18*62ef2041SSong Liu
19*62ef2041SSong Liusetup
20*62ef2041SSong Liu
21*62ef2041SSong Liu# Declared above that this is Clang's; a given Clang may still be too old.
22*62ef2041SSong Liucc_supports -fsanitize=kcfi ||
23*62ef2041SSong Liu	probe_skip "this clang does not support -fsanitize=kcfi"
24*62ef2041SSong Liu
25*62ef2041SSong Liubuild_pair kcfi.c -fsanitize=kcfi
26*62ef2041SSong Liu
27*62ef2041SSong Liuassert_input_section .kcfi_traps
28*62ef2041SSong Liuassert_input_symbol __cfi_target
29*62ef2041SSong Liu
30*62ef2041SSong Liurun_diff
31*62ef2041SSong Liu
32*62ef2041SSong Liuassert_patched target
33*62ef2041SSong Liu
34*62ef2041SSong Liu# The prefix symbol comes with its function ...
35*62ef2041SSong Liuassert_symbol __cfi_target
36*62ef2041SSong Liu# ... and so does the trap entry.
37*62ef2041SSong Liuassert_section .kcfi_traps
38*62ef2041SSong Liu
39*62ef2041SSong Liupass "kCFI prefix symbol and trap entry carried with the patched function"
40