From: Masami Hiramatsu <mhiramat@kernel.org>
To: chenjiankang <chenjiankang1@huawei.com>
Cc: <ananth@linux.vnet.ibm.com>, <anil.s.keshavamurthy@intel.com>,
<linux-kernel@vger.kernel.org>, <xieyisheng1@huawei.com>,
<wangkefeng.wang@huawei.com>, <davem@davemloft.net>
Subject: Re: [PATCH] kernel/kprobes: add check to avoid kprobe memory leak
Date: Thu, 26 Oct 2017 15:21:30 +0900 [thread overview]
Message-ID: <20171026152130.119473592483b3106b2ac4df@kernel.org> (raw)
In-Reply-To: <a11a31b6-bff3-b6c1-db47-787540cd0d07@huawei.com>
On Thu, 26 Oct 2017 09:22:23 +0800
chenjiankang <chenjiankang1@huawei.com> wrote:
> > 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.
>
> Hmm, your advice is very good, we can use check_kprobe_rereg() at
> the beginning of the register_kretprobe();
>
> For example:
>
> int register_kretprobe(struct kretprobe *rp)
> {
> int ret = 0;
> struct kretprobe_instance *inst;
> int i;
> void *addr;
>
> ret = check_kprobe_rereg(&rp->kp);
> if (ret)
> return ret;
Yeah, this looks much better for me :)
Thanks,
>
> Thank you!
>
>
--
Masami Hiramatsu <mhiramat@kernel.org>
next prev parent reply other threads:[~2017-10-26 6:21 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
2017-10-26 1:22 ` chenjiankang
2017-10-26 6:21 ` Masami Hiramatsu [this message]
[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=20171026152130.119473592483b3106b2ac4df@kernel.org \
--to=mhiramat@kernel.org \
--cc=ananth@linux.vnet.ibm.com \
--cc=anil.s.keshavamurthy@intel.com \
--cc=chenjiankang1@huawei.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--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