linux/drivers/misc/lkdtm/cfi.c

// SPDX-License-Identifier: GPL-2.0
/*
 * This is for all the tests relating directly to Control Flow Integrity.
 */
#include "lkdtm.h"
#include <asm/page.h>

static int called_count;

/* Function taking one argument, without a return value. */
static noinline void lkdtm_increment_void(int *counter)
{}

/* Function taking one argument, returning int. */
static noinline int lkdtm_increment_int(int *counter)
{}

/* Don't allow the compiler to inline the calls. */
static noinline void lkdtm_indirect_call(void (*func)(int *))
{}

/*
 * This tries to call an indirect function with a mismatched prototype.
 */
static void lkdtm_CFI_FORWARD_PROTO(void)
{}

/*
 * This can stay local to LKDTM, as there should not be a production reason
 * to disable PAC && SCS.
 */
#ifdef CONFIG_ARM64_PTR_AUTH_KERNEL
# ifdef CONFIG_ARM64_BTI_KERNEL
#define __no_pac
# else
#  ifdef CONFIG_CC_HAS_BRANCH_PROT_PAC_RET
#define __no_pac
#  else
#define __no_pac
#  endif
# endif
#define __no_ret_protection
#else
#define __no_ret_protection
#endif

#define no_pac_addr(addr)

#ifdef CONFIG_RISCV
/* https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc#frame-pointer-convention */
#define FRAME_RA_OFFSET
#else
#define FRAME_RA_OFFSET
#endif

/* The ultimate ROP gadget. */
static noinline __no_ret_protection
void set_return_addr_unchecked(unsigned long *expected, unsigned long *addr)
{}

static noinline
void set_return_addr(unsigned long *expected, unsigned long *addr)
{}

static volatile int force_check;

static void lkdtm_CFI_BACKWARD(void)
{}

static struct crashtype crashtypes[] =;

struct crashtype_category cfi_crashtypes =;