From nobody Fri Nov 22 10:25:36 2024 Received: from cstnet.cn (smtp81.cstnet.cn [159.226.251.81]) (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 A7F5D161 for ; Sat, 16 Nov 2024 12:13:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.226.251.81 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731759202; cv=none; b=KS+6tQd+BEDrJ7hfvAFC/neVjmpAtBOavAFJcObxPJohTRNesjoKc4ZSnnZOGrmCFvK5g9PU0TRDVSG7zGXyqjWZHGBKrDl4ym3d3GHYu/OTI89frDaLQ1KlvwSbzMQkBJq2O/14frQVR23dKhy/tEDzZqECqB3UXH+zxzwD65M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731759202; c=relaxed/simple; bh=JYMEaRjrLJZJp/WVYKY998cN7Lo7+syvrmumd73EB7M=; h=Message-ID:Subject:From:To:Cc:Date:Content-Type:MIME-Version; b=u8dT/YwnNiYTLrrx5X8N5mzxDGbpWLNjBLmkkt3erdhvMlhgxzSNAS6otCRFHShqBHfjUngI2uck+yh4XbZwpqFUqKqDmFlBzt7Zw7fq6rpItsKuRnDLiqacM+xNfoaL6i72Vj/sYyBBVU9AEKUJMlxPTSoQdTKFF98kC6RS1u0= 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.81 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 [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 Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4-2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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-CM-SenderInfo: x2kd0wxndlqxpvfd2hldfou0/ Content-Type: text/plain; charset="utf-8" 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): =C2=A0 comm "insmod", pid 1101, jiffies 4295045138 =C2=A0 hex dump (first 16 bytes): =C2=A0=C2=A0=C2=A0 e0 c0 f5 87 d8 ff ff ff 60 c5 f5 87 d8 ff ff ff=C2=A0 ..= ......`....... =C2=A0 backtrace (crc d2ecb20c): =C2=A0=C2=A0=C2=A0 [<00000000b01655f6>] kmalloc_trace_noprof+0x268/0x2f6 =C2=A0=C2=A0=C2=A0 [<000000006dc0067a>] add_relocation_to_accumulate.constprop.0+0xf2/0x1aa =C2=A0=C2=A0=C2=A0 [<00000000e1b29a36>] apply_relocate_add+0x13c/0x36e =C2=A0=C2=A0=C2=A0 [<000000007543f1fb>] load_module+0x5c6/0x83e =C2=A0=C2=A0=C2=A0 [<00000000abce12e8>] init_module_from_file+0x74/0xaa =C2=A0=C2=A0=C2=A0 [<0000000049413e3d>] idempotent_init_module+0x116/0x22e =C2=A0=C2=A0=C2=A0 [<00000000f9b98b85>] __riscv_sys_finit_module+0x62/0xae Signed-off-by: Kai Zhang --- =C2=A0arch/riscv/kernel/module.c | 1 + =C2=A01 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, =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 reloc_handl= ers[curr_type].accumulate_handler( =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 me, location, buffer); +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 kfree(rel_head= _iter->rel_entry); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 kfree(rel_h= ead_iter); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 kfree(bucket_iter);