Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1199014pxb; Thu, 28 Jan 2021 10:13:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJzyXEg0g+UkhZRJD4J1etV2dQa76GBNCTGL8zLkIS28KopzYdrUbaIpfh8sNDuZD8zaRhM4 X-Received: by 2002:a17:906:2c4e:: with SMTP id f14mr686233ejh.432.1611857581199; Thu, 28 Jan 2021 10:13:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611857581; cv=none; d=google.com; s=arc-20160816; b=GCu4gJ1syn26v98F+e7DaILmbYPawqmGgAWUGeWefGXdyuvE1gVZRS5iZ5wqDzuKG1 h2GVH66Up9r4PC85Ga3cfy/mzYcVO6Ugulnjz0AlHN2G40HY+vlWvf5+ZGcVxdLI3U0J aGdsmgw8IK2YMrccxv7GvZUyG2N5Dk69D3U++oPsHOusbOC1umpeDvFjavA6SgT/ostV SqDwElrCCuHdsaLvpZ4gdwF5i7PocGFVnYMy17LN977cpnpcjq6+wdnWs6cRjjnOMjmV 8AajZPfx4bi/5R8YGchZOiQvRg2F66fk0+GUnNaiG7Qh753Et/OJSv2d6cbIULhDLXe+ f0BA== 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=9uFn8efQS8b9UIfJDUEDXuLjCZvgdS58S1fnAYbd8Wk=; b=iByd6WxSLZIska3a0kdklE8CHIXtR7WXnE/5LEFFQwwzc63WwR0//WYW8rbFTmzh7A 5KZFA7b3hNQ8r1efWWNvn09mhok4j/izznEj31RU73xsg18Ut8E1TRxE36zQ1GOw+vI8 cmw5qhdR+DMe+AFacNnyjXUaMcafJ92eBpwkWv0z3+tVGB1sNWJN2TurCbiSrpIrySgN x3AMnmuTB3j1A+fyuvkpHjEI0jRMPcteXKH42k3cUCC4AvAL4HwKx8/lqa9O9GmYh4G/ 2dpbeXCRda+QDEEtdqoe1XjLTR1v0goOObUp4dCkIvDq9AF07uGsTULaYxq2GaxygtcT IilA== 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 dg6si3397788edb.485.2021.01.28.10.12.37; Thu, 28 Jan 2021 10:13:01 -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 S231847AbhA1SLa (ORCPT + 99 others); Thu, 28 Jan 2021 13:11:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:35626 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231678AbhA1SHE (ORCPT ); Thu, 28 Jan 2021 13:07:04 -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 3B10564E1D; Thu, 28 Jan 2021 18:06:23 +0000 (UTC) Date: Thu, 28 Jan 2021 13:06:21 -0500 From: Steven Rostedt To: Wang ShaoBo , Masami Hiramatsu Cc: , , , , , , Subject: Re: [PATCH v2] kretprobe: avoid re-registration of the same kretprobe earlier Message-ID: <20210128130621.41d99638@gandalf.local.home> In-Reply-To: <20210128124427.2031088-1-bobo.shaobowang@huawei.com> References: <20210128124427.2031088-1-bobo.shaobowang@huawei.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; 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, Care to review? Thanks! -- Steve On Thu, 28 Jan 2021 20:44:27 +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 running register_kretprobe()'s body, for giving a warning message > and terminate registration process. > > Signed-off-by: Wang ShaoBo > Signed-off-by: Cheng Jian > --- > kernel/kprobes.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > index f7fb5d135930..5c4a884953e9 100644 > --- a/kernel/kprobes.c > +++ b/kernel/kprobes.c > @@ -1978,6 +1978,10 @@ int register_kretprobe(struct kretprobe *rp) > if (!kprobe_on_func_entry(rp->kp.addr, rp->kp.symbol_name, rp->kp.offset)) > return -EINVAL; > > + /* If only rp->kp.addr is specified, check reregistering kprobes */ > + if (rp->kp.addr && check_kprobe_rereg(&rp->kp)) > + return -EINVAL; > + > if (kretprobe_blacklist_size) { > addr = kprobe_addr(&rp->kp); > if (IS_ERR(addr))