mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wang Nan <wangnan0@huawei.com>
To: <tixy@linaro.org>, <masami.hiramatsu.pt@hitachi.com>,
	<linux@arm.linux.org.uk>, <will.deacon@arm.com>,
	<dave.long@linaro.org>, <taras.kondratiuk@linaro.org>,
	Ben Dooks <ben.dooks@codethink.co.uk>,
	Christoph Lameter <cl@linux.com>, Rabin Vincent <rabin@rab.in>,
	"David S. Miller" <davem@davemloft.net>
Cc: <linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	"Li Zefan" <lizefan@huawei.com>
Subject: [PATCH v6 3/7] ARM: kprobes: introduces checker
Date: Wed, 22 Oct 2014 19:32:01 +0800	[thread overview]
Message-ID: <1413977525-51480-4-git-send-email-wangnan0@huawei.com> (raw)
In-Reply-To: <1413977525-51480-1-git-send-email-wangnan0@huawei.com>

This patch introdces a 'checker' field to decode_action, and calls
checkers when instruction decoding. This allows further analysis
for specific instructions.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
---
 arch/arm/kernel/probes.c | 10 ++++++++++
 arch/arm/kernel/probes.h | 10 ++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/arch/arm/kernel/probes.c b/arch/arm/kernel/probes.c
index ec030b8..6164b4d 100644
--- a/arch/arm/kernel/probes.c
+++ b/arch/arm/kernel/probes.c
@@ -393,6 +393,7 @@ probes_decode_insn(probes_opcode_t insn, struct arch_probes_insn *asi,
 	const struct decode_header *h = (struct decode_header *)table;
 	const struct decode_header *next;
 	bool matched = false;
+	probes_opcode_t origin_insn = insn;
 
 	if (emulate)
 		insn = prepare_emulated_insn(insn, asi, thumb);
@@ -423,17 +424,26 @@ probes_decode_insn(probes_opcode_t insn, struct arch_probes_insn *asi,
 
 		case DECODE_TYPE_CUSTOM: {
 			struct decode_custom *d = (struct decode_custom *)h;
+			probes_check_t *checker = actions[d->decoder.action].checker;
+			if (checker && (checker(origin_insn, asi, h) == INSN_REJECTED))
+				return INSN_REJECTED;
 			return actions[d->decoder.action].decoder(insn, asi, h);
 		}
 
 		case DECODE_TYPE_SIMULATE: {
 			struct decode_simulate *d = (struct decode_simulate *)h;
+			probes_check_t *checker = actions[d->handler.action].checker;
+			if (checker && (checker(origin_insn, asi, h) == INSN_REJECTED))
+				return INSN_REJECTED;
 			asi->insn_handler = actions[d->handler.action].handler;
 			return INSN_GOOD_NO_SLOT;
 		}
 
 		case DECODE_TYPE_EMULATE: {
 			struct decode_emulate *d = (struct decode_emulate *)h;
+			probes_check_t *checker = actions[d->handler.action].checker;
+			if (checker && (checker(origin_insn, asi, h) == INSN_REJECTED))
+				return INSN_REJECTED;
 
 			if (!emulate)
 				return actions[d->handler.action].decoder(insn,
diff --git a/arch/arm/kernel/probes.h b/arch/arm/kernel/probes.h
index 739c2a2..c56dd3d 100644
--- a/arch/arm/kernel/probes.h
+++ b/arch/arm/kernel/probes.h
@@ -309,9 +309,15 @@ typedef enum probes_insn (probes_custom_decode_t)(probes_opcode_t,
 						  struct arch_probes_insn *,
 						  const struct decode_header *);
 
+typedef enum probes_insn (probes_check_t)(probes_opcode_t,
+					   struct arch_probes_insn *,
+					   const struct decode_header *);
 struct decode_action {
-	probes_insn_handler_t	*handler;
-	probes_custom_decode_t	*decoder;
+	probes_check_t *checker;
+	union {
+		probes_insn_handler_t	*handler;
+		probes_custom_decode_t	*decoder;
+	};
 };
 
 #define DECODE_END			\
-- 
1.8.4


  parent reply	other threads:[~2014-10-22 11:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-22 11:31 [PATCH v6 0/7] ARM: kprobes: enable OPTPROBES for ARM 32 Wang Nan
2014-10-22 11:31 ` [PATCH v6 1/7] ARM: kprobes: replace 'union decode_action' to 'struct decode_action' Wang Nan
2014-10-22 11:32 ` [PATCH v6 2/7] ARM: kprobes: seprates load and store actions Wang Nan
2014-10-22 11:32 ` Wang Nan [this message]
2014-10-22 11:32 ` [PATCH v6 4/7] ARM: kprobes: collects stack consumption for store instructions Wang Nan
2014-10-22 11:32 ` [PATCH v6 5/7] ARM: kprobes: disallow probing stack consuming instructions Wang Nan
2014-10-22 11:32 ` [PATCH v6 6/7] kprobes: copy ainsn after alloc aggr kprobe Wang Nan
2014-10-22 11:32 ` [PATCH v6 7/7] ARM: kprobes: enable OPTPROBES for ARM 32 Wang Nan
2014-10-24  0:52 ` [PATCH v6 0/7] " Masami Hiramatsu
2014-10-24  9:02   ` Jon Medhurst (Tixy)
2014-10-25  9:49     ` Wang Nan
2014-10-27 17:17       ` Jon Medhurst (Tixy)
2014-10-28 10:58         ` Jon Medhurst (Tixy)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1413977525-51480-4-git-send-email-wangnan0@huawei.com \
    --to=wangnan0@huawei.com \
    --cc=ben.dooks@codethink.co.uk \
    --cc=cl@linux.com \
    --cc=dave.long@linaro.org \
    --cc=davem@davemloft.net \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=lizefan@huawei.com \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=rabin@rab.in \
    --cc=taras.kondratiuk@linaro.org \
    --cc=tixy@linaro.org \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®