]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
powerpc/64/module: REL32 relocation range check
authorNicholas Piggin <npiggin@gmail.com>
Wed, 29 Aug 2018 11:56:56 +0000 (21:56 +1000)
committerJuerg Haefliger <juergh@canonical.com>
Wed, 24 Jul 2019 01:58:35 +0000 (19:58 -0600)
BugLink: https://bugs.launchpad.net/bugs/1836802
[ Upstream commit b851ba02a6f3075f0f99c60c4bc30a4af80cf428 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
arch/powerpc/kernel/module_64.c

index e6c011d566292c7769c156f99bdee26d9585d670..f941bcaeeac80468cfe1cf6e1daf6278edceac07 100644 (file)
@@ -658,7 +658,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: