Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp910050ybe; Wed, 11 Sep 2019 06:39:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzo70p8faM3xWSgf0jIDn7lwP70d+1/49RE4H8ItP5yX932WQIY1FqN0EKWzgw+HDUScK02 X-Received: by 2002:a17:906:f2d3:: with SMTP id gz19mr29838042ejb.306.1568209176728; Wed, 11 Sep 2019 06:39:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568209176; cv=none; d=google.com; s=arc-20160816; b=J/G1q28ZKSpiUiekrbyToF3zffex6H5cAjipFXoAnBg4snPSfJHi0dJ4wLPeogBR44 Zbq6Qt3vigRkjER+AAcee6nFDgL/xDPpvdXtA+12hl/7eEKZmMFoK0Ni3HPJvLBq/uaQ Yv5uFMNhAx9qE8O3rbcm0JlkfzNTJyClJJmAcJDw+uCTKsdUuZWxBJvDLEa0ADxQ3XdL +vIeRV39QwVq09GW1RJJmV5nAQyTse/H4M/DkiL3AELm4WB05NRVEv45mLhf0vd6TLBm ycaKesn+2HcASpipkbLj3xDEwVzJrMSf+0cdROsG9XdtBeNSz2JwWPQKTsmLqGAvamfu Ak/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=YSTc7ZfPd7W7soqABQvXpbgVw5SkZ8Ur1Kb4Wi00Ssk=; b=hZJXQzrxErNeHS5FTHp527ZUjTFWHGPXO+dmz08KJWdpqtf57GeCBvDr82uuwD+yU9 frFhUHgLEFaNpUt2suCrsfOf/4+bcCD271C8xSALiXVXI6SUAnhbXf2UyClAaLqXwVsh 9F++T5JcswaTsByaBubgKKm/vZ4N+bj+oydLKP03IBudlhMFBUrBaPaoKyEjXp0hAZCA dU8lDz7rM3rCEGkJB/S+0wnlFLYMmk+ylHki+emc2nKah718mxYF6YCx4gimJT0X+NSm BVU9ydK30BdUU/m9ONPQKX11/DCDcqvIIUCIRyKWauk9+lw5+XOw0bCJcPFUI5KXwk+/ uNKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vx40CWwn; 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 f21si14055372edb.379.2019.09.11.06.39.12; Wed, 11 Sep 2019 06:39:36 -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=vx40CWwn; 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 S1727782AbfIKNfN (ORCPT + 99 others); Wed, 11 Sep 2019 09:35:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:35618 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726954AbfIKNfN (ORCPT ); Wed, 11 Sep 2019 09:35:13 -0400 Received: from linux-8ccs (unknown [92.117.136.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 130002084D; Wed, 11 Sep 2019 13:35:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568208911; bh=1CRAQnptUQ4fQ04kIuiUfCC3gBXzF737L9SvzOevbac=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=vx40CWwnYOZaGQp9qelZ59grtAhs4U/GgPAcPKAtQRp22lMWc5KkeO4z3YeGLx3Xb kLLtJWWAOL3FIbBX5fSprpUm9DAuJdBJaullDLf8GI0uNS41cFquXQ97wDT7y0rZsk DpaX9JtFLvf7qaJ7Oo1eZoyjOpZB/YDrdDQ/bwEM= Date: Wed, 11 Sep 2019 15:35:06 +0200 From: Jessica Yu To: Will Deacon Cc: linux-kernel@vger.kernel.org, maco@android.com, gregkh@linuxfoundation.org, Matthias Maennich , Ard Biesheuvel , Catalin Marinas Subject: Re: [PATCH] module: Fix link failure due to invalid relocation on namespace offset Message-ID: <20190911133506.GB7837@linux-8ccs> References: <20190911122646.13838-1-will@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20190911122646.13838-1-will@kernel.org> X-OS: Linux linux-8ccs 4.12.14-lp150.12.61-default x86_64 User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +++ Will Deacon [11/09/19 13:26 +0100]: >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. Thanks for fixing this so quickly. I can confirm that this fixes the build for arm64 defconfig and x86 built fine for me as well. I'll wait a bit and apply this at the end of the day in case Matthias or anybody else would like to confirm/test. Thanks, Jessica > 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 >