Skip to contentSkip to conversation

module: release codetag section when module load fails

PATCH Superseded David Wang 2 participants 6 messages May 18, 2025 – May 19, 2025 Module support

lore
Share & tools
lore

David Wang

author
#0 lore raw

PATCH 1/1 module: release codetag section when module load fails

When module load failed after memory for codetag sections ready, codetag section memory was not properly released. This causes memory leak, and if next module load happens to got the same module address, codetag may pick the uninitialized section when manipulating tags during module unload, and lead to "unable to handle page fault" BUG.

---
 kernel/module/main.c | 1 +
 1 file changed, 1 insertion(+)
kernel/module/main.c +1 -0
index a2859dc3eea6..5c6ab20240a6 100644
@@ -2829,6 +2829,7 @@ static void module_deallocate(struct module *mod, struct load_info *info)
 {
 	percpu_modfree(mod);
 	module_arch_freeing_init(mod);
+	codetag_free_module_sections(mod);
 
 	free_mod_mem(mod);
 }
Signature · 1 line
2.39.2
Acked-by on v1 1/1
#1 lore raw
Quoted 2 lines · David Wang

When module load failed after memory for codetag sections ready,

nit: s/ready/is ready

Quoted 2 lines

codetag section memory was not properly released. This causes memory leak, and if next module load happens to got the

nit: s/happens to got/happens to get

Quoted 6 lines

same module address, codetag may pick the uninitialized section when manipulating tags during module unload, and lead to "unable to handle page fault" BUG.

Quoted 19 lines
---
 kernel/module/main.c | 1 +
 1 file changed, 1 insertion(+)
kernel/module/main.c +1 -1
index a2859dc3eea6..5c6ab20240a6 100644
@@ -2829,6 +2829,7 @@ static void module_deallocate(struct module *mod, struct load_info *info)
 {
        percpu_modfree(mod);
        module_arch_freeing_init(mod);
+       codetag_free_module_sections(mod);
 
        free_mod_mem(mod);
 }
--

2.39.2

author
#2 lore raw
Quoted 11 lines · Suren Baghdasaryan
Quoted 2 lines · David Wang

When module load failed after memory for codetag sections ready,

nit: s/ready/is ready

Quoted 2 lines

codetag section memory was not properly released. This causes memory leak, and if next module load happens to got the

nit: s/happens to got/happens to get

Thanks, I will send new version.

Quoted 29 lines
Quoted 7 lines

same module address, codetag may pick the uninitialized section when manipulating tags during module unload, and lead to "unable to handle page fault" BUG.

Quoted 19 lines
---
 kernel/module/main.c | 1 +
 1 file changed, 1 insertion(+)
kernel/module/main.c +1 -1
index a2859dc3eea6..5c6ab20240a6 100644
@@ -2829,6 +2829,7 @@ static void module_deallocate(struct module *mod, struct load_info *info)
 {
        percpu_modfree(mod);
        module_arch_freeing_init(mod);
+       codetag_free_module_sections(mod);
 
        free_mod_mem(mod);
 }
--

2.39.2

author
#3 lore raw

PATCH v2 1/1 module: release codetag section when module load fails

In reply to David Wang

When module load fails after memory for codetag section is ready, codetag section memory will not be properly released. This causes memory leak, and if next module load happens to get the same module address, codetag may pick the uninitialized section when manipulating tags during module unload, and leads to "unable to handle page fault" BUG.

---
 kernel/module/main.c | 1 +
 1 file changed, 1 insertion(+)
kernel/module/main.c +1 -0
index a2859dc3eea6..5c6ab20240a6 100644
@@ -2829,6 +2829,7 @@ static void module_deallocate(struct module *mod, struct load_info *info)
 {
 	percpu_modfree(mod);
 	module_arch_freeing_init(mod);
+	codetag_free_module_sections(mod);
 
 	free_mod_mem(mod);
 }
Signature · 1 line
2.39.2
#4 lore raw
Quoted 11 lines · David Wang

When module load fails after memory for codetag section is ready, codetag section memory will not be properly released. This causes memory leak, and if next module load happens to get the same module address, codetag may pick the uninitialized section when manipulating tags during module unload, and leads to "unable to handle page fault" BUG.

Sending to Andrew for adding into the mm tree.

Quoted 19 lines
---
 kernel/module/main.c | 1 +
 1 file changed, 1 insertion(+)
kernel/module/main.c +1 -1
index a2859dc3eea6..5c6ab20240a6 100644
@@ -2829,6 +2829,7 @@ static void module_deallocate(struct module *mod, struct load_info *info)
 {
        percpu_modfree(mod);
        module_arch_freeing_init(mod);
+       codetag_free_module_sections(mod);
 
        free_mod_mem(mod);
 }
--

2.39.2

#5 lore raw
Quoted 10 lines · Suren Baghdasaryan
Quoted 8 lines · David Wang

When module load fails after memory for codetag section is ready, codetag section memory will not be properly released. This causes memory leak, and if next module load happens to get the same module address, codetag may pick the uninitialized section when manipulating tags during module unload, and leads to "unable to handle page fault" BUG.

Fixes 0db6f8d7820a ("alloc_tag: load module tags into separate

contiguous memory")

Quoted 25 lines
Quoted 3 lines

Sending to Andrew for adding into the mm tree.

Quoted 19 lines
---
 kernel/module/main.c | 1 +
 1 file changed, 1 insertion(+)
kernel/module/main.c +1 -1
index a2859dc3eea6..5c6ab20240a6 100644
@@ -2829,6 +2829,7 @@ static void module_deallocate(struct module *mod, struct load_info *info)
 {
        percpu_modfree(mod);
        module_arch_freeing_init(mod);
+       codetag_free_module_sections(mod);
 
        free_mod_mem(mod);
 }
--

2.39.2