From nobody Mon Nov 25 08:31:27 2024 Received: from cstnet.cn (smtp86.cstnet.cn [159.226.251.86]) (using TLSv1.2 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 543692F29 for ; Sat, 16 Nov 2024 10:50:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.226.251.86 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731754259; cv=none; b=PSCN3yOJNQIfRICT69z0PZrX4F/FJYt7Ds8dkE3R9ZjaHkYcuoLHasLdk7pNQW/I6/WBKwq5VBjJAH6heCLmtOkzi2i7B7dtv/R4drH/lSPpubcSW55B3ipxKovOUGr+BQMdC0JpfPV3e5CVhYQ/2yocUaBupjVLolMr4onF9E0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731754259; c=relaxed/simple; bh=BuB53FTJREEHwAeWK8MHYXH1B2OOiVw/eqOaaaJJMWg=; h=Date:From:To:Cc:Subject:Content-Type:MIME-Version:Message-ID; b=H8bShLRO5qilzsVvwxxfJqpakJUAJcqkTQCuusdlODnRMXaDlxX9tMl12QdcbE1qm7nFI3XiLZbc2h56Icd1egnbkH1VzQNRYXP2BJtEpJ4DpOi/dJQcUI8hUcBCIXK11VA1c6pmaPRAd7jLKYNS7Mrn5qvu2ev1to1tN9kP+eQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn; spf=pass smtp.mailfrom=iscas.ac.cn; arc=none smtp.client-ip=159.226.251.86 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iscas.ac.cn Received: from zhangkai$iscas.ac.cn ( [175.164.144.183] ) by ajax-webmail-APP-16 (Coremail) ; Sat, 16 Nov 2024 18:42:58 +0800 (GMT+08:00) Date: Sat, 16 Nov 2024 18:42:58 +0800 (GMT+08:00) X-CM-HeaderCharset: UTF-8 From: zhangkai@iscas.ac.cn To: Walmsley , Dabbelt , Ou , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] riscv: fix memory leakage in process_accumulated_relocations X-Priority: 3 X-Mailer: Coremail Webmail Server Version 2024.1-cmXT5 build 20240627(e6c6db66) Copyright (c) 2002-2024 www.mailtech.cn cnic.cn Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <35cab46a.6d145.19334919ed0.Coremail.zhangkai@iscas.ac.cn> X-Coremail-Locale: zh_CN X-CM-TRANSID: sQCowAC3vwczdzhn83MCAA--.31286W X-CM-SenderInfo: x2kd0wxndlqxpvfd2hldfou0/1tbiBgsDBmc36Uv1MQABs- X-Coremail-Antispam: 1Ur529EdanIXcx71UUUUU7IcSsGvfJ3iIAIbVAYjsxI4VWxJw CS07vEb4IE77IF4wCS07vE1I0E4x80FVAKz4kxMIAIbVAFxVCaYxvI4VCIwcAKzIAtYxBI daVFxhVjvjDU= Content-Type: text/plain; charset="utf-8" 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+0xf= 2/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); --=20 2.39.5