Skip to content

Commit 0b4cce6

Browse files
SiFiveHollandAlexandre Ghiti
authored andcommitted
riscv: module: Fix out-of-bounds relocation access
The current code allows rel[j] to access one element past the end of the relocation section. Simplify to num_relocations which is equivalent to the existing size expression. Fixes: 080c432 ("riscv: optimize ELF relocation function in riscv") Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Maxim Kochetkov <fido_max@inbox.ru> Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com> Link: https://lore.kernel.org/r/20250409171526.862481-1-samuel.holland@sifive.com Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
1 parent e94eb7e commit 0b4cce6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/riscv/kernel/module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
860860
}
861861

862862
j++;
863-
if (j > sechdrs[relsec].sh_size / sizeof(*rel))
863+
if (j == num_relocations)
864864
j = 0;
865865

866866
} while (j_idx != j);

0 commit comments

Comments
 (0)