mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: zhangkai@iscas.ac.cn
To: Walmsley <paul.walmsley@sifive.com>, Dabbelt <palmer@dabbelt.com>,
	 Ou <aou@eecs.berkeley.edu>,
	linux-riscv@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] riscv: fix memory leakage in process_accumulated_relocations
Date: Sat, 16 Nov 2024 18:42:58 +0800 (GMT+08:00)	[thread overview]
Message-ID: <35cab46a.6d145.19334919ed0.Coremail.zhangkai@iscas.ac.cn> (raw)

When module relocation is done, process_accumulated_relocations()
frees all dynamic allocated memory. rel_head_iter-&gt;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):
    [&lt;00000000b01655f6&gt;] kmalloc_trace_noprof+0x268/0x2f6
    [&lt;000000006dc0067a&gt;] add_relocation_to_accumulate.constprop.0+0xf2/0x1aa
    [&lt;00000000e1b29a36&gt;] apply_relocate_add+0x13c/0x36e
    [&lt;000000007543f1fb&gt;] load_module+0x5c6/0x83e
    [&lt;00000000abce12e8&gt;] init_module_from_file+0x74/0xaa
    [&lt;0000000049413e3d&gt;] idempotent_init_module+0x116/0x22e
    [&lt;00000000f9b98b85&gt;] __riscv_sys_finit_module+0x62/0xae

Signed-off-by: Kai Zhang <zhangkai@iscas.ac.cn>
---
 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-&gt;rel_entry);
                        kfree(rel_head_iter);
                }
                kfree(bucket_iter);
-- 
2.39.5

</zhangkai@iscas.ac.cn>

             reply	other threads:[~2024-11-16 10:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-16 10:42 zhangkai [this message]
2024-11-19 16:57 ` Clément Léger
2024-11-20 14:23   ` laokz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=35cab46a.6d145.19334919ed0.Coremail.zhangkai@iscas.ac.cn \
    --to=zhangkai@iscas.ac.cn \
    --cc=aou@eecs.berkeley.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®