diff mbox series

ARM: module: Reclaim the unwind list of module on kmalloc failed

Message ID 20221103011713.138974-1-liaochang1@huawei.com (mailing list archive)
State New, archived
Headers show
Series ARM: module: Reclaim the unwind list of module on kmalloc failed | expand

Commit Message

Liao, Chang Nov. 3, 2022, 1:17 a.m. UTC
When unwind table allocation failed, it needs to reclaim the unwind list
of module to avoid potential NULL pointer exception and memory leakage.

Fixes: b6f21d14f1ac ("ARM: 9204/2: module: Add all unwind tables when load module")
Signed-off-by: Liao Chang <liaochang1@huawei.com>
Cc: Chen Zhongjin <chenzhongjin@huawei.com>
---
 arch/arm/kernel/module.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Chen Zhongjin Nov. 4, 2022, 9:47 a.m. UTC | #1
On 2022/11/3 9:17, Liao Chang wrote:
> When unwind table allocation failed, it needs to reclaim the unwind list
> of module to avoid potential NULL pointer exception and memory leakage.
>
> Fixes: b6f21d14f1ac ("ARM: 9204/2: module: Add all unwind tables when load module")
> Signed-off-by: Liao Chang <liaochang1@huawei.com>
> Cc: Chen Zhongjin <chenzhongjin@huawei.com>
> ---
>   arch/arm/kernel/module.c | 4 ++++
>   1 file changed, 4 insertions(+)
>
> diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
> index d59c36dc0494..cc637dcdcb10 100644
> --- a/arch/arm/kernel/module.c
> +++ b/arch/arm/kernel/module.c
> @@ -485,6 +485,10 @@ int module_finalize(const Elf32_Ehdr *hdr, const Elf_Shdr *sechdrs,
>   						s->sh_size,
>   						txt_sec->sh_addr,
>   						txt_sec->sh_size);
> +			if (!table) {
> +				module_arch_cleanup(mod);
> +				return -ENOMEM;
> +			}
>   
>   			list_add(&table->mod_list, unwind_list);
>   

Looks good to me.

Reviewed-by: Chen Zhongjin <chenzhongjin@huawei.com>


Thanks.
Linus Walleij Nov. 8, 2022, 2:05 p.m. UTC | #2
On Thu, Nov 3, 2022 at 2:20 AM Liao Chang <liaochang1@huawei.com> wrote:

> When unwind table allocation failed, it needs to reclaim the unwind list
> of module to avoid potential NULL pointer exception and memory leakage.
>
> Fixes: b6f21d14f1ac ("ARM: 9204/2: module: Add all unwind tables when load module")
> Signed-off-by: Liao Chang <liaochang1@huawei.com>
> Cc: Chen Zhongjin <chenzhongjin@huawei.com>

Looks good to me:
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Please put this into Russells patch tracker.

Yours,
Linus Walleij
diff mbox series

Patch

diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
index d59c36dc0494..cc637dcdcb10 100644
--- a/arch/arm/kernel/module.c
+++ b/arch/arm/kernel/module.c
@@ -485,6 +485,10 @@  int module_finalize(const Elf32_Ehdr *hdr, const Elf_Shdr *sechdrs,
 						s->sh_size,
 						txt_sec->sh_addr,
 						txt_sec->sh_size);
+			if (!table) {
+				module_arch_cleanup(mod);
+				return -ENOMEM;
+			}
 
 			list_add(&table->mod_list, unwind_list);