[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200307002115.b96be2310cc553a922e1ba31@kernel.org>
Date: Sat, 7 Mar 2020 00:21:15 +0900
From: Masami Hiramatsu <mhiramat@...nel.org>
To: Cheng Jian <cj.chengjian@...wei.com>,
Ingo Molnar <mingo@...nel.org>
Cc: <linux-kernel@...r.kernel.org>, <huawei.libin@...wei.com>,
<xiexiuqi@...wei.com>, <bobo.shaobowang@...wei.com>,
<naveen.n.rao@...ux.ibm.com>, <anil.s.keshavamurthy@...el.com>,
<davem@...emloft.net>, <mhiramat@...nel.org>
Subject: Re: [PATCH] kretprobe: check re-registration of the same kretprobe
earlier
Hi Cheng,
On Fri, 6 Mar 2020 17:35:06 +0800
Cheng Jian <cj.chengjian@...wei.com> wrote:
> Our system encountered a use-after-free when re-register a
> same kretprobe. it access the hlist node in rp->free_instances
> which has been released already.
>
> Prevent re-registration has been implemented for kprobe before,
> but it's too late for kretprobe. We must check the re-registration
> before re-initializing the kretprobe, otherwise it will destroy the
> data and struct of the kretprobe registered, it can lead to memory
> leak and use-after-free.
I couldn't get how it cause use-after-free, but it causes memory leak.
Anyway, if we can help to find a wrong usage, it might be good.
Acked-by: Masami Hiramatsu <mhiramat@...nel.org>
BTW, I think we should use WARN_ON() for this error, because this
means the caller is completely buggy.
Thank you,
>
> Signed-off-by: Cheng Jian <cj.chengjian@...wei.com>
> ---
> kernel/kprobes.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 2625c24..f1fc921 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -1946,6 +1946,11 @@ int register_kretprobe(struct kretprobe *rp)
> }
> }
>
> + /* Return error if it's being re-registered */
> + ret = check_kprobe_rereg(&rp->kp);
> + if (ret)
> + return ret;
> +
> rp->kp.pre_handler = pre_handler_kretprobe;
> rp->kp.post_handler = NULL;
> rp->kp.fault_handler = NULL;
> --
> 2.7.4
>
--
Masami Hiramatsu <mhiramat@...nel.org>
Powered by blists - more mailing lists