diff mbox series

arm64/module: deal with ambiguity in PRELxx relocation ranges

Message ID 20190521125707.6115-1-ard.biesheuvel@arm.com (mailing list archive)
State New, archived
Headers show
Series arm64/module: deal with ambiguity in PRELxx relocation ranges | expand

Commit Message

Ard Biesheuvel May 21, 2019, 12:57 p.m. UTC
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(-)

Comments

Will Deacon May 23, 2019, 10:24 a.m. UTC | #1
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
diff mbox series

Patch

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: