From: James Hogan <james.hogan@imgtec.com>
To: Paul Burton <paul.burton@imgtec.com>
Cc: <linux-mips@linux-mips.org>, Ralf Baechle <ralf@linux-mips.org>,
"Andrey Konovalov" <adech.fo@gmail.com>,
"Steven J. Hill" <Steven.Hill@imgtec.com>,
Andrey Ryabinin <ryabinin.a.a@gmail.com>,
<linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 1/5] MIPS: Bail on unsupported module relocs
Date: Wed, 3 Feb 2016 12:23:32 +0000 [thread overview]
Message-ID: <20160203122332.GG5038@jhogan-linux.le.imgtec.org> (raw)
In-Reply-To: <1454471085-20963-2-git-send-email-paul.burton@imgtec.com>
[-- Attachment #1: Type: text/plain, Size: 3532 bytes --]
On Wed, Feb 03, 2016 at 03:44:41AM +0000, Paul Burton wrote:
> When an unsupported reloc is encountered in a module, we currently
> blindly branch to whatever would be at its entry in the reloc handler
> function pointer arrays. This may be NULL, or if the unsupported reloc
> has a type greater than that of the supported reloc with the highest
> type then we'll dereference some value after the function pointer array
> & branch to that. The result is at best a kernel oops.
>
> Fix this by checking that the reloc type has an entry in the function
> pointer array (ie. is less than the number of items in the array) and
> that the handler is non-NULL, returning an error code to fail the module
> load if no handler is found.
>
> Signed-off-by: Paul Burton <paul.burton@imgtec.com>
> Cc: James Hogan <james.hogan@imgtec.com>
Reviewed-by: James Hogan <james.hogan@imgtec.com>
Cheers
James
> ---
>
> arch/mips/kernel/module-rela.c | 19 ++++++++++++++++---
> arch/mips/kernel/module.c | 19 ++++++++++++++++---
> 2 files changed, 32 insertions(+), 6 deletions(-)
>
> diff --git a/arch/mips/kernel/module-rela.c b/arch/mips/kernel/module-rela.c
> index 2b70723..769e316 100644
> --- a/arch/mips/kernel/module-rela.c
> +++ b/arch/mips/kernel/module-rela.c
> @@ -109,9 +109,10 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
> struct module *me)
> {
> Elf_Mips_Rela *rel = (void *) sechdrs[relsec].sh_addr;
> + int (*handler)(struct module *me, u32 *location, Elf_Addr v);
> Elf_Sym *sym;
> u32 *location;
> - unsigned int i;
> + unsigned int i, type;
> Elf_Addr v;
> int res;
>
> @@ -134,9 +135,21 @@ int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
> return -ENOENT;
> }
>
> - v = sym->st_value + rel[i].r_addend;
> + type = ELF_MIPS_R_TYPE(rel[i]);
> +
> + if (type < ARRAY_SIZE(reloc_handlers_rela))
> + handler = reloc_handlers_rela[type];
> + else
> + handler = NULL;
>
> - res = reloc_handlers_rela[ELF_MIPS_R_TYPE(rel[i])](me, location, v);
> + if (!handler) {
> + pr_warn("%s: Unknown relocation type %u\n",
> + me->name, type);
> + return -EINVAL;
> + }
> +
> + v = sym->st_value + rel[i].r_addend;
> + res = handler(me, location, v);
> if (res)
> return res;
> }
> diff --git a/arch/mips/kernel/module.c b/arch/mips/kernel/module.c
> index 1833f51..2adf572 100644
> --- a/arch/mips/kernel/module.c
> +++ b/arch/mips/kernel/module.c
> @@ -197,9 +197,10 @@ int apply_relocate(Elf_Shdr *sechdrs, const char *strtab,
> struct module *me)
> {
> Elf_Mips_Rel *rel = (void *) sechdrs[relsec].sh_addr;
> + int (*handler)(struct module *me, u32 *location, Elf_Addr v);
> Elf_Sym *sym;
> u32 *location;
> - unsigned int i;
> + unsigned int i, type;
> Elf_Addr v;
> int res;
>
> @@ -223,9 +224,21 @@ int apply_relocate(Elf_Shdr *sechdrs, const char *strtab,
> return -ENOENT;
> }
>
> - v = sym->st_value;
> + type = ELF_MIPS_R_TYPE(rel[i]);
> +
> + if (type < ARRAY_SIZE(reloc_handlers_rel))
> + handler = reloc_handlers_rel[type];
> + else
> + handler = NULL;
>
> - res = reloc_handlers_rel[ELF_MIPS_R_TYPE(rel[i])](me, location, v);
> + if (!handler) {
> + pr_warn("%s: Unknown relocation type %u\n",
> + me->name, type);
> + return -EINVAL;
> + }
> +
> + v = sym->st_value;
> + res = handler(me, location, v);
> if (res)
> return res;
> }
> --
> 2.7.0
>
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2016-02-03 12:23 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-03 3:44 [PATCH 0/5] Support new MIPSr6 relocations Paul Burton
2016-02-03 3:44 ` [PATCH 1/5] MIPS: Bail on unsupported module relocs Paul Burton
2016-02-03 12:23 ` James Hogan [this message]
2016-02-03 12:24 ` Maciej W. Rozycki
2016-02-03 16:15 ` Paul Burton
2016-02-03 16:55 ` Maciej W. Rozycki
2016-02-03 3:44 ` [PATCH 2/5] MIPS: module-rela: Make consistent use of pr_*() Paul Burton
2016-02-03 3:44 ` [PATCH 3/5] MIPS: Add support for 64-bit R6 ELF relocations Paul Burton
2016-02-03 3:44 ` [PATCH 4/5] MIPS: Support R_MIPS_PC16 rel-style reloc Paul Burton
2016-02-03 10:25 ` Sergei Shtylyov
2016-02-03 10:32 ` Paul Burton
2016-02-03 10:36 ` Sergei Shtylyov
2016-02-03 10:48 ` Paul Burton
2016-02-03 12:49 ` James Hogan
2016-02-03 3:44 ` [PATCH 5/5] MIPS: Implement MIPSr6 R_MIPS_PC2x rel-style relocs Paul Burton
2016-02-03 12:47 ` James Hogan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160203122332.GG5038@jhogan-linux.le.imgtec.org \
--to=james.hogan@imgtec.com \
--cc=Steven.Hill@imgtec.com \
--cc=adech.fo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=paul.burton@imgtec.com \
--cc=ralf@linux-mips.org \
--cc=ryabinin.a.a@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).