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 8D8C0C433F5 for ; Wed, 25 May 2022 01:24:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243187AbiEYBYj (ORCPT ); Tue, 24 May 2022 21:24:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235409AbiEYBYi (ORCPT ); Tue, 24 May 2022 21:24:38 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8D8A6A071 for ; Tue, 24 May 2022 18:24:37 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4L7Cvg4y4WzQkDn; Wed, 25 May 2022 09:21:35 +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 09:24:35 +0800 Message-ID: <6c692ace-9902-e11f-21c2-ef464be4d3c6@huawei.com> Date: Wed, 25 May 2022 09:24:15 +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] riscv/kprobe: reclaim insn_slot on kprobe unregistration To: Jisheng Zhang , Guo Ren CC: , , , , , , , , References: <20220523015124.98743-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: dggems701-chm.china.huawei.com (10.3.19.178) 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/24 23:12, Jisheng Zhang 写道: > On Mon, May 23, 2022 at 09:51:24AM +0800, 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. > > + Guo Ren > > Nice catch! I think csky needs the fix as well. > >> >> This bug reported by Chen Guokai . > > This needs a "Reported-by: ..." tag Thanks for comment. > >> >> Signed-off-by: Liao Chang >> --- >> 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; >> + } >> } >> >> static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb) >> -- >> 2.17.1 >> >> >> _______________________________________________ >> linux-riscv mailing list >> linux-riscv@lists.infradead.org >> http://lists.infradead.org/mailman/listinfo/linux-riscv > . -- BR, Liao, Chang