linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64/module: deal with ambiguity in PRELxx relocation ranges
@ 2019-05-21 12:57 Ard Biesheuvel
  2019-05-23 10:24 ` Will Deacon
  0 siblings, 1 reply; 2+ messages in thread
From: Ard Biesheuvel @ 2019-05-21 12:57 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: mark.rutland, guillaume.gardet, marc.zyngier, will.deacon,
	james.morse, Ard Biesheuvel

The R_AARCH64_PREL16 and R_AARCH64_PREL32 relocations are
documented as permitting a range of [-2^15 .. 2^16), resp.
[-2^31 .. 2^32). It is also documented that this means we
cannot detect overflow in some cases, which is bad.

Since we always interpret the targets of these relocations as
signed quantities (e.g., in the ksymtab handling code), let's
tighten the overflow checks so that targets that are out of
range for our signed interpretation of the relocated quantity
get flagged.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
---
 arch/arm64/kernel/module.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c
index f713e2fc4d75..2e4e3915b4d0 100644
--- a/arch/arm64/kernel/module.c
+++ b/arch/arm64/kernel/module.c
@@ -99,12 +99,12 @@ static int reloc_data(enum aarch64_reloc_op op, void *place, u64 val, int len)
 	switch (len) {
 	case 16:
 		*(s16 *)place = sval;
-		if (sval < S16_MIN || sval > U16_MAX)
+		if (sval < S16_MIN || sval > S16_MAX)
 			return -ERANGE;
 		break;
 	case 32:
 		*(s32 *)place = sval;
-		if (sval < S32_MIN || sval > U32_MAX)
+		if (sval < S32_MIN || sval > S32_MAX)
 			return -ERANGE;
 		break;
 	case 64:
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] arm64/module: deal with ambiguity in PRELxx relocation ranges
  2019-05-21 12:57 [PATCH] arm64/module: deal with ambiguity in PRELxx relocation ranges Ard Biesheuvel
@ 2019-05-23 10:24 ` Will Deacon
  0 siblings, 0 replies; 2+ messages in thread
From: Will Deacon @ 2019-05-23 10:24 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: marc.zyngier, mark.rutland, james.morse, linux-arm-kernel,
	guillaume.gardet

On Tue, May 21, 2019 at 01:57:07PM +0100, Ard Biesheuvel wrote:
> The R_AARCH64_PREL16 and R_AARCH64_PREL32 relocations are
> documented as permitting a range of [-2^15 .. 2^16), resp.
> [-2^31 .. 2^32). It is also documented that this means we
> cannot detect overflow in some cases, which is bad.
> 
> Since we always interpret the targets of these relocations as
> signed quantities (e.g., in the ksymtab handling code), let's
> tighten the overflow checks so that targets that are out of
> range for our signed interpretation of the relocated quantity
> get flagged.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
> ---
>  arch/arm64/kernel/module.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c
> index f713e2fc4d75..2e4e3915b4d0 100644
> --- a/arch/arm64/kernel/module.c
> +++ b/arch/arm64/kernel/module.c
> @@ -99,12 +99,12 @@ static int reloc_data(enum aarch64_reloc_op op, void *place, u64 val, int len)
>  	switch (len) {
>  	case 16:
>  		*(s16 *)place = sval;
> -		if (sval < S16_MIN || sval > U16_MAX)
> +		if (sval < S16_MIN || sval > S16_MAX)

Sorry to be a pain, but can you add a comment here saying why we're
devaiting from the AArch64 ELF spec, please? It's all in the commit message,
but I'd like to have it in the code too so we don't "fix" it later on.

Cheers,

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-05-23 10:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-21 12:57 [PATCH] arm64/module: deal with ambiguity in PRELxx relocation ranges Ard Biesheuvel
2019-05-23 10:24 ` Will Deacon

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).