Patch "riscv: Correctly free relocation hashtable on error" has been added to the 6.7-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    riscv: Correctly free relocation hashtable on error

to the 6.7-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     riscv-correctly-free-relocation-hashtable-on-error.patch
and it can be found in the queue-6.7 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit f8d8ea62f8b0302156bc87502202c0094bce6c6e
Author: Charlie Jenkins <charlie@xxxxxxxxxxxx>
Date:   Thu Jan 4 11:42:48 2024 -0800

    riscv: Correctly free relocation hashtable on error
    
    [ Upstream commit 4b38b36bfbd83b23e20c172d08dd85773791e3bd ]
    
    When there is not enough allocatable memory for the relocation
    hashtable, module loading should exit gracefully. Previously, this was
    attempted to be accomplished by checking if an unsigned number is less
    than zero which does not work. Instead have the caller check if the
    hashtable was correctly allocated and add a comment explaining that
    hashtable_bits that is 0 is valid.
    
    Signed-off-by: Charlie Jenkins <charlie@xxxxxxxxxxxx>
    Fixes: d8792a5734b0 ("riscv: Safely remove entries from relocation list")
    Reported-by: kernel test robot <lkp@xxxxxxxxx>
    Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
    Closes: https://lore.kernel.org/r/202312132019.iYGTwW0L-lkp@xxxxxxxxx/
    Reported-by: kernel test robot <lkp@xxxxxxxxx>
    Reported-by: Julia Lawall <julia.lawall@xxxxxxxx>
    Closes: https://lore.kernel.org/r/202312120044.wTI1Uyaa-lkp@xxxxxxxxx/
    Reviewed-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20240104-module_loading_fix-v3-2-a71f8de6ce0f@xxxxxxxxxxxx
    Signed-off-by: Palmer Dabbelt <palmer@xxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c
index 5cf3a693482d..91f7cd221afc 100644
--- a/arch/riscv/kernel/module.c
+++ b/arch/riscv/kernel/module.c
@@ -747,6 +747,10 @@ initialize_relocation_hashtable(unsigned int num_relocations,
 {
 	/* Can safely assume that bits is not greater than sizeof(long) */
 	unsigned long hashtable_size = roundup_pow_of_two(num_relocations);
+	/*
+	 * When hashtable_size == 1, hashtable_bits == 0.
+	 * This is valid because the hashing algorithm returns 0 in this case.
+	 */
 	unsigned int hashtable_bits = ilog2(hashtable_size);
 
 	/*
@@ -763,7 +767,7 @@ initialize_relocation_hashtable(unsigned int num_relocations,
 					      sizeof(*relocation_hashtable),
 					      GFP_KERNEL);
 	if (!*relocation_hashtable)
-		return -ENOMEM;
+		return 0;
 
 	__hash_init(*relocation_hashtable, hashtable_size);
 
@@ -789,8 +793,8 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
 	hashtable_bits = initialize_relocation_hashtable(num_relocations,
 							 &relocation_hashtable);
 
-	if (hashtable_bits < 0)
-		return hashtable_bits;
+	if (!relocation_hashtable)
+		return -ENOMEM;
 
 	INIT_LIST_HEAD(&used_buckets_list);
 




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux