[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <cb6d98dc-49e9-2d3b-1acc-f208e4fd13fc@gmail.com>
Date: Wed, 16 Apr 2025 16:21:07 +0200
From: Uros Bizjak <ubizjak@...il.com>
To: Alexander Potapenko <glider@...gle.com>
Cc: quic_jiangenj@...cinc.com, linux-kernel@...r.kernel.org,
kasan-dev@...glegroups.com, x86@...nel.org,
Aleksandr Nogikh <nogikh@...gle.com>, Andrey Konovalov
<andreyknvl@...il.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, Dmitry Vyukov
<dvyukov@...gle.com>, Ingo Molnar <mingo@...hat.com>,
Josh Poimboeuf <jpoimboe@...nel.org>, Marco Elver <elver@...gle.com>,
Peter Zijlstra <peterz@...radead.org>, Thomas Gleixner <tglx@...utronix.de>
Subject: Re: [PATCH 6/7] x86: objtool: add support for R_X86_64_REX_GOTPCRELX
On 16. 04. 25 10:54, Alexander Potapenko wrote:
> When compiling modules with -fsanitize-coverage=trace-pc-guard, Clang
> will emit R_X86_64_REX_GOTPCRELX relocations for the
> __start___sancov_guards and __stop___sancov_guards symbols. Although
> these relocations can be resolved within the same binary, they are left
> over by the linker because of the --emit-relocs flag.
>
> This patch makes it possible to resolve the R_X86_64_REX_GOTPCRELX
> relocations at runtime, as doing so does not require a .got section.
> In addition, add a missing overflow check to R_X86_64_PC32/R_X86_64_PLT32.
>
> Cc: x86@...nel.org
> Signed-off-by: Alexander Potapenko <glider@...gle.com>
> ---
> arch/x86/include/asm/elf.h | 1 +
> arch/x86/kernel/module.c | 8 ++++++++
> arch/x86/um/asm/elf.h | 1 +
> tools/objtool/arch/x86/decode.c | 1 +
> 4 files changed, 11 insertions(+)
>
> diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
> index 1fb83d47711f9..15d0438467e94 100644
> --- a/arch/x86/include/asm/elf.h
> +++ b/arch/x86/include/asm/elf.h
> @@ -63,6 +63,7 @@ typedef struct user_i387_struct elf_fpregset_t;
> #define R_X86_64_8 14 /* Direct 8 bit sign extended */
> #define R_X86_64_PC8 15 /* 8 bit sign extended pc relative */
> #define R_X86_64_PC64 24 /* Place relative 64-bit signed */
> +#define R_X86_64_REX_GOTPCRELX 42 /* R_X86_64_GOTPCREL with optimizations */
>
> /*
> * These are used to set parameters in the core dumps.
> diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
> index 8984abd91c001..6c8b524bfbe3b 100644
> --- a/arch/x86/kernel/module.c
> +++ b/arch/x86/kernel/module.c
> @@ -133,6 +133,14 @@ static int __write_relocate_add(Elf64_Shdr *sechdrs,
> case R_X86_64_PC32:
> case R_X86_64_PLT32:
> val -= (u64)loc;
> + if ((s64)val != *(s32 *)&val)
> + goto overflow;
> + size = 4;
> + break;
> + case R_X86_64_REX_GOTPCRELX:
> + val -= (u64)loc;
> + if ((s64)val != *(s32 *)&val)
> + goto overflow;
> size = 4;
> break;
These two cases are the same. You probably want:
case R_X86_64_PC32:
case R_X86_64_PLT32:
case R_X86_64_REX_GOTPCRELX:
val -= (u64)loc;
if ((s64)val != *(s32 *)&val)
goto overflow;
size = 4;
break;
Uros.
Powered by blists - more mailing lists