^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * arch/arm/probes/kprobes/checkers-common.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2014 Huawei Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "../decode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "../decode-arm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "checkers.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) enum probes_insn checker_stack_use_none(probes_opcode_t insn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) struct arch_probes_insn *asi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) const struct decode_header *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) asi->stack_space = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) return INSN_GOOD_NO_SLOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) enum probes_insn checker_stack_use_unknown(probes_opcode_t insn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct arch_probes_insn *asi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) const struct decode_header *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) asi->stack_space = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) return INSN_GOOD_NO_SLOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #ifdef CONFIG_THUMB2_KERNEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) enum probes_insn checker_stack_use_imm_0xx(probes_opcode_t insn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct arch_probes_insn *asi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) const struct decode_header *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int imm = insn & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) asi->stack_space = imm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) return INSN_GOOD_NO_SLOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * Different from other insn uses imm8, the real addressing offset of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * STRD in T32 encoding should be imm8 * 4. See ARMARM description.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) enum probes_insn checker_stack_use_t32strd(probes_opcode_t insn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct arch_probes_insn *asi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) const struct decode_header *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) int imm = insn & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) asi->stack_space = imm << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return INSN_GOOD_NO_SLOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) enum probes_insn checker_stack_use_imm_x0x(probes_opcode_t insn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct arch_probes_insn *asi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) const struct decode_header *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) int imm = ((insn & 0xf00) >> 4) + (insn & 0xf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) asi->stack_space = imm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) return INSN_GOOD_NO_SLOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) enum probes_insn checker_stack_use_imm_xxx(probes_opcode_t insn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct arch_probes_insn *asi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) const struct decode_header *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int imm = insn & 0xfff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) asi->stack_space = imm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return INSN_GOOD_NO_SLOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) enum probes_insn checker_stack_use_stmdx(probes_opcode_t insn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct arch_probes_insn *asi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) const struct decode_header *h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) unsigned int reglist = insn & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int pbit = insn & (1 << 24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) asi->stack_space = (hweight32(reglist) - (!pbit ? 1 : 0)) * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return INSN_GOOD_NO_SLOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) const union decode_action stack_check_actions[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) [STACK_USE_NONE] = {.decoder = checker_stack_use_none},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) [STACK_USE_UNKNOWN] = {.decoder = checker_stack_use_unknown},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #ifdef CONFIG_THUMB2_KERNEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) [STACK_USE_FIXED_0XX] = {.decoder = checker_stack_use_imm_0xx},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) [STACK_USE_T32STRD] = {.decoder = checker_stack_use_t32strd},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) [STACK_USE_FIXED_X0X] = {.decoder = checker_stack_use_imm_x0x},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) [STACK_USE_FIXED_XXX] = {.decoder = checker_stack_use_imm_xxx},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) [STACK_USE_STMDX] = {.decoder = checker_stack_use_stmdx},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) };