提交 069e1c07 编写于 作者: W Will Deacon 提交者: Jessica Yu

module: Fix link failure due to invalid relocation on namespace offset

Commit 8651ec01 ("module: add support for symbol namespaces.")
broke linking for arm64 defconfig:

  | lib/crypto/arc4.o: In function `__ksymtab_arc4_setkey':
  | arc4.c:(___ksymtab+arc4_setkey+0x8): undefined reference to `no symbol'
  | lib/crypto/arc4.o: In function `__ksymtab_arc4_crypt':
  | arc4.c:(___ksymtab+arc4_crypt+0x8): undefined reference to `no symbol'

This is because the dummy initialisation of the 'namespace_offset' field
in 'struct kernel_symbol' when using EXPORT_SYMBOL on architectures with
support for PREL32 locations uses an offset from an absolute address (0)
in an effort to trick 'offset_to_pointer' into behaving as a NOP,
allowing non-namespaced symbols to be treated in the same way as those
belonging to a namespace.

Unfortunately, place-relative relocations require a symbol reference
rather than an absolute value and, although x86 appears to get away with
this due to placing the kernel text at the top of the address space, it
almost certainly results in a runtime failure if the kernel is relocated
dynamically as a result of KASLR.

Rework 'namespace_offset' so that a value of 0, which cannot occur for a
valid namespaced symbol, indicates that the corresponding symbol does
not belong to a namespace.

Cc: Matthias Maennich <maennich@google.com>
Cc: Jessica Yu <jeyu@kernel.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Fixes: 8651ec01 ("module: add support for symbol namespaces.")
Reported-by: Nkbuild test robot <lkp@intel.com>
Tested-by: NMatthias Maennich <maennich@google.com>
Tested-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: NMatthias Maennich <maennich@google.com>
Acked-by: NArd Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: NWill Deacon <will@kernel.org>
Signed-off-by: NJessica Yu <jeyu@kernel.org>
上级 32bca2df
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
.macro __put, val, name .macro __put, val, name
#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
.long \val - ., \name - ., 0 - . .long \val - ., \name - ., 0
#elif defined(CONFIG_64BIT) #elif defined(CONFIG_64BIT)
.quad \val, \name, 0 .quad \val, \name, 0
#else #else
......
...@@ -68,7 +68,7 @@ extern struct module __this_module; ...@@ -68,7 +68,7 @@ extern struct module __this_module;
"__ksymtab_" #sym ": \n" \ "__ksymtab_" #sym ": \n" \
" .long " #sym "- . \n" \ " .long " #sym "- . \n" \
" .long __kstrtab_" #sym "- . \n" \ " .long __kstrtab_" #sym "- . \n" \
" .long 0 - . \n" \ " .long 0 \n" \
" .previous \n") " .previous \n")
struct kernel_symbol { struct kernel_symbol {
......
...@@ -547,6 +547,8 @@ static const char *kernel_symbol_name(const struct kernel_symbol *sym) ...@@ -547,6 +547,8 @@ static const char *kernel_symbol_name(const struct kernel_symbol *sym)
static const char *kernel_symbol_namespace(const struct kernel_symbol *sym) static const char *kernel_symbol_namespace(const struct kernel_symbol *sym)
{ {
#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
if (!sym->namespace_offset)
return NULL;
return offset_to_ptr(&sym->namespace_offset); return offset_to_ptr(&sym->namespace_offset);
#else #else
return sym->namespace; return sym->namespace;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册