Skip to contentSkip to conversation

ARM: module: Drop 'rel->r_offset < 0' statement

PATCH RESEND In review Austin Kim 1 participant 2 messages Sep 11, 2019 – Sep 15, 2019 Arm (32-bit)

lore
Share & tools
lore

Austin Kim

author
#0 lore raw

PATCH RESEND 1/1 ARM: module: Drop 'rel->r_offset < 0' statement

Since rel->r_offset is declared as Elf32_Addr, this value is always non-negative.
typedef struct elf32_rel {
Elf32_Addr r_offset;
Elf32_Word r_info;
} Elf32_Rel;

typedef __u32 Elf32_Addr;
typedef unsigned int __u32;

Drop 'rel->r_offset < 0' statement which is always false. Also change %u to %d in pr_err() for rel->r_offset.

---
 arch/arm/kernel/module.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/kernel/module.c +2 -2
index deef17f34..f805bcbda 100644
@@ -92,8 +92,8 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
 		sym = ((Elf32_Sym *)symsec->sh_addr) + offset;
 		symname = strtab + sym->st_name;
 
-		if (rel->r_offset < 0 || rel->r_offset > dstsec->sh_size - sizeof(u32)) {
-			pr_err("%s: section %u reloc %u sym '%s': out of bounds relocation, offset %d size %u\n",
+		if (rel->r_offset > dstsec->sh_size - sizeof(u32)) {
+			pr_err("%s: section %u reloc %u sym '%s': out of bounds relocation, offset %u size %u\n",
 			       module->name, relindex, i, symname,
 			       rel->r_offset, dstsec->sh_size);
 			return -ENOEXEC;
Signature · 1 line
2.11.0
author
#1 lore raw

Hello, Maintainer(Russell King)...
Would you please update the feedback for this patch?

2019년 9월 11일 (수) 오후 11:16, Austin Kim <[email protected]>님이 작성:

Quoted 37 lines

Since rel->r_offset is declared as Elf32_Addr, this value is always non-negative.
typedef struct elf32_rel {
Elf32_Addr r_offset;
Elf32_Word r_info;
} Elf32_Rel;

typedef __u32 Elf32_Addr;
typedef unsigned int __u32;

Drop 'rel->r_offset < 0' statement which is always false. Also change %u to %d in pr_err() for rel->r_offset.

---
 arch/arm/kernel/module.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/kernel/module.c +2 -3
index deef17f34..f805bcbda 100644
@@ -92,8 +92,8 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
                sym = ((Elf32_Sym *)symsec->sh_addr) + offset;
                symname = strtab + sym->st_name;
 
-               if (rel->r_offset < 0 || rel->r_offset > dstsec->sh_size - sizeof(u32)) {
-                       pr_err("%s: section %u reloc %u sym '%s': out of bounds relocation, offset %d size %u\n",
+               if (rel->r_offset > dstsec->sh_size - sizeof(u32)) {
+                       pr_err("%s: section %u reloc %u sym '%s': out of bounds relocation, offset %u size %u\n",
                               module->name, relindex, i, symname,
                               rel->r_offset, dstsec->sh_size);
                        return -ENOEXEC;
--

2.11.0