Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2761688pxu; Mon, 14 Dec 2020 10:14:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJxnl7DrXzaSNH0JUXIjyUoC/27WH9RaZLfygh8hX6SVo5pCh4mkmJTdtVj1Rf+qA+amgyOJ X-Received: by 2002:aa7:c919:: with SMTP id b25mr25259360edt.108.1607969678163; Mon, 14 Dec 2020 10:14:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607969678; cv=none; d=google.com; s=arc-20160816; b=tCaGIjYQpGJEtiTzcX0e+v4ukQV9ex8R5nTADUQYjR6SE7wGfaosEDq3TjGsL75kSC iQPusc1O4BxjqQfxmajUX0NtRjwgzWFdWSaJ8lIjeiAZuHha6v+c/WZZzSkodfWDTbuM 4RWOq9zcGorZDKTgiSbqRrX/vvJ+CTvom/uSMwWsVnB5VGYByL9FnDl9SFGwrinQd9xb xS7hf00L+SaEnYM8ddcPheF4/CcAoaquRHx5fgxamBeAPQoIuplenPPHVOsS9EtZcx+z 4RW3I0c2yuHg3G7FsNb0FeL8tIIwlQr7NrI3oRwFJD6qzC1FoIjyNKcLn7ejLA1ITUAQ yw8w== 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=Tb8Ye0DjmN8y2oqr3rmLZeBWn9eXYGGcSucQGjAN93s=; b=LCTChCarysPwv0DPefvsE4LZcCiZbHpVKYq+SA0hlCYiVuy4Vq2En/9QduN4kR7u7H Q3ychSpNJB0GhENCT2kJZLyEtkyHICcBG6R3AzKgpn0l8Vc2IYXbFDv1KEabC7pvBhcr Y1p1moMgN8RFj06R/IkR0QEQRBm78cvm/3oo6eOSUbe/i0alrVqFIivml6uFjh///4d7 GLJdaqOpkzx2Hki52QPG6gRn/Pb2XCHRuX6k8LHQrxsblq/MWKwaNS8L4byUWe9srXTi 3cNKaPcvLOpnkl61yAvHTTsxRIzOuiHBxrbX57fWFAhXwRkeeYROtK5vvqB4c5mNsdWf tN7w== 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 dd1si10206765ejb.357.2020.12.14.10.14.10; Mon, 14 Dec 2020 10:14:38 -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 S2440149AbgLNQhe convert rfc822-to-8bit (ORCPT + 99 others); Mon, 14 Dec 2020 11:37:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:42434 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2440068AbgLNQhe (ORCPT ); Mon, 14 Dec 2020 11:37:34 -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 F364222286; Mon, 14 Dec 2020 16:36:52 +0000 (UTC) Date: Mon, 14 Dec 2020 11:36:51 -0500 From: Steven Rostedt To: "Wangshaobo (bobo)" Cc: Masami Hiramatsu , , , , , , Subject: Re: [PATCH] kretprobe: avoid re-registration of the same kretprobe earlier Message-ID: <20201214113651.04e550f6@gandalf.local.home> In-Reply-To: <9dff21f8-4ab9-f9b2-64fd-cc8c5f731932@huawei.com> References: <20201124115719.11799-1-bobo.shaobowang@huawei.com> <20201130161850.34bcfc8a@gandalf.local.home> <20201202083253.9dbc76704149261e131345bf@kernel.org> <9dff21f8-4ab9-f9b2-64fd-cc8c5f731932@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=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2 Dec 2020 09:23:35 +0800 "Wangshaobo (bobo)" wrote: > Hi steve, Masami, > > Thanks for your works, i will check code again and modify properly > according to steve's suggestion. > > -- ShaoBo > Anything happen with this? -- Steve > 在 2020/12/2 7:32, Masami Hiramatsu 写道: > > On Mon, 30 Nov 2020 16:18:50 -0500 > > Steven Rostedt wrote: > > > >> Masami, > >> > >> Can you review this patch, and also, should this go to -rc and stable? > >> > >> -- Steve > > Thanks for ping me! > > > >> 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. > > Ah, OK. Anyway if re-register happens on kretprobe, it must lose instances > > on the list before checking re-register in register_kprobe(). > > So the idea looks good to me. > > > > > >>> 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; > > If you call this here, you must make sure kprobe_addr() is called on rp->kp. > > But if kretprobe_blacklist_size == 0, kprobe_addr() is not called before > > this check. So it should be in between kprobe_on_func_entry() and > > kretprobe_blacklist_size check, like this > > > > if (!kprobe_on_func_entry(rp->kp.addr, rp->kp.symbol_name, rp->kp.offset)) > > return -EINVAL; > > > > addr = kprobe_addr(&rp->kp); > > if (IS_ERR(addr)) > > return PTR_ERR(addr); > > rp->kp.addr = addr; > > > > ret = check_kprobe_rereg(&rp->kp); > > if (WARN_ON(ret)) > > return ret; > > > > if (kretprobe_blacklist_size) { > > for (i = 0; > > + ret = check_kprobe_rereg(&rp->kp); > > > > > > Thank you, > > > >