linux/drivers/misc/lkdtm/perms.c

// SPDX-License-Identifier: GPL-2.0
/*
 * This is for all the tests related to validating kernel memory
 * permissions: non-executable regions, non-writable regions, and
 * even non-readable regions.
 */
#include "lkdtm.h"
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/mman.h>
#include <linux/uaccess.h>
#include <asm/cacheflush.h>
#include <asm/sections.h>

/* Whether or not to fill the target memory area with do_nothing(). */
#define CODE_WRITE
#define CODE_AS_IS

/* How many bytes to copy to be sure we've copied enough of do_nothing(). */
#define EXEC_SIZE

/* This is non-const, so it will end up in the .data section. */
static u8 data_area[EXEC_SIZE];

/* This is const, so it will end up in the .rodata section. */
static const unsigned long rodata =;

/* This is marked __ro_after_init, so it should ultimately be .rodata. */
static unsigned long ro_after_init __ro_after_init =;

/*
 * This just returns to the caller. It is designed to be copied into
 * non-executable memory regions.
 */
static noinline void do_nothing(void)
{}

/* Must immediately follow do_nothing for size calculuations to work out. */
static noinline void do_overwritten(void)
{}

static noinline void do_almost_nothing(void)
{}

static void *setup_function_descriptor(func_desc_t *fdesc, void *dst)
{}

static noinline __nocfi void execute_location(void *dst, bool write)
{}

static void execute_user_location(void *dst)
{}

static void lkdtm_WRITE_RO(void)
{}

static void lkdtm_WRITE_RO_AFTER_INIT(void)
{}

static void lkdtm_WRITE_KERN(void)
{}

static void lkdtm_WRITE_OPD(void)
{}

static void lkdtm_EXEC_DATA(void)
{}

static void lkdtm_EXEC_STACK(void)
{}

static void lkdtm_EXEC_KMALLOC(void)
{}

static void lkdtm_EXEC_VMALLOC(void)
{}

static void lkdtm_EXEC_RODATA(void)
{}

static void lkdtm_EXEC_USERSPACE(void)
{}

static void lkdtm_EXEC_NULL(void)
{}

static void lkdtm_ACCESS_USERSPACE(void)
{}

static void lkdtm_ACCESS_NULL(void)
{}

void __init lkdtm_perms_init(void)
{}

static struct crashtype crashtypes[] =;

struct crashtype_category perms_crashtypes =;