Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1135293ybe; Wed, 11 Sep 2019 09:55:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqx6mCdBZhIMuQ3/RVZETwhiWEiuazKAPe8MBcuuuNHqGykNKLC+YStFgmDpVF6lAx2HpiAO X-Received: by 2002:aa7:d755:: with SMTP id a21mr37194888eds.18.1568220901761; Wed, 11 Sep 2019 09:55:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568220901; cv=none; d=google.com; s=arc-20160816; b=vk9IJ+BtViZgCIXqk/sKJdY3axiAZmx6pcuGqwGHsnkt4D1SmSd+x0YFYJtEM6HOci eqDcnTwwP1IWOgj7skbCY5IcEwukblfj/bgU1jO3RgDsn4Pol0iy1R+m/kK1gmXS7dEt pLDCaATIC7Blo5ZaMQJgN7wqG3xTcZngfWb7X4+/Y6vq1qMKp8K1paiXyAd3dMkN8ukr eFQZlYYvgKr+GG426owhLlsNxL7ZU4J7ns8C082AnIHyomoesCDQSHerscN9JtrbF81j 2r8YupREIxZx8sUDcAIhIf6NnZuUudDk/H489dncy2BVtBUoVWi2alwXjG7SsAEqkKU1 lwEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=d3ECIsRGngFyFH2jbVLH1ZsB1j4Lio7jznUTM12k5iY=; b=lqM2EP+SL3KiKpBSVPytzBi/AHJJySGLCFJZrBfFbFK+bVZcCZUlNXsyjjXl0/8slu NN1y7TwAbOmIUQboIem3BfJ65Cw+TBHZnhVQuyO60QtKOY6wsteEtDSY/wFKqaiO/fK9 6N/wlbG2RPdpkgooF4+1VCfVoYLD0qsOtKXktzvJDaGUvID7Xhk9wnNrTMQ3pb5xUl7O JPeGjHmQUEGyuWXCP1dxQeRmELZ0cwkAypbogeoeIZjIkTmXsYm9TXSPJnsaO1qoF41Z GuvcmadUgvGOCDNnfiTUIR9FFPdV72QoS4t8+EbHTFDc7ay/JznVQ4eKjdQBEB67exH0 Wd/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IRnSx9s7; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d27si14846914ede.381.2019.09.11.09.54.37; Wed, 11 Sep 2019 09:55:01 -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=@linaro.org header.s=google header.b=IRnSx9s7; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729495AbfIKQwB (ORCPT + 99 others); Wed, 11 Sep 2019 12:52:01 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:55463 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729028AbfIKQwB (ORCPT ); Wed, 11 Sep 2019 12:52:01 -0400 Received: by mail-wm1-f65.google.com with SMTP id g207so4302068wmg.5 for ; Wed, 11 Sep 2019 09:51:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=d3ECIsRGngFyFH2jbVLH1ZsB1j4Lio7jznUTM12k5iY=; b=IRnSx9s7SGPyQDYBtwkGT+C2HJBmux4cX3LA4BXnurVeqPWx0EP8o2Ufhr+KO9n/z8 N4qlTgJj9ufybjzzgfsRuqW+wWnA8RTLuCIg9ScooMYGPwv0/42uq/gEDyLbB7ThGgZ9 BFJsEE9avk8cp33uOWhlBR0blkSQc/ipzCw4iGpaLocv8PpmlNmVKll80E4p3DDz/IBT vAZBEwS8LKPIy9EmdXeyf8udo8dLWl7Zi84/bdJtn/GaNYduECEMUujTe3t03buQ5rTO G1lmAdpqNSEvzSyxx6MBgQ2jBwRKQQZgdWKlwNoghzrIb7oFZ/MQ9VroVEbddGAqp7tV 95PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=d3ECIsRGngFyFH2jbVLH1ZsB1j4Lio7jznUTM12k5iY=; b=nXwFxjlV0X20s52h7D6/1JDvJTIBmD9nowdo2PRb8RmBhBF4yqeKQUxVJEsjqHYabO dJCHYcvC903/lRFCbfr9jbpYuTHTWWU6ef+kx4hf6OZMuIh6hMXFGrihrXAZQA6yMP7F +dupGcoDC5QTZmfqxvdpSWtp/FNb42p2XCtCq5Cjf4vQ4oOrhVgLw2hiCjJeF0WvRdhg QoEz+v3dPcTFsUoAuMxzqthbOZbAHaW14vopjOPwa6c165jhn3MxXrUGruRKb+Htsw9n qw283UjTVWWcdk5X7+l3Airh7iqWNZ5Wvm1tSN9WwqWHaPo0NYue/j6NDoXWjaZKodmZ LGfQ== X-Gm-Message-State: APjAAAWvIxSI1jjweGqu9KlPcQRgypJpAKwTZY09IYFxRBabDIZjvK/5 br3xZZCQYqlwhhEhBu8PxK5ql+L9yq77R4Ln8zynwXapLJqm+Rx+ X-Received: by 2002:a05:600c:114e:: with SMTP id z14mr390682wmz.61.1568220718948; Wed, 11 Sep 2019 09:51:58 -0700 (PDT) MIME-Version: 1.0 References: <20190911122646.13838-1-will@kernel.org> In-Reply-To: <20190911122646.13838-1-will@kernel.org> From: Ard Biesheuvel Date: Wed, 11 Sep 2019 17:51:38 +0100 Message-ID: Subject: Re: [PATCH] module: Fix link failure due to invalid relocation on namespace offset To: Will Deacon Cc: Linux Kernel Mailing List , Martijn Coenen , Greg Kroah-Hartman , Matthias Maennich , Jessica Yu , Catalin Marinas Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 11 Sep 2019 at 13:26, Will Deacon wrote: > > 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. > The build tests all passed, and the boot tests that have completed by now all look fine, so Acked-by: Ard Biesheuvel Tested-by: Ard Biesheuvel > 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 >