From patchwork Sat Nov 16 12:07:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: laokz X-Patchwork-Id: 13877565 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B94B7D68BEA for ; Sat, 16 Nov 2024 12:07:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Date:Cc:To:From:Subject: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=HqBrSGN4DHmyufgoNbrGOL2gIDnkNYSha8RJJoCYTlA=; b=WT2h5/9qOKlgxs BZhBFodQ8tRlfiYXrDosCTaaj8csjBn2OwRFpzXgWtlBbG7PBXnLh4j4pzxamP2NLQR5m6INZh0ds gDB+xDEjz+daTWl+DLKbR0Gn5mw+dWbdQR8TOJz00o2161I0UKdKHC1FrDCCdYLkULhhTriHaNyKE BbJxDA0I9Lz//HE8PZvMCzhdhgsqcY3RiOi31Au03lQGPiqxJwLqIayMODrqx0HOqRFP5ATjum7Gb RepY9pyGLzMzLYS29zBNOZZZJEBDWndYfIIk1urHyMzYldiYZv7Jtv1kgNeR7aIengQ4ZOgiblyIv fnfR/jT4AvNncFnJrwMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tCHaL-00000005XJH-29WL; Sat, 16 Nov 2024 12:07:29 +0000 Received: from smtp81.cstnet.cn ([159.226.251.81] helo=cstnet.cn) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tCHaI-00000005XIe-151Q for linux-riscv@lists.infradead.org; Sat, 16 Nov 2024 12:07:28 +0000 Received: from [192.168.2.4] (unknown [60.17.9.120]) by APP-03 (Coremail) with SMTP id rQCowADX34v2ijhnmFgAAw--.11080S2; Sat, 16 Nov 2024 20:07:18 +0800 (CST) Message-ID: Subject: [resend PATCH] riscv: fix memory leakage in process_accumulated_relocations From: laokz To: Walmsley , Dabbelt , Ou , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org Date: Sat, 16 Nov 2024 20:07:18 +0800 X-Priority: 1 User-Agent: Evolution 3.46.4-2 MIME-Version: 1.0 X-CM-TRANSID: rQCowADX34v2ijhnmFgAAw--.11080S2 X-Coremail-Antispam: 1UD129KBjvJXoW7urWxtw15Kr1fCw1rGFWUCFg_yoW8CFy5pr 1rGr1UGrW8Jr1kJF4Utw1kWryUGr1DCa17WF45JF1xJr13Jr1jvw1UXr1Fgrs8Jr48Jry7 Jr1UJr1jvryDJw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmSb7Iv0xC_KF4lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwV C2z280aVCY1x0267AKxVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVAC Y4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJV W8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lFcxC0VAYjxAxZF0Ew4CEw7xC 0wACY4xI67k04243AVC20s07MxkF7I0En4kS14v26r126r1DMxkIecxEwVAFwVW5JwCF04 k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18 MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr4 1lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1l IxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4 A2jsIEc7CjxVAFwI0_Gr0_Gr1UMs0E7xkvzxkvxsIE5cxS5wCE64xvF2IEb7IF0Fy7YxBI daVFxhVjvjDU0xZFpf9x07jfHUDUUUUU= X-Originating-IP: [60.17.9.120] X-CM-SenderInfo: x2kd0wxndlqxpvfd2hldfou0/ X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241116_040726_678161_8D1A0461 X-CRM114-Status: UNSURE ( 3.82 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Sorry for last weird email. --- When module relocation is done, process_accumulated_relocations() frees all dynamic allocated memory. rel_head_iter->rel_entry is missed to free that kmemleak might report: unreferenced object 0xffffffd880c5fc40 (size 16):   comm "insmod", pid 1101, jiffies 4295045138   hex dump (first 16 bytes):     e0 c0 f5 87 d8 ff ff ff 60 c5 f5 87 d8 ff ff ff  ........`.......   backtrace (crc d2ecb20c):     [<00000000b01655f6>] kmalloc_trace_noprof+0x268/0x2f6     [<000000006dc0067a>] add_relocation_to_accumulate.constprop.0+0xf2/0x1aa     [<00000000e1b29a36>] apply_relocate_add+0x13c/0x36e     [<000000007543f1fb>] load_module+0x5c6/0x83e     [<00000000abce12e8>] init_module_from_file+0x74/0xaa     [<0000000049413e3d>] idempotent_init_module+0x116/0x22e     [<00000000f9b98b85>] __riscv_sys_finit_module+0x62/0xae Signed-off-by: Kai Zhang ---  arch/riscv/kernel/module.c | 1 +  1 file changed, 1 insertion(+) diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index 1cd461f3d87..f8c3c4b47dc 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -643,6 +643,7 @@ process_accumulated_relocations(struct module *me,                         }                         reloc_handlers[curr_type].accumulate_handler(                                 me, location, buffer); +                       kfree(rel_head_iter->rel_entry);                         kfree(rel_head_iter);                 }                 kfree(bucket_iter);