]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
ia64: module: fix symbolizer crash on fdescr
authorSergei Trofimovich <slyfox@gentoo.org>
Fri, 30 Apr 2021 05:53:48 +0000 (22:53 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 May 2021 08:08:24 +0000 (10:08 +0200)
[ Upstream commit 99e729bd40fb3272fa4b0140839d5e957b58588a ]

Noticed failure as a crash on ia64 when tried to symbolize all backtraces
collected by page_owner=on:

    $ cat /sys/kernel/debug/page_owner
    <oops>

    CPU: 1 PID: 2074 Comm: cat Not tainted 5.12.0-rc4 #226
    Hardware name: hp server rx3600, BIOS 04.03 04/08/2008
    ip is at dereference_module_function_descriptor+0x41/0x100

Crash happens at dereference_module_function_descriptor() due to
use-after-free when dereferencing ".opd" section header.

All section headers are already freed after module is laoded successfully.

To keep symbolizer working the change stores ".opd" address and size after
module is relocated to a new place and before section headers are
discarded.

To make similar errors less obscure module_finalize() now zeroes out all
variables relevant to module loading only.

Link: https://lkml.kernel.org/r/20210403074803.3309096-1-slyfox@gentoo.org
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/ia64/include/asm/module.h
arch/ia64/kernel/module.c

index f319144260ce13fcb316e1d0b40715f9a6f427b2..9fbf32e6e8813a918db68f9dd0643cc6b16e19fe 100644 (file)
 struct elf64_shdr;                     /* forward declration */
 
 struct mod_arch_specific {
+       /* Used only at module load time. */
        struct elf64_shdr *core_plt;    /* core PLT section */
        struct elf64_shdr *init_plt;    /* init PLT section */
        struct elf64_shdr *got;         /* global offset table */
        struct elf64_shdr *opd;         /* official procedure descriptors */
        struct elf64_shdr *unwind;      /* unwind-table section */
        unsigned long gp;               /* global-pointer for module */
+       unsigned int next_got_entry;    /* index of next available got entry */
 
+       /* Used at module run and cleanup time. */
        void *core_unw_table;           /* core unwind-table cookie returned by unwinder */
        void *init_unw_table;           /* init unwind-table cookie returned by unwinder */
-       unsigned int next_got_entry;    /* index of next available got entry */
+       void *opd_addr;                 /* symbolize uses .opd to get to actual function */
+       unsigned long opd_size;
 };
 
 #define MODULE_PROC_FAMILY     "ia64"
index 1a42ba885188a5c8e865bb28108c685ed1a37515..ee693c8cec498fa30c2b47d7ba80ef54f2f0deb9 100644 (file)
@@ -905,9 +905,31 @@ register_unwind_table (struct module *mod)
 int
 module_finalize (const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, struct module *mod)
 {
+       struct mod_arch_specific *mas = &mod->arch;
+
        DEBUGP("%s: init: entry=%p\n", __func__, mod->init);
-       if (mod->arch.unwind)
+       if (mas->unwind)
                register_unwind_table(mod);
+
+       /*
+        * ".opd" was already relocated to the final destination. Store
+        * it's address for use in symbolizer.
+        */
+       mas->opd_addr = (void *)mas->opd->sh_addr;
+       mas->opd_size = mas->opd->sh_size;
+
+       /*
+        * Module relocation was already done at this point. Section
+        * headers are about to be deleted. Wipe out load-time context.
+        */
+       mas->core_plt = NULL;
+       mas->init_plt = NULL;
+       mas->got = NULL;
+       mas->opd = NULL;
+       mas->unwind = NULL;
+       mas->gp = 0;
+       mas->next_got_entry = 0;
+
        return 0;
 }
 
@@ -926,10 +948,9 @@ module_arch_cleanup (struct module *mod)
 
 void *dereference_module_function_descriptor(struct module *mod, void *ptr)
 {
-       Elf64_Shdr *opd = mod->arch.opd;
+       struct mod_arch_specific *mas = &mod->arch;
 
-       if (ptr < (void *)opd->sh_addr ||
-                       ptr >= (void *)(opd->sh_addr + opd->sh_size))
+       if (ptr < mas->opd_addr || ptr >= mas->opd_addr + mas->opd_size)
                return ptr;
 
        return dereference_function_descriptor(ptr);