Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3058963pxu; Mon, 14 Dec 2020 19:34:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJyuoSjoXB6tj5yZujPENJaeq1JUHtorjJhH+XIWV1u5WiYYKfploSHK50R2NjG1SQuA2HPV X-Received: by 2002:a17:906:74d9:: with SMTP id z25mr7470652ejl.217.1608003290992; Mon, 14 Dec 2020 19:34:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608003290; cv=none; d=google.com; s=arc-20160816; b=xG5KEL35BOVPynlz5m4dQpBVheK7mKWyWFYSqBdOEaM4inPQaC0ztK7xR1WND9qFki yEpbKB0SnooaOEikXSp9LD8qmNOCm14joJJ+nlDPuY58jM3dPS7jBSZvtG2WSHif0Yhr oihNMuXRnWSTm4ZMiKOUe98EFjMKEbW/6TIUliFziYWRm3aMKSuLiCFIBRHaAzuEtQRs 0w4EvwVUZFGL6dmETjc4V65NuaVJV/LbX8rm9yB9T6KjJwMzKLPbgCqjwjgeEIDcVH4T V/v5Egkyw9QVAXmk4WRpJbcqWcNb+U+PU8ZfXMFSUGwWdgwUn4UCxNi+5md8vHVp9R10 V7gQ== 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:dkim-signature :date; bh=vhOg9d7abLZo7EderB0jw4NDHO51zT4LuDzY4dJBw0E=; b=H34VsGWZ8JwVi3DIFlI+OFXjmdLXUQjNkjzxna3Mwv8Zu/2nghGvtPV+Ov91wOkEoM +jgnWhnu/N6eBgDYjVELAnP/pQtM6mAKa9x0qyKlsTBLURqfFvpqprZDLODqrCudV3X+ r+iDahN4J+BzPNnBI0UO9ulbqPTwOwR7WFqH082RflNjVrsEGJbvy7182OFHzXE6+WRj 97d0vpQPU+N/KIBT455W7rcRIBxlzNuDifu9AcDa+hbQHFI20nh94f1v75Qqb3Pa20Hl 1dukrTbR0hJOc4PKNmY1leFkj3TvsycmezfyQXujl00yAWk0hhBLy/tCKm5mIL8cwuRN aWcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=q34xaiCn; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eb6si186257edb.497.2020.12.14.19.34.26; Mon, 14 Dec 2020 19:34:50 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=q34xaiCn; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726760AbgLODcN (ORCPT + 99 others); Mon, 14 Dec 2020 22:32:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:46460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726572AbgLODcE (ORCPT ); Mon, 14 Dec 2020 22:32:04 -0500 Date: Tue, 15 Dec 2020 12:31:19 +0900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1608003083; bh=C6IzPjA0W0Rh2okIUI847AeqqYbJr3CHNG/+eSplB0M=; h=From:To:Cc:Subject:In-Reply-To:References:From; b=q34xaiCnitoWAlnCwhjJAQxt2+CVSc3/FLqfdpCaJJEVaYDseAsZ7SE69tmk4pNlQ sMyZeUoEcsbFTMj1kK9sWlslqnEO7bX0xfkawd2772lBNT3JsY8vkEGJ1et709MLqT bRKYdFrni79MJcp6JFYSg9UiMd34f7S90YfvY+4QvdHF03w8nvdlFRYzYhGTBuNkWV 6NyAQXM0sAPdQsaZwlDy8wd5hkGknG4tuGKLNu2ueyFeYG0hPbMgJwFXdT0Kdbc9pl 3BDXK3Cy15lhtwoPWqO8/eclXODDM9ongH7tK+M95b3dTJ2hooeLNygfXE0i4cQuE+ Y5M4WwH3G3MNg== From: Masami Hiramatsu To: "Wangshaobo (bobo)" Cc: Steven Rostedt , , , , , , Subject: Re: [PATCH] kretprobe: avoid re-registration of the same kretprobe earlier Message-Id: <20201215123119.35258dd5006942be247600db@kernel.org> 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: Sylpheed 3.7.0 (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 Hi ShaoBo, 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. > Can you update your patch and resend it? Thank you, > -- ShaoBo > > 在 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, > > > > -- Masami Hiramatsu