mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: JianKang Chen <chenjiankang1@huawei.com>
Cc: <nanth@linux.vnet.ibm.com>, <anil.s.keshavamurthy@intel.com>,
	<linux-kernel@vger.kernel.org>, <xieyisheng1@huawei.com>,
	<wangkefeng.wang@huawei.com>
Subject: Re: [PATCH] kernel/kprobes: add check to avoid kprobe memory leak
Date: Thu, 26 Oct 2017 01:54:53 +0900	[thread overview]
Message-ID: <20171026015453.ba08699319ffaa9a18bbd8e3@kernel.org> (raw)
In-Reply-To: <1508847422-63641-1-git-send-email-chenjiankang1@huawei.com>

On Tue, 24 Oct 2017 20:17:02 +0800
JianKang Chen <chenjiankang1@huawei.com> wrote:

> The function register_kretprobe is used to initialize a struct
> kretprobe and allocate a list table for kprobe instance.
> However,in this function, there is a memory leak.
> 
> The test case:
> 
> static struct kretprobe rp;
> struct  kretprobe *rps[10]={&rp ,&rp ,&rp ,
> &rp ,&rp ,&rp ,&rp ,&rp ,&rp,&rp};

What ? this is buggy code. you must not list same kretprobe.
But, year, since register_kprobe() already has similar protection against
reusing, register_kretprobe() should do so.

[..]
>  	raw_spin_lock_init(&rp->lock);
> +
> +	if (!hlist_empty(&rp->free_instances))
> +		return -EBUSY;
> +

Hmm, but can you use check_kprobe_rereg() before raw_spin_lock_init()?
If user reuses rp after it starts, rp->lock can already be used.

Thank you,

>  	INIT_HLIST_HEAD(&rp->free_instances);
>  	for (i = 0; i < rp->maxactive; i++) {
>  		inst = kmalloc(sizeof(struct kretprobe_instance) +
> -- 
> 1.7.12.4
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

  reply	other threads:[~2017-10-25 16:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-24 12:17 JianKang Chen
2017-10-25 16:54 ` Masami Hiramatsu [this message]
2017-10-26  1:22   ` chenjiankang
2017-10-26  6:21     ` Masami Hiramatsu
     [not found]       ` <701DBEAC0F0CEF4095614CC8188DF8158920C0@DGGEMM506-MBS.china.huawei.com>
2017-11-10  0:57         ` 答复: " Masami Hiramatsu
2017-10-24 12:23 JianKang Chen

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=20171026015453.ba08699319ffaa9a18bbd8e3@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=anil.s.keshavamurthy@intel.com \
    --cc=chenjiankang1@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nanth@linux.vnet.ibm.com \
    --cc=wangkefeng.wang@huawei.com \
    --cc=xieyisheng1@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

Powered by JetHome