Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp291503pxx; Wed, 28 Oct 2020 05:09:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4ZILcu+3dv2WOHGh4D3NaOGSCTD8CNY7bEtSl75KD/aIL9DsKZte39HWeAXlLdvpXlU9Y X-Received: by 2002:a17:906:b24c:: with SMTP id ce12mr7064801ejb.386.1603886995927; Wed, 28 Oct 2020 05:09:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603886995; cv=none; d=google.com; s=arc-20160816; b=Uo+4aUC+M3e2j1CglhFscNpDg4+KPa5gwSpSexPey/JBoArNFYIgkso+JfRikNCS8Y mZGsZ4eub7wkqF9hkI4VTMjJpbGwvItfi14HfdwMuLVdDOqrePCo1nm4bbLCAu/bGogB uRoop1o3GcLdHp2v71+jDsBm9vfgu0jzr59BoK0eIcwO6sR5cRBzPSuQJEZ7ucbz/TFz dGPTeuMXCsQgGS9x9JdAMPEq36cO5CC/M1Khoystp6kDrimFsMzB5FQ8i3AJjWV1Qmby E3oiGp/gsw0jJ5eKeMHf9h8Ow0fNh0jZauAx8SYgGRNDZoDYh5Vw+N/1gZHvPcINSMVb gfCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=tSAveALklgiTOQv/EjC3hD4wJPEL5gUnJxuzL5Tt/a4=; b=DjS0H8G5LsMiESFki6szenyC5gD1H0oqDkr9EN9rp6TUOid/uqmLCtE7X/XC9gYoga EXAl3kns5PM3y3Yu3jjGaWU7aevjK1X0++UZXhmEODKO2Zodu6wFpL72kmJyk/kzEIpL n0XEgdRnpdcyr6bt7Ez8QYTtVbv3y+VbOtwOnhPsSiV53AUlrbYCMucK2j8ufDQoZekF HcjgsihN0LsuWqy6dffYabdVNtLxbp7vgG1PM4VrYYSDINkTiiLWiRZP0vH2ASWeMPuI WFUnjQDmowI9QqM35SMJGeaRBpk/AEMQmSv3hZmNCDT3Z8LJ6BdFuWJLbU+6gxvL4/wr o13A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KnT5lraB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id p90si2749641edd.284.2020.10.28.05.09.33; Wed, 28 Oct 2020 05:09:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KnT5lraB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1795630AbgJ0PPR (ORCPT + 99 others); Tue, 27 Oct 2020 11:15:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:47790 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1794438AbgJ0PLu (ORCPT ); Tue, 27 Oct 2020 11:11:50 -0400 Received: from e123331-lin.nice.arm.com (lfbn-nic-1-188-42.w2-15.abo.wanadoo.fr [2.15.37.42]) (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 B6EF820657; Tue, 27 Oct 2020 15:11:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603811509; bh=MEOHJpFg/hSBwnyU+/C/N9+Qa7RXtkpK49digCQfxBc=; h=From:To:Cc:Subject:Date:From; b=KnT5lraBfZ/7vx1hN0P7obGVygBSAmfYDK5mhWAeewS2ufv945b4XfWIPctftNSu2 6uV1JiXXLV7UI09v6GGxXzmfoI3hQKzpePSNzgHbsdJQDf3txT0lub1uHSc+Qo5OQJ lMeyoA/vUucITAcnBqlmd1TsxQJZ0VFWzZINtLi8= From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, will@kernel.org, catalin.marinas@arm.com, Ard Biesheuvel , Jessica Yu , Kees Cook , Geert Uytterhoeven , Nick Desaulniers Subject: [PATCH] module: use hidden visibility for weak symbol references Date: Tue, 27 Oct 2020 16:11:32 +0100 Message-Id: <20201027151132.14066-1-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Geert reports that commit be2881824ae9eb92 ("arm64/build: Assert for unwanted sections") results in build errors on arm64 for configurations that have CONFIG_MODULES disabled. The commit in question added ASSERT()s to the arm64 linker script to ensure that linker generated sections such as .got, .plt etc are empty, but as it turns out, there are corner cases where the linker does emit content into those sections. More specifically, weak references to function symbols (which can remain unsatisfied, and can therefore not be emitted as relative references) will be emitted as GOT and PLT entries when linking the kernel in PIE mode (which is the case when CONFIG_RELOCATABLE is enabled, which is on by default). What happens is that code such as struct device *(*fn)(struct device *dev); struct device *iommu_device; fn = symbol_get(mdev_get_iommu_device); if (fn) { iommu_device = fn(dev); essentially gets converted into the following when CONFIG_MODULES is off: struct device *iommu_device; if (&mdev_get_iommu_device) { iommu_device = mdev_get_iommu_device(dev); where mdev_get_iommu_device is emitted as a weak symbol reference into the object file. The first reference is decorated with an ordinary ABS64 data relocation (which yields 0x0 if the reference remains unsatisfied). However, the indirect call is turned into a direct call covered by a R_AARCH64_CALL26 relocation, which is converted into a call via a PLT entry taking the target address from the associated GOT entry. Given that such GOT and PLT entries are unnecessary for fully linked binaries such as the kernel, let's give these weak symbol references hidden visibility, so that the linker knows that the weak reference via R_AARCH64_CALL26 can simply remain unsatisfied. Cc: Jessica Yu Cc: Kees Cook Cc: Geert Uytterhoeven Cc: Nick Desaulniers Signed-off-by: Ard Biesheuvel --- include/linux/module.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/module.h b/include/linux/module.h index 7ccdf87f376f..6264617bab4d 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -740,7 +740,7 @@ static inline bool within_module(unsigned long addr, const struct module *mod) } /* Get/put a kernel symbol (calls should be symmetric) */ -#define symbol_get(x) ({ extern typeof(x) x __attribute__((weak)); &(x); }) +#define symbol_get(x) ({ extern typeof(x) x __attribute__((weak,visibility("hidden"))); &(x); }) #define symbol_put(x) do { } while (0) #define symbol_put_addr(x) do { } while (0) -- 2.17.1