Skip to content

Commit b851ba0

Browse files
npigginmpe
authored andcommitted
powerpc/64/module: REL32 relocation range check
The recent module relocation overflow crash demonstrated that we have no range checking on REL32 relative relocations. This patch implements a basic check, the same kernel that previously oopsed and rebooted now continues with some of these errors when loading the module: module_64: x_tables: REL32 527703503449812 out of range! Possibly other relocations (ADDR32, REL16, TOC16, etc.) should also have overflow checks. Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent dd76ff5 commit b851ba0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

arch/powerpc/kernel/module_64.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,14 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
680680

681681
case R_PPC64_REL32:
682682
/* 32 bits relative (used by relative exception tables) */
683-
*(u32 *)location = value - (unsigned long)location;
683+
/* Convert value to relative */
684+
value -= (unsigned long)location;
685+
if (value + 0x80000000 > 0xffffffff) {
686+
pr_err("%s: REL32 %li out of range!\n",
687+
me->name, (long int)value);
688+
return -ENOEXEC;
689+
}
690+
*(u32 *)location = value;
684691
break;
685692

686693
case R_PPC64_TOCSAVE:

0 commit comments

Comments
 (0)