From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3CFDC433F5 for ; Wed, 25 May 2022 07:59:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234050AbiEYH7X (ORCPT ); Wed, 25 May 2022 03:59:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232164AbiEYH7S (ORCPT ); Wed, 25 May 2022 03:59:18 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C52E7CB4B for ; Wed, 25 May 2022 00:59:17 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4L7NkR2m1jzDqS5; Wed, 25 May 2022 15:59:11 +0800 (CST) Received: from [10.67.110.108] (10.67.110.108) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 25 May 2022 15:59:14 +0800 Message-ID: Date: Wed, 25 May 2022 15:59:14 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH v2] riscv/kprobe: reclaim insn_slot on kprobe unregistration To: Guo Ren CC: Paul Walmsley , Palmer Dabbelt , Albert Ou , Masami Hiramatsu , Steven Rostedt , Peter Zijlstra , Naveen Rao , , linux-riscv , Linux Kernel Mailing List References: <20220525014424.20717-1-liaochang1@huawei.com> From: "liaochang (A)" In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.110.108] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2022/5/25 14:23, Guo Ren 写道: > On Wed, May 25, 2022 at 9:46 AM Liao Chang wrote: >> >> On kprobe registration kernel allocate one insn_slot for new kprobe, >> but it forget to reclaim the insn_slot on unregistration, leading to a >> potential leakage. >> >> Reported-by: Chen Guokai >> Signed-off-by: Liao Chang >> --- >> v2: >> Add Reported-by tag >> >> arch/riscv/kernel/probes/kprobes.c | 4 ++++ >> 1 file changed, 4 insertions(+) >> >> diff --git a/arch/riscv/kernel/probes/kprobes.c b/arch/riscv/kernel/probes/kprobes.c >> index e6e950b7cf32..f12eb1fbb52c 100644 >> --- a/arch/riscv/kernel/probes/kprobes.c >> +++ b/arch/riscv/kernel/probes/kprobes.c >> @@ -110,6 +110,10 @@ void __kprobes arch_disarm_kprobe(struct kprobe *p) >> >> void __kprobes arch_remove_kprobe(struct kprobe *p) >> { >> + if (p->ainsn.api.insn) { >> + free_insn_slot(p->ainsn.api.insn, 0); >> + p->ainsn.api.insn = NULL; >> + } > Thx reviewed-by: Guo Ren > > You also could give a fixup patch to csky, thx: > > diff --git a/arch/csky/kernel/probes/kprobes.c > b/arch/csky/kernel/probes/kprobes.c > index 42920f25e73c..661da54b418f 100644 > --- a/arch/csky/kernel/probes/kprobes.c > +++ b/arch/csky/kernel/probes/kprobes.c > @@ -124,6 +124,10 @@ void __kprobes arch_disarm_kprobe(struct kprobe *p) > > void __kprobes arch_remove_kprobe(struct kprobe *p) > { > + if (p->ainsn.api.insn) { > + free_insn_slot(p->ainsn.api.insn, 0); > + p->ainsn.api.insn = NULL; > + } > } Sure, I will, thanks. > > static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb) > >> } >> >> static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb) >> -- >> 2.17.1 >> > > -- BR, Liao, Chang