]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/misc/lkdtm/cfi.c
Merge tag 'compiler-attributes-for-linus-v5.11' of git://github.com/ojeda/linux
[mirror_ubuntu-hirsute-kernel.git] / drivers / misc / lkdtm / cfi.c
CommitLineData
b0eb93cf
KC
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * This is for all the tests relating directly to Control Flow Integrity.
4 */
5#include "lkdtm.h"
6
7static int called_count;
8
9/* Function taking one argument, without a return value. */
10static noinline void lkdtm_increment_void(int *counter)
11{
12 (*counter)++;
13}
14
15/* Function taking one argument, returning int. */
16static noinline int lkdtm_increment_int(int *counter)
17{
18 (*counter)++;
19
20 return *counter;
21}
22/*
23 * This tries to call an indirect function with a mismatched prototype.
24 */
25void lkdtm_CFI_FORWARD_PROTO(void)
26{
27 /*
28 * Matches lkdtm_increment_void()'s prototype, but not
29 * lkdtm_increment_int()'s prototype.
30 */
31 void (*func)(int *);
32
33 pr_info("Calling matched prototype ...\n");
34 func = lkdtm_increment_void;
35 func(&called_count);
36
37 pr_info("Calling mismatched prototype ...\n");
38 func = (void *)lkdtm_increment_int;
39 func(&called_count);
40
41 pr_info("Fail: survived mismatched prototype function call!\n");
42}