Commit d340d28a authored by Sven Schnelle's avatar Sven Schnelle Committed by Vasily Gorbik
Browse files

kprobes: add testcases for s390



Add a few testcases to make sure that it's not possible to place
a kprobe in the mid of an instruction on s390.

Signed-off-by: default avatarSven Schnelle <svens@linux.ibm.com>
Acked-by: default avatarHeiko Carstens <hca@linux.ibm.com>
Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
parent f768a20c
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -946,4 +946,16 @@ config S390_UNWIND_SELFTEST

	  Say N if you are unsure.

config S390_KPROBES_SANITY_TEST
	def_tristate n
	prompt "Enable s390 specific kprobes tests"
	depends on KPROBES
	depends on KUNIT
	help
	  This option enables an s390 specific kprobes test module. This option
	  is not useful for distributions or general kernels, but only for kernel
	  developers working on architecture code.

	  Say N if you are unsure.

endmenu
+1 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ CONFIG_CMM=m
CONFIG_APPLDATA_BASE=y
CONFIG_KVM=m
CONFIG_S390_UNWIND_SELFTEST=y
CONFIG_S390_KPROBES_SANITY_TEST=y
CONFIG_KPROBES=y
CONFIG_JUMP_LABEL=y
CONFIG_STATIC_KEYS_SELFTEST=y
+2 −0
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@ lib-y += delay.o string.o uaccess.o find.o spinlock.o
obj-y += mem.o xor.o
lib-$(CONFIG_KPROBES) += probes.o
lib-$(CONFIG_UPROBES) += probes.o
obj-$(CONFIG_S390_KPROBES_SANITY_TEST) += test_kprobes_s390.o
test_kprobes_s390-objs += test_kprobes_asm.o test_kprobes.o

# Instrumenting memory accesses to __user data (in different address space)
# produce false positives
+75 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0+

#include <linux/kernel.h>
#include <linux/kprobes.h>
#include <linux/random.h>
#include <kunit/test.h>
#include "test_kprobes.h"

static struct kprobe kp;

static void setup_kprobe(struct kunit *test, struct kprobe *kp,
			 const char *symbol, int offset)
{
	kp->offset = offset;
	kp->addr = NULL;
	kp->symbol_name = symbol;
}

static void test_kprobe_offset(struct kunit *test, struct kprobe *kp,
			       const char *target, int offset)
{
	int ret;

	setup_kprobe(test, kp, target, 0);
	ret = register_kprobe(kp);
	if (!ret)
		unregister_kprobe(kp);
	KUNIT_EXPECT_EQ(test, 0, ret);
	setup_kprobe(test, kp, target, offset);
	ret = register_kprobe(kp);
	KUNIT_EXPECT_EQ(test, -EINVAL, ret);
	if (!ret)
		unregister_kprobe(kp);
}

static void test_kprobe_odd(struct kunit *test)
{
	test_kprobe_offset(test, &kp, "kprobes_target_odd",
			   kprobes_target_odd_offs);
}

static void test_kprobe_in_insn4(struct kunit *test)
{
	test_kprobe_offset(test, &kp, "kprobes_target_in_insn4",
			   kprobes_target_in_insn4_offs);
}

static void test_kprobe_in_insn6_lo(struct kunit *test)
{
	test_kprobe_offset(test, &kp, "kprobes_target_in_insn6_lo",
			   kprobes_target_in_insn6_lo_offs);
}

static void test_kprobe_in_insn6_hi(struct kunit *test)
{
	test_kprobe_offset(test, &kp, "kprobes_target_in_insn6_hi",
			   kprobes_target_in_insn6_hi_offs);
}

static struct kunit_case kprobes_testcases[] = {
	KUNIT_CASE(test_kprobe_odd),
	KUNIT_CASE(test_kprobe_in_insn4),
	KUNIT_CASE(test_kprobe_in_insn6_lo),
	KUNIT_CASE(test_kprobe_in_insn6_hi),
	{}
};

static struct kunit_suite kprobes_test_suite = {
	.name = "kprobes_test_s390",
	.test_cases = kprobes_testcases,
};

kunit_test_suites(&kprobes_test_suite);

MODULE_LICENSE("GPL");
+10 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0+ */
#ifndef TEST_KPROBES_H
#define TEST_KPROBES_H

extern unsigned long kprobes_target_odd_offs;
extern unsigned long kprobes_target_in_insn4_offs;
extern unsigned long kprobes_target_in_insn6_lo_offs;
extern unsigned long kprobes_target_in_insn6_hi_offs;

#endif
Loading