mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Cheng Jian <cj.chengjian@huawei.com>
Cc: <ananth@linux.vnet.ibm.com>, <anil.s.keshavamurthy@intel.com>,
	<davem@davemloft.net>, <linux-kernel@vger.kernel.org>,
	<xiexiuqi@huawei.com>, <huawei.libin@huawei.com>
Subject: Re: [PATCH] kprobe : fix out-of-bounds in register_kretprobe when parsing negative data_size
Date: Wed, 13 Dec 2017 22:14:33 +0900	[thread overview]
Message-ID: <20171213221433.a733aeed6fe8cbf59a3f9bfc@kernel.org> (raw)
In-Reply-To: <1513168041-26924-1-git-send-email-cj.chengjian@huawei.com>

On Wed, 13 Dec 2017 20:27:21 +0800
Cheng Jian <cj.chengjian@huawei.com> wrote:

> When we register kretprobe, data_size used to allocate space
> for storing per-instance private data.
> 
> If we use a negative values as data_size, It will register
> successfully, then cause slab-out-of-bounds which can be
> found by KASAN.
> 
> The call trace is like :
> 
> 	=============================================================
> 	BUG: KASAN: slab-out-of-bounds in trampoline_probe_handler
> 	+0xb4/0x2f0 at addr ffff8000b732a7a0
> 	Read of size 8 by task sh/1945
> 	=============================================================
> 	BUG kmalloc-64 (Tainted: G    B   W  OE  ):
> 	kasan: bad access detected
> 	-------------------------------------------------------------
> 	INFO: Allocated in register_kretprobe+0x12c/0x350
> 	age=157 cpu=4 pid=1947
> 	......
> 	INFO: Freed in do_one_initcall+0x110/0x260
> 	age=169 cpu=4 pid=1947
> 	......
> 	INFO: Slab 0xffff7bffc2dcca80 objects=21 used=10
> 	fp=0xffff8000b732aa80 flags=0x7fff00000004080
> 	INFO: Object 0xffff8000b732a780 @offset=1920 fp=0x     (null)
> 
> 	CPU: 7 PID: 1945 Comm: sh Tainted: G    B   W  OE   4.1.46 #8
> 	Hardware name: linux,dummy-virt (DT)
> 	Call trace:
> 	[<0008d2a0>] dump_backtrace+0x0/0x220
> 	[<0008d4e0>] show_stack+0x20/0x30
> 	[<00ff2278>] dump_stack+0xa8/0xcc
> 	[<002dc6c8>] print_trailer+0xf8/0x160
> 	[<002e20d8>] object_err+0x48/0x60
> 	[<002e48dc>] kasan_report+0x26c/0x5a0
> 	[<002e39a0>] __asan_load8+0x60/0x80
> 	[<01000054>] trampoline_probe_handler+0xb4/0x2f0
> 	[<00ffff38>] kretprobe_trampoline+0x54/0xbc
> 	Memory state around the buggy address:
>  	b732a680: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>  	b732a700: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
> 	>b732a780: 00 00 00 00 07 fc fc fc fc fc fc fc fc fc fc fc
>                                ^
> 
> If data_size is invalid, then we should not register it.

Good catch!
Anyway, this influence is limited because this interface is
only exposed to custom kernel modules. So only roots can
shoot in the foot.

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>

Thank you!

> 
> Signed-off-by: Cheng Jian <cj.chengjian@huawei.com>
> Reported-by: Kong ZhangHuan <kongzhanghuan@huawei.com>
> ---
>  kernel/kprobes.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index da2ccf1..8002f28 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -1924,6 +1924,9 @@ int register_kretprobe(struct kretprobe *rp)
>  	int i;
>  	void *addr;
>  
> +	if ((ssize_t)rp->data_size < 0)
> +		return -EINVAL;
> +
>  	if (!kprobe_on_func_entry(rp->kp.addr, rp->kp.symbol_name, rp->kp.offset))
>  		return -EINVAL;
>  
> -- 
> 1.8.3.1
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

      parent reply	other threads:[~2017-12-13 13:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-13 12:27 Cheng Jian
2017-12-13 12:25 ` chengjian (D)
2017-12-13 13:14 ` Masami Hiramatsu [this message]

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=20171213221433.a733aeed6fe8cbf59a3f9bfc@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=ananth@linux.vnet.ibm.com \
    --cc=anil.s.keshavamurthy@intel.com \
    --cc=cj.chengjian@huawei.com \
    --cc=davem@davemloft.net \
    --cc=huawei.libin@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xiexiuqi@huawei.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®