* [RFC PATCH] powerpc/64/module: REL32 relocation range check
@ 2018-08-29 11:56 Nicholas Piggin
2018-10-22 9:36 ` [RFC] " Michael Ellerman
0 siblings, 1 reply; 2+ messages in thread
From: Nicholas Piggin @ 2018-08-29 11:56 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Nicholas Piggin, Alan Modra
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!
Question is whether other relocations (ADDR32, REL16, TOC16, etc.)
should also have overflow checks.
---
arch/powerpc/kernel/module_64.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c
index a2636c250b7b..2a2fb656d23b 100644
--- a/arch/powerpc/kernel/module_64.c
+++ b/arch/powerpc/kernel/module_64.c
@@ -678,7 +678,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:
--
2.18.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [RFC] powerpc/64/module: REL32 relocation range check
2018-08-29 11:56 [RFC PATCH] powerpc/64/module: REL32 relocation range check Nicholas Piggin
@ 2018-10-22 9:36 ` Michael Ellerman
0 siblings, 0 replies; 2+ messages in thread
From: Michael Ellerman @ 2018-10-22 9:36 UTC (permalink / raw)
To: Nicholas Piggin, linuxppc-dev; +Cc: Nicholas Piggin, Alan Modra
On Wed, 2018-08-29 at 11:56:56 UTC, Nicholas Piggin wrote:
> 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!
>
> Question is whether other relocations (ADDR32, REL16, TOC16, etc.)
> should also have overflow checks.
> ---
> arch/powerpc/kernel/module_64.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c
> index a2636c250b7b..2a2fb656d23b 100644
> --- a/arch/powerpc/kernel/module_64.c
> +++ b/arch/powerpc/kernel/module_64.c
> @@ -678,7 +678,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:
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/b851ba02a6f3075f0f99c60c4bc30a
cheers
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-10-22 9:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-29 11:56 [RFC PATCH] powerpc/64/module: REL32 relocation range check Nicholas Piggin
2018-10-22 9:36 ` [RFC] " Michael Ellerman
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).