Skip to content

Conversation

@modules-kpd-app
Copy link

Pull request for series with
subject: module: Fix memory deallocation on error path in move_module()
version: 2
url: https://patchwork.kernel.org/project/linux-modules/list/?series=973425

dkruces and others added 3 commits June 25, 2025 13:39
The function move_module() uses the variable t to track how many memory
types it has allocated and consequently how many should be freed if an
error occurs.

The variable is initially set to 0 and is updated when a call to
module_memory_alloc() fails. However, move_module() can fail for other
reasons as well, in which case t remains set to 0 and no memory is freed.

Fix the problem by initializing t to MOD_MEM_NUM_TYPES. Additionally, make
the deallocation loop more robust by not relying on the mod_mem_type_t enum
having a signed integer as its underlying type.

Fixes: c7ee8ae ("module: add stop-grap sanity check on module memcpy()")
Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
Reviewed-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Daniel Gomez <da.gomez@samsung.com>
All error conditions in move_module() set the return value by updating the
ret variable. Therefore, it is not necessary to the initialize the variable
when declaring it.

Remove the unnecessary initialization.

Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
Reviewed-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Daniel Gomez <da.gomez@samsung.com>
@modules-kpd-app
Copy link
Author

Upstream branch: a0b018a
series: https://patchwork.kernel.org/project/linux-modules/list/?series=973425
version: 2

@dkruces dkruces force-pushed the modules-next_base branch from 6a1a12c to 7c2b408 Compare June 26, 2025 12:20
@modules-kpd-app modules-kpd-app bot force-pushed the modules-next_base branch 2 times, most recently from 6381fa5 to aaa7ece Compare June 26, 2025 18:03
@dkruces dkruces force-pushed the modules-next_base branch 2 times, most recently from b4d1c4e to 61dc34e Compare July 4, 2025 19:48
@modules-kpd-app modules-kpd-app bot force-pushed the modules-next_base branch 2 times, most recently from 1df8185 to 9aab33d Compare July 8, 2025 19:00
@dkruces dkruces force-pushed the modules-next_base branch from 9aab33d to 99d099e Compare July 8, 2025 19:46
@modules-kpd-app modules-kpd-app bot force-pushed the modules-next_base branch from 99d099e to 3aed49d Compare July 8, 2025 19:56
@modules-kpd-app modules-kpd-app bot force-pushed the modules-next_base branch 3 times, most recently from 0299e02 to cdc6b9e Compare October 22, 2025 10:27
@modules-kpd-app
Copy link
Author

Upstream branch: 5eb4b9a
series: https://patchwork.kernel.org/project/linux-modules/list/?series=973425
version: 2

Pull request is NOT updated. Failed to apply https://patchwork.kernel.org/project/linux-modules/list/?series=973425
error message:

Cmd('git') failed due to: exit code(128)
  cmdline: git am --3way
  stdout: 'Applying: module: Fix memory deallocation on error path in move_module()
Using index info to reconstruct a base tree...
M	kernel/module/main.c
Falling back to patching base and 3-way merge...
Auto-merging kernel/module/main.c
CONFLICT (content): Merge conflict in kernel/module/main.c
Patch failed at 0001 module: Fix memory deallocation on error path in move_module()'
  stderr: 'error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"'

conflict:

diff --cc kernel/module/main.c
index c66b26184936,9ac994b2f354..000000000000
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@@ -2723,8 -2696,9 +2723,14 @@@ static int find_module_sections(struct 
  
  static int move_module(struct module *mod, struct load_info *info)
  {
++<<<<<<< HEAD
 +	int i, ret;
 +	enum mod_mem_type t = MOD_MEM_NUM_TYPES;
++=======
+ 	int i;
+ 	enum mod_mem_type t = MOD_MEM_NUM_TYPES;
+ 	int ret = -ENOMEM;
++>>>>>>> module: Fix memory deallocation on error path in move_module()
  	bool codetag_section_found = false;
  
  	for_each_mod_mem_type(type) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants