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