Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3926632pxu; Mon, 30 Nov 2020 13:22:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJzgcmTz2+QBgd+FJ55RS92qXcZn2/gBbJCK/7xPX4zb766E2Heu1RRlRoX39UOznY4VF2xe X-Received: by 2002:a05:6402:22a3:: with SMTP id cx3mr4319063edb.375.1606771349786; Mon, 30 Nov 2020 13:22:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606771349; cv=none; d=google.com; s=arc-20160816; b=ye1UGnwGhvEw+HpPD58c2mmtsGTThCIGaU+EnpJqQ/ifMVm5Hn5tZ1GMatcNvWLRDC dSfgxkDP4up/YT/ERvSruFlQw+aLDcnPPQmis+Ez+8vBM9hsuHoVVMMGC0AXCgb3QW3V qzM+1OidcqgW0WapMMJEuBT6ft6jssvAL5VwlWBarysMYzXyV1pTWzbk+y20v5AdFriq Zgpl42pp/TTs6FBfD5cbl5ug58KhO6hQZDok0IeGCHPKg4Zkc2PrjaC6T4Kmz2O0QZP7 LKTJvfoOwPCxWCX08SoLOGsHQqUEojuJ7lfTGEVy5nJgYqL368QWsr7egQSs2PSzEBD1 U+hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=pkHiqyMhWktKC9y6S2Dk82cw2Qqefdv1q5y08vb2Ciw=; b=t4oE1uBjdF4e5fQEjvkKIMZAx07BDlFd55oaStcTAhx3xleS3oPembZ8pJsppxl8yx r+5VAJ9Jgr/pl1fI90sQuk3VEbTs9yUu/QPgK8voVEMll3AR8muFuMbI5eqwao9ferqt ZUYi97rQpyzJNTMjiJ477Z7D/LIXW+e7MqvQjryxwmcmvKqLGS/JKJoTNOVYPz1AdC/T sSXCpGLCyRc+MfqohYy+4AsWFMaQllO7lHJBTqgijdQpNmm8/lWupVavWQ3b0jLM//Gu Qf+Xtq6Jb2v5r9hqkpvJwrYZXWRQGvGwy6brRS3eMfwqLylJMiPFwx4NmiPAfWmNXMGi QruA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 63si12401090edl.54.2020.11.30.13.21.58; Mon, 30 Nov 2020 13:22:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388538AbgK3VTe (ORCPT + 99 others); Mon, 30 Nov 2020 16:19:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:39726 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387645AbgK3VTd (ORCPT ); Mon, 30 Nov 2020 16:19:33 -0500 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0A82C2076A; Mon, 30 Nov 2020 21:18:51 +0000 (UTC) Date: Mon, 30 Nov 2020 16:18:50 -0500 From: Steven Rostedt To: Masami Hiramatsu Cc: Wang ShaoBo , , , , , , Subject: Re: [PATCH] kretprobe: avoid re-registration of the same kretprobe earlier Message-ID: <20201130161850.34bcfc8a@gandalf.local.home> In-Reply-To: <20201124115719.11799-1-bobo.shaobowang@huawei.com> References: <20201124115719.11799-1-bobo.shaobowang@huawei.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Masami, Can you review this patch, and also, should this go to -rc and stable? -- Steve On Tue, 24 Nov 2020 19:57:19 +0800 Wang ShaoBo wrote: > Our system encountered a re-init error when re-registering same kretprobe, > where the kretprobe_instance in rp->free_instances is illegally accessed > after re-init. > > Implementation to avoid re-registration has been introduced for kprobe > before, but lags for register_kretprobe(). We must check if kprobe has > been re-registered before re-initializing kretprobe, otherwise it will > destroy the data struct of kretprobe registered, which can lead to memory > leak, system crash, also some unexpected behaviors. > > we use check_kprobe_rereg() to check if kprobe has been re-registered > before calling register_kretprobe(), for giving a warning message and > terminate registration process. > > Signed-off-by: Wang ShaoBo > Signed-off-by: Cheng Jian > --- > kernel/kprobes.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > index 41fdbb7953c6..7f54a70136f3 100644 > --- a/kernel/kprobes.c > +++ b/kernel/kprobes.c > @@ -2117,6 +2117,14 @@ int register_kretprobe(struct kretprobe *rp) > } > } > > + /* > + * Return error if it's being re-registered, > + * also give a warning message to the developer. > + */ > + ret = check_kprobe_rereg(&rp->kp); > + if (WARN_ON(ret)) > + return ret; > + > rp->kp.pre_handler = pre_handler_kretprobe; > rp->kp.post_handler = NULL; > rp->kp.fault_handler = NULL;