public inbox for linux-riscv@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v2 1/3] riscv: module: Fix out-of-bounds relocation access
@ 2025-04-09 17:14 Samuel Holland
  2025-04-09 17:14 ` [PATCH v2 2/3] riscv: module: Allocate PLT entries for R_RISCV_PLT32 Samuel Holland
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Samuel Holland @ 2025-04-09 17:14 UTC (permalink / raw)
  To: Palmer Dabbelt, Alexandre Ghiti, linux-riscv
  Cc: Andrew Jones, Pinkesh Vaghela, Pritesh Patel, Darshan Prajapati,
	Samuel Holland, Albert Ou, Amma Lee, Charlie Jenkins,
	Clément Léger, Jinjie Ruan, Luis Chamberlain,
	Maxim Kochetkov, Mike Rapoport (IBM), Paul Walmsley, linux-kernel

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>
---

Changes in v2:
 - New patch for v2

 arch/riscv/kernel/module.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c
index 47d0ebeec93c..060f576cc988 100644
--- a/arch/riscv/kernel/module.c
+++ b/arch/riscv/kernel/module.c
@@ -859,7 +859,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);
-- 
2.47.0


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-06-02 22:12 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-09 17:14 [PATCH v2 1/3] riscv: module: Fix out-of-bounds relocation access Samuel Holland
2025-04-09 17:14 ` [PATCH v2 2/3] riscv: module: Allocate PLT entries for R_RISCV_PLT32 Samuel Holland
2025-04-09 18:53   ` Andrew Jones
2025-04-09 17:14 ` [PATCH v2 3/3] riscv: module: Optimize PLT/GOT entry counting Samuel Holland
2025-04-09 19:07   ` Andrew Jones
2025-04-09 19:18     ` Samuel Holland
2025-04-09 19:24       ` Andrew Jones
2025-04-09 19:11 ` [PATCH v2 1/3] riscv: module: Fix out-of-bounds relocation access Maxim Kochetkov
2025-04-11 11:21 ` Alexandre Ghiti
2025-04-16 18:42 ` patchwork-bot+linux-riscv
2025-06-02 22:12 ` patchwork-bot+linux-riscv

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox