lkml.org 
[lkml]   [2017]   [Oct]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] kernel/kprobes: add check to avoid kprobe memory leak
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>

\
 
 \ /
  Last update: 2017-10-26 08:22    [W:0.042 / U:8.988 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site