Skip to content

Commit

Permalink
powerpc/64/module: REL32 relocation range check
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Nicholas Piggin authored and Michael Ellerman committed Oct 20, 2018
1 parent dd76ff5 commit b851ba0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion arch/powerpc/kernel/module_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,14 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,

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

case R_PPC64_TOCSAVE:
Expand Down

0 comments on commit b851ba0

Please sign in to comment.