Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3198415pxu; Tue, 15 Dec 2020 00:44:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJyfSHRfdxtFrS8URPh4u326+h7AdwRqzfS4s6OG5kaSbbdNN/9oyTW2TmKMgmlGz1XSNo1V X-Received: by 2002:a17:906:9613:: with SMTP id s19mr26105330ejx.351.1608021864951; Tue, 15 Dec 2020 00:44:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608021864; cv=none; d=google.com; s=arc-20160816; b=s2qaRFxagPsCCjCGd7IrQilY7oKVziYbJPe+7hehXRr1+FxzKnh2RlFHMCumgFjKWA Q4rumlY7iTN1q5a6Skg2RUQ4H5g1mxEaefbLEQt/D73HSbSS1q/WvpVqSR940mmXnNOx yUPv/2Y7EJF64kxJAUnP6VfloMrzAUSr4hGNSEkbH73HsluKfi/UeLVjC8X2w9nFSPfS UJioZbKvL6RDOG7KyHm63L4SLGjTstM879iQMcjXoowYj9wZv/BBrRVkNO6/tF055zAo jDdEHW7pstDS1OwKLUYA2zpuYrWupSKt+a53QzSP6YDVsa5N+55WGRj/2k3V2+RiiXWU DR5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=LGfjK0yQuZwQkLLEktDaPgrWT7FHhlIy4b5VWKW0BNc=; b=XsUQJbMturjFNWh9dLWOA45VQfFtV6AqMBhBNQVXzBLt0IH6igcOYqX8GYuMw6n7aE ZEFpFTcoBy/7YhU91hV2dOgboyPkBGlFrAu2JIMaIH3XBOl1/4yh7AwYhAd23E8C95L1 9ITBRZwK5ASjiNnT0vAY8wj1KAJPs7R16kcfmzPPxJL2uLufhmQTMWuSF13BW0FAsPqk Pg53g4n54u+iARoUmdZGsUqZYxgM9DJ/EuLFih8FnwxNmgFDDcSDXZcIHVsSH5LLLMjw vXrwgLkGYafLy/ualdCa7B54AZqnoEo6a3lMnXMnIPH8zKIPFuP2qbRFfzQ0lqx7BwUS vKOQ== 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 f7si525965ejx.294.2020.12.15.00.44.02; Tue, 15 Dec 2020 00:44:24 -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 S1726934AbgLOIki (ORCPT + 99 others); Tue, 15 Dec 2020 03:40:38 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:9205 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727030AbgLOIkZ (ORCPT ); Tue, 15 Dec 2020 03:40:25 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4CwBVz4RWmzkr5C; Tue, 15 Dec 2020 16:38:51 +0800 (CST) Received: from [10.174.178.52] (10.174.178.52) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.498.0; Tue, 15 Dec 2020 16:39:30 +0800 Subject: Re: [PATCH] kretprobe: avoid re-registration of the same kretprobe earlier To: Masami Hiramatsu CC: Steven Rostedt , , , , , , References: <20201124115719.11799-1-bobo.shaobowang@huawei.com> <20201130161850.34bcfc8a@gandalf.local.home> <20201202083253.9dbc76704149261e131345bf@kernel.org> <9dff21f8-4ab9-f9b2-64fd-cc8c5f731932@huawei.com> <20201215123119.35258dd5006942be247600db@kernel.org> From: "Wangshaobo (bobo)" Message-ID: <4b1db6c0-2ff3-f163-7d03-ebc594971005@huawei.com> Date: Tue, 15 Dec 2020 16:39:30 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.1.0 MIME-Version: 1.0 In-Reply-To: <20201215123119.35258dd5006942be247600db@kernel.org> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.52] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Masami, I will update and resend it soon Thank you -- ShaoBo 在 2020/12/15 11:31, Masami Hiramatsu 写道: > 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, >>> >>> >