mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Cheng Jian <cj.chengjian@huawei.com>
To: <linux-kernel@vger.kernel.org>
Cc: <cj.chengjian@huawei.com>, <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: [PATCH] kretprobe: check re-registration of the same kretprobe earlier
Date: Fri, 6 Mar 2020 17:35:06 +0800	[thread overview]
Message-ID: <1583487306-81985-1-git-send-email-cj.chengjian@huawei.com> (raw)

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.

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


             reply	other threads:[~2020-03-06  9:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-06  9:35 Cheng Jian [this message]
2020-03-06 15:21 ` Masami Hiramatsu
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=1583487306-81985-1-git-send-email-cj.chengjian@huawei.com \
    --to=cj.chengjian@huawei.com \
    --cc=anil.s.keshavamurthy@intel.com \
    --cc=bobo.shaobowang@huawei.com \
    --cc=davem@davemloft.net \
    --cc=huawei.libin@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@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®