diff options
author | Samuel Holland <samuel.holland@sifive.com> | 2025-04-09 20:14:49 +0300 |
---|---|---|
committer | Alexandre Ghiti <alexghiti@rivosinc.com> | 2025-04-14 16:07:07 +0300 |
commit | 0b4cce68efb93e31a8e51795d696df6e379cb41c (patch) | |
tree | f0aa8c478a414e668794227bfca25bcbe11f45e3 | |
parent | e94eb7ea6f206e229791761a5fdf9389f8dbd183 (diff) | |
download | linux-0b4cce68efb93e31a8e51795d696df6e379cb41c.tar.xz |
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: 080c4324fa5e ("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>
-rw-r--r-- | arch/riscv/kernel/module.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c index 0ae34d79b87b..7f6147c18033 100644 --- a/arch/riscv/kernel/module.c +++ b/arch/riscv/kernel/module.c @@ -860,7 +860,7 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, } j++; - if (j > sechdrs[relsec].sh_size / sizeof(*rel)) + if (j == num_relocations) j = 0; } while (j_idx != j); |