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>, Ingo Molnar <mingo@kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <huawei.libin@huawei.com>,
	<xiexiuqi@huawei.com>, <bobo.shaobowang@huawei.com>,
	<naveen.n.rao@linux.ibm.com>, <anil.s.keshavamurthy@intel.com>,
	<davem@davemloft.net>, <mhiramat@kernel.org>
Subject: Re: [PATCH] kretprobe: check re-registration of the same kretprobe earlier
Date: Sat, 7 Mar 2020 00:21:15 +0900	[thread overview]
Message-ID: <20200307002115.b96be2310cc553a922e1ba31@kernel.org> (raw)
In-Reply-To: <1583487306-81985-1-git-send-email-cj.chengjian@huawei.com>

Hi Cheng,

On Fri, 6 Mar 2020 17:35:06 +0800
Cheng Jian <cj.chengjian@huawei.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@kernel.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@huawei.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@kernel.org>

  reply	other threads:[~2020-03-06 15:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-06  9:35 Cheng Jian
2020-03-06 15:21 ` Masami Hiramatsu [this message]
2020-03-07  2:16   ` chengjian (D)
2020-03-07  9:54     ` Masami Hiramatsu
2020-03-09  7:38       ` chengjian (D)

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=20200307002115.b96be2310cc553a922e1ba31@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=anil.s.keshavamurthy@intel.com \
    --cc=bobo.shaobowang@huawei.com \
    --cc=cj.chengjian@huawei.com \
    --cc=davem@davemloft.net \
    --cc=huawei.libin@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=naveen.n.rao@linux.ibm.com \
    --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®