From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from azure-sdnproxy.icoremail.net (azure-sdnproxy.icoremail.net [4.193.249.245]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D80D38E8BC for ; Wed, 5 Aug 2026 08:23:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.193.249.245 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785918194; cv=none; b=ZmbiIHXYKEt1uNyXVwMQTEqvK8XobFkXmYRBaaVV8bGGWRL48KerU0hhGWp8o+3jaM4PuDe6/blH4CBAeRg7IXmCQf45ShmY1eXK27NVja8LuN15jk8RL7HrnS5UnIxnCkS7xBvf95qbZ7ujpohROPo//2CCNuceLMQ2l3rHdiE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785918194; c=relaxed/simple; bh=0ISCukku4SForoWS1LobVVCNuyIFX0BLZPv+7cOmsq0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cKaX/rNEJwW6pBv5csy+yt4shgzduHfLlL7KSI6rPmLl41KWzrboizNRDLUptNpyDheYx37jn6ZPpA3HFYENZWeUDbsoapBXd5UgbqwzXLyUFFSIRGEOl1WLzRcjqsuqUZr71dKfgARtuUxys1S4QwJ3zYF64LNmAHBHW8b9Ix4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=eswincomputing.com; spf=pass smtp.mailfrom=eswincomputing.com; arc=none smtp.client-ip=4.193.249.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=eswincomputing.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=eswincomputing.com Received: from E0002472LT.eswin.cn (unknown [10.12.96.78]) by app1 (Coremail) with SMTP id TAJkCgCXKW7p8nJqxQI5AA--.6568S2; Wed, 05 Aug 2026 16:23:06 +0800 (CST) From: Xiaofeng Yuan To: linux-kernel@vger.kernel.org Cc: yuanxiaofeng@eswincomputing.com Subject: [PATCH] riscv: kprobes: free insn slot in arch_remove_kprobe() to avoid memory leak Date: Wed, 5 Aug 2026 16:23:02 +0800 Message-Id: <20260805082302.670-1-yuanxiaofeng@eswincomputing.com> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20260731100940.2330-1-yuanxiaofeng@eswincomputing.com> References: <20260731100940.2330-1-yuanxiaofeng@eswincomputing.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:TAJkCgCXKW7p8nJqxQI5AA--.6568S2 X-Coremail-Antispam: 1UD129KBjvdXoWrZF4DZF1xWFyDXr4UWr18AFb_yoWDKrc_C3 4ftryFgrWY9FWDWFy7Kw4rtrsIk3yfKFn5Wr1aqFy5tFy7J3W5KFsYgr1UJ3s7WrZ7JFy3 A3sxurWYqF12vjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUb7AFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_ Gr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s 0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xII jxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr 1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkIecxEwVCm-wCF04k2 0xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI 8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij64vIr41l IxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIx AIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2 jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7VUbrMaUUUUUU== X-CM-SenderInfo: h1xd05xldrwv1qj6v25zlqu0xpsx3x1qjou0bp/1tbiAgEKE2pyFJ4S5QAAs- When a kprobe is removed, arch_remove_kprobe() does not free the instruction slot allocated by arch_prepare_kprobe(). This causes a memory leak every time a kprobe is unregistered. Other architectures such as arm64, x86, and powerpc all free the slot in their arch_remove_kprobe() implementations. Add the missing free_insn_slot() call for RISC-V. Signed-off-by: Xiaofeng Yuan --- 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 9e2afabf94..a76eab2972 100644 --- a/arch/riscv/kernel/probes/kprobes.c +++ b/arch/riscv/kernel/probes/kprobes.c @@ -128,6 +128,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.43.0