Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3305809lfo; Mon, 23 May 2022 01:13:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjQpGqRG6ubGhHZ+TvZWmeJQJTnIpPNb3Y4X7jQJYojre8HXUKTm9nL0AxutFx/FpTkwik X-Received: by 2002:a63:8bc1:0:b0:3f9:f00b:f877 with SMTP id j184-20020a638bc1000000b003f9f00bf877mr8726925pge.378.1653293618639; Mon, 23 May 2022 01:13:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653293618; cv=none; d=google.com; s=arc-20160816; b=pj9AYzWSeBd99P/p5OMClK7wGfuNfdrEf/IZMrCc8+JYYv0C8DmMzWzpxrZW94r+l0 uCnKhpRKq1t0dB5SUSvsH+8oi4nna9OwPR8piKclvmP4JW+BLFNgnZotPpjcbFMsEc7h jnbOvVyR1svzPTSwXIWTBRLAosMzaWEJGLxTq5oOCdfuXRAV0PLYKA6hR9CSmmB3wji+ HzGqKtuSdPn4dGdar6yOCENVkmpTuCffZuXwhWgrH/ELmvuT6Gs6lD4zm4xYRNLSSY9m HAKUFns8lLXZXFwNbRsTxm6BGQpyOGnrhCCfVaWB+VVgQub0FdkntlqN3duDl+1s0Ojr 0dLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=vvsmHUzluvEvQBof5D87XgRf+T6x1OltD2M2UVNj7M0=; b=Ckrwu2+tNqkd7YqR4I9aeNEWvcocXSbRTS+rf2kI45fZqgZbOeIoI2Mr5JTAEy4zch juKekRQ5P73QlPamrK1SHjAa0Kw/Zy5vd407VnCc54s8VDBkk5oPUhV7yPzWYNPUh6nt oqs7gEi5C1gXR0SsLSsLIN1byaUlOzGayd8jngZpFrJhPNs0PLSxOeyAY28E5StnjcRX ZgPxpJbp1lihnukUZZr1fhy3+5M/XjGPL0XMGXLnZQi59DU80RW8uIgm3aOqurbHJfyy Fnq4JSfFUmg1BLEcGRHzJjWS+1iopNjzuoU5u0DQm3/GeNXRq9NNZn0JezugaW3X8DII KLIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i9-20020a17090332c900b0015872dc578csi10388571plr.311.2022.05.23.01.13.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 01:13:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DAB166D4DC; Mon, 23 May 2022 00:08:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352023AbiEWBxF (ORCPT + 99 others); Sun, 22 May 2022 21:53:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233570AbiEWBxD (ORCPT ); Sun, 22 May 2022 21:53:03 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81AD62F3A8 for ; Sun, 22 May 2022 18:53:02 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4L60dQ1VpczQk9Y; Mon, 23 May 2022 09:50:02 +0800 (CST) Received: from huawei.com (10.67.174.53) 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; Mon, 23 May 2022 09:53:00 +0800 From: Liao Chang To: , , , , , , , , CC: , Subject: [PATCH] riscv/kprobe: reclaim insn_slot on kprobe unregistration Date: Mon, 23 May 2022 09:51:24 +0800 Message-ID: <20220523015124.98743-1-liaochang1@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.174.53] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. This bug reported by Chen Guokai . 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