lib/elf: Fix relocation bounds check overflow for large r_addr values
diff --git a/common/lib/elf.c b/common/lib/elf.c
index f983495c..3514c651 100644
--- a/common/lib/elf.c
+++ b/common/lib/elf.c
@@ -487,7 +487,7 @@ end_of_pt_segment:
continue;
// Relocation is after buffer
- if (vaddr + size < relocation->r_addr + 8)
+ if (size < 8 || relocation->r_addr > vaddr + size - 8)
continue;
// It's inside it, calculate where it is
