]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
riscv: Fix module loading free order
authorCharlie Jenkins <charlie@rivosinc.com>
Thu, 4 Jan 2024 19:42:47 +0000 (11:42 -0800)
committerPalmer Dabbelt <palmer@rivosinc.com>
Wed, 10 Jan 2024 14:48:11 +0000 (06:48 -0800)
Reverse order of kfree calls to resolve use-after-free error.

Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
Fixes: d8792a5734b0 ("riscv: Safely remove entries from relocation list")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/r/202312132019.iYGTwW0L-lkp@intel.com/
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Julia Lawall <julia.lawall@inria.fr>
Closes: https://lore.kernel.org/r/202312120044.wTI1Uyaa-lkp@intel.com/
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/20240104-module_loading_fix-v3-1-a71f8de6ce0f@rivosinc.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/kernel/module.c

index aac019ed63b1bdaa766262a5266deb4c8c5a4bdf..21c7a773a8efa9db0cad8cd93604f891393731d8 100644 (file)
@@ -723,8 +723,8 @@ static int add_relocation_to_accumulate(struct module *me, int type,
 
                        if (!bucket) {
                                kfree(entry);
-                               kfree(rel_head);
                                kfree(rel_head->rel_entry);
+                               kfree(rel_head);
                                return -ENOMEM;
                        }