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 53195C433EF for ; Wed, 25 May 2022 13:42:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244478AbiEYNmZ (ORCPT ); Wed, 25 May 2022 09:42:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236921AbiEYNmV (ORCPT ); Wed, 25 May 2022 09:42:21 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 970A6633B4 for ; Wed, 25 May 2022 06:42:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 589D4B81DA8 for ; Wed, 25 May 2022 13:42:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7707C385B8; Wed, 25 May 2022 13:42:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653486138; bh=2qPbWRcSRsl4LlFjbtIBkM7PQ9cUCKoA7Q1w7x4JsG8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=g32X/wmOcFhk3gydR4eQIpEK9yC6yh6BhsAwB+Bei9id1+rTaE0pBnl4YQ5zG9HAk uixuL892t//cAiE1g+7rsa8PXGaLIl9HJhNNQ8YJ7wJEFPF5/I/5x4MskCP//+h4/j +kCPBr20/Hcnvcbo/aUaWk7bZiKAJnHuBkEDt9QEXqZojmuaX92nJoQ37z0ua2T+el ZXDSEXU41qi/ofBq0EK5g4ct9JAYxs5NulkPjiB7D43V6DX/VDJP/w6ADMtTiX4Qw4 rXTBUN59EJEjQOphiuAgDBm12opD3Qd5kyKpWfbWf+/P6oLNcSsC29YTMiOOI/t5R5 2GdYKGZeq5i0w== Date: Wed, 25 May 2022 21:33:39 +0800 From: Jisheng Zhang To: Guo Ren Cc: Liao Chang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Masami Hiramatsu , Steven Rostedt , Peter Zijlstra , Naveen Rao , linux-riscv , Linux Kernel Mailing List Subject: Re: [PATCH v2] riscv/kprobe: reclaim insn_slot on kprobe unregistration Message-ID: References: <20220525014424.20717-1-liaochang1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 25, 2022 at 02:23:50PM +0800, Guo Ren wrote: > 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 Reviewed-by: Jisheng Zhang > > --- > > 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; > + } > } > > static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb) > > > } > > > > static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb) > > -- > > 2.17.1 > > > > > -- > Best Regards > Guo Ren > > ML: https://lore.kernel.org/linux-csky/