s390/kprobes: allow kprobes only on known instructions
authorHeiko Carstens <heiko.carstens@de.ibm.com>
Fri, 13 Sep 2013 12:14:10 +0000 (14:14 +0200)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Thu, 24 Oct 2013 15:16:50 +0000 (17:16 +0200)
Since we have an in-kernel disassembler we can make sure that
there won't be any kprobes set on random data.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
arch/s390/include/asm/dis.h
arch/s390/kernel/dis.c
arch/s390/kernel/kprobes.c

index 4d0dffc682211530898a75e5f6c63370d164fd7e..04a83f5773cd5638959c8d7187a4c0043ffca190 100644 (file)
@@ -42,5 +42,11 @@ static inline int insn_length(unsigned char code)
 void show_code(struct pt_regs *regs);
 void print_fn_code(unsigned char *code, unsigned long len);
 int insn_to_mnemonic(unsigned char *instruction, char *buf, unsigned int len);
+struct s390_insn *find_insn(unsigned char *code);
+
+static inline int is_known_insn(unsigned char *code)
+{
+       return !!find_insn(code);
+}
 
 #endif /* __ASM_S390_DIS_H__ */
index ce554f3ec4457c8ad24e6802d8a714c193ed9a04..993efe6a887c2c31d4bcd90b02bccbb3c0234ae9 100644 (file)
@@ -1586,7 +1586,7 @@ static unsigned int extract_operand(unsigned char *code,
        return val;
 }
 
-static struct s390_insn *find_insn(unsigned char *code)
+struct s390_insn *find_insn(unsigned char *code)
 {
        unsigned char opfrag = code[1];
        unsigned char opmask;
index c52fdf290301811afeca0be8c9e07245334052b6..59a9c35c4598ae3265c60f69f8f87ca0a1538c2d 100644 (file)
@@ -60,6 +60,8 @@ struct kprobe_insn_cache kprobe_dmainsn_slots = {
 
 static int __kprobes is_prohibited_opcode(kprobe_opcode_t *insn)
 {
+       if (!is_known_insn((unsigned char *)insn))
+               return -EINVAL;
        switch (insn[0] >> 8) {
        case 0x0c:      /* bassm */
        case 0x0b:      /* bsm   */