Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp829371ybe; Wed, 11 Sep 2019 05:29:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqyA+Jt9aZmeLuTb+QWdWISewL98UpyEF79jVllAhJh95OzxRRKD5zjLxuyA/mEyFqLQrOaS X-Received: by 2002:a17:906:5214:: with SMTP id g20mr28963355ejm.220.1568204962090; Wed, 11 Sep 2019 05:29:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568204962; cv=none; d=google.com; s=arc-20160816; b=eJN9FZmyRYJcWTyjX+OlcFVbje+S2/nvhdX4DjfonUssMFLEzSuODFlpVWfropOnqX R3ZiS6X7hM7UG53zOQjJKmRFkJTA2d7JVR3Xdds5/kV2zehJxZ4RmDJpN5aY47Nb+Clo LscyEDDj6x/64+KCgEw8xvyt53p8BBFyQJK5HM3Buz4nbUZRqmbHhr8obiQb8xzJQnNz QLPIIBsjs7YDhEa0FugztdL2XR3Uh8tFIpJWH472/SrlAelcACFYYertDY1sRxSo493d jbE+hcMLUTxmQa4jUNOykIgiY7KNAyYy0IG0cx1qLEOjAP0ptsGa5HU4N1R63/4lPQKK MvgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=ShtK1Htszfwwct/bMNrUXF1Ic9svPv3Ynm2ifmKJlvA=; b=U5PjkrcU8qQrf57pHzfeEOgsjc1RU1J6Klkg86kUFB74E4NRWNcQM+3Ii7f1mU2SYu YGwqg+wQDHKaOWi6C1ToETjst9i9DzLfITCwjbTBE5OY08nm/RPWxfn9U23wNICI+J2A FDYj/Vl9FeKSIQu/b5VoajrYhWX/ebC44C6lm6iRHvasXybNlVXeRE5+6AKYC3zJ3hiU U1dHQ4iUsdhiQqGsmfPQSsSVTlGNmXcL0rSDe+mUKFoEMjwe53ig/Y+dP30t7FDcoNFP vN4Z4OuzlfVfh0NSIl93Kram/fNng79c8ZP/Cl7r+ngYZbPa5HVoW8yk7/2Gpq5rFuqj Bdpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LZdJBvqC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k39si13090943edb.52.2019.09.11.05.28.57; Wed, 11 Sep 2019 05:29:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LZdJBvqC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727879AbfIKM04 (ORCPT + 99 others); Wed, 11 Sep 2019 08:26:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:33318 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726781AbfIKM04 (ORCPT ); Wed, 11 Sep 2019 08:26:56 -0400 Received: from localhost.localdomain (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7220A2075C; Wed, 11 Sep 2019 12:26:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568204815; bh=MseBqWNeudWiY5Pr7ynKRYTy7jqmwG9LbsTu29MhRKY=; h=From:To:Cc:Subject:Date:From; b=LZdJBvqCBTeZla1V84Jvesl+/iKxoEMHllQ6mdelwy6CTJTUtMeG23jEOWk9243i+ 7nWDOMMWIdhPNK+TRxsdmaTNGp7NciuNvs1Zx8Au6khZC07bagyXzJ97FH/gkXkBmQ CsnNzvqSqBcBz7jA1rgVBX6+SX5AL/zvH1eD2PUw= From: Will Deacon To: linux-kernel@vger.kernel.org Cc: maco@android.com, gregkh@linuxfoundation.org, Will Deacon , Matthias Maennich , Jessica Yu , Ard Biesheuvel , Catalin Marinas Subject: [PATCH] module: Fix link failure due to invalid relocation on namespace offset Date: Wed, 11 Sep 2019 13:26:46 +0100 Message-Id: <20190911122646.13838-1-will@kernel.org> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 8651ec01daed ("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 Cc: Jessica Yu Cc: Ard Biesheuvel Cc: Catalin Marinas Fixes: 8651ec01daed ("module: add support for symbol namespaces.") Reported-by: kbuild test robot Signed-off-by: Will Deacon --- Please note that I've not been able to test this at LPC, but it's been submitted to kernelci. include/asm-generic/export.h | 2 +- include/linux/export.h | 2 +- kernel/module.c | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/asm-generic/export.h b/include/asm-generic/export.h index e2b5d0f569d3..d0912c7ac2fc 100644 --- a/include/asm-generic/export.h +++ b/include/asm-generic/export.h @@ -17,7 +17,7 @@ .macro __put, val, name #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS - .long \val - ., \name - ., 0 - . + .long \val - ., \name - ., 0 #elif defined(CONFIG_64BIT) .quad \val, \name, 0 #else diff --git a/include/linux/export.h b/include/linux/export.h index 2c5468d8ea9a..ef5d015d754a 100644 --- a/include/linux/export.h +++ b/include/linux/export.h @@ -68,7 +68,7 @@ extern struct module __this_module; "__ksymtab_" #sym ": \n" \ " .long " #sym "- . \n" \ " .long __kstrtab_" #sym "- . \n" \ - " .long 0 - . \n" \ + " .long 0 \n" \ " .previous \n") struct kernel_symbol { diff --git a/kernel/module.c b/kernel/module.c index f76efcf2043e..7ab244c4e1ba 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -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) { #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS + if (!sym->namespace_offset) + return NULL; return offset_to_ptr(&sym->namespace_offset); #else return sym->namespace; -- 2.23.0.162.g0b9fbb3734-goog