Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp691882pxx; Wed, 28 Oct 2020 14:39:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpO/WR6FnVoSE2lL63wRe7kAa43c6rel3ABTc52dsPxH1FOyK+NF6RH3MjjWFQjk1zf0uu X-Received: by 2002:a05:6402:c12:: with SMTP id co18mr957623edb.162.1603921175429; Wed, 28 Oct 2020 14:39:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603921175; cv=none; d=google.com; s=arc-20160816; b=xd5YWkP2S2a34OzUcl1q+JuquQdhfH3fMl6CwW0ZcaUEXMwlC5ykyy5i850qqN2W5g l1YE8RDnbYfQX9Sre0iHgvoeUT+9/oRQYUlQKBPLEw+Y1PhLMV+c1VKPWBMg7oC/CiDM c9HRTu0evdDtG3zSMULk8PZQ69b0UWVwMoiIaRJ88thycKWDDyAl1usuh/28ahd1vqGM p6s9ZaNu1Wi7BA2XD8mE7+az6APImGpbkNSlmKA3eY9DbCxcafY0MY5CHgn1qqkSRCp2 WqokVPhjbcTgIWQwTDvWh7WO9GdympP3BJhsWMPy4cz76LWTe8utbUNIONCds3QB/6oH g7Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=R+TzVjMGuuOAhuzCd/X5fEku0ly/jO19B59u1oK4LbQ=; b=RiSkXZ4vAReB0XuIwYJx49aH1J0Hs3YDae1rCuD/V5haGKkl9Kfu7C9Xo5Sp+ZP1Ps VtokXHy2HM3kwBjXTwXoQ4kE7cUTfBnYDnpKjbtnqycNlSK2Z2jMtWGx4Q+Vq8u9twsp 9GHaFKCMgGbvP8SVdsNLYVPZv4EXIYhgB2bwbx04O9E01AX/zMHecAxFseG842q+bdgC lTZFpSHI0V4n643EvWlokB/cCnn5078XkUBP8gHFB4oVaaFJGY6KAUReo8Axb155Ip6O ZVpJ/XcH43SBHiOw+zLYlG7Ffw34LNCaT0kXvfRxBXu3fPfjiM7ljZ9UyhMj9fgh8dNz ql4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Okz3JM1X; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gz19si399342ejb.18.2020.10.28.14.39.13; Wed, 28 Oct 2020 14:39:35 -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=@google.com header.s=20161025 header.b=Okz3JM1X; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1832250AbgJ0WSU (ORCPT + 99 others); Tue, 27 Oct 2020 18:18:20 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:35589 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1832245AbgJ0WST (ORCPT ); Tue, 27 Oct 2020 18:18:19 -0400 Received: by mail-pg1-f196.google.com with SMTP id f38so1602263pgm.2 for ; Tue, 27 Oct 2020 15:18:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=R+TzVjMGuuOAhuzCd/X5fEku0ly/jO19B59u1oK4LbQ=; b=Okz3JM1XL2nGsxb1umt2mHqpIKQ+k+MWyuFrfrCyx40mavkIIWPiaIfEkAuBDROdJe tlbiQ/Gr4XoD+3zlQLbIrm/t9pU0Z2mlENWFUMLC9JsXD9e4QSxvs1De7eZtcmAis+tk 7ZQwLnxij0pofykJ1B3MrMtMPz1yQ4rwRkYb7PWjYh9DFctmRPVhDMWIS6XCWIG7CIfS PWvvifkuQY6SkpIfAEPngT3HmkdvtSeUaZbEjZt//6hWmBqxmfRgD4wAdpjQzwyhXRht jokEHxj7qc0Smu0DhMj8vYHrAxK1OMgmABWamWw/UxwP12Jeckngab4TJXFNy3NYarKH SMLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=R+TzVjMGuuOAhuzCd/X5fEku0ly/jO19B59u1oK4LbQ=; b=ZYjEF2FQ3R3FNI1auyLqlbQzKmMzaIj8fVSqZyTzT9sZ7qaycsaEXo5BzMBxsKbBIt ovPFE8oOEafUg5FEGCfIx5LrqUJ2fDIdys7MpzNb/YNw1bkjWSHlaf1kzxTj1wQF6FEZ oF4kLT1t9EOp57gKkScUYG+NnycFF2cgb/Ssz/9UFrl6oi3MySUrNtCNysz4q9ncdJ1G nA6Fgoj8mMGxegC6R2Kny1tJFc4b/TtnxVT/bDY6OWW/vhutBR/bpOMHAhg0qFg5pjyn /5/fRJQZkUnrGBNlWuWN0SjJQUfs1MAL+x51QDDgrgXSkuRaPzUqQqGQChpnOwgfJNpr qP2w== X-Gm-Message-State: AOAM530hCPPmTSgL7cOKbYCTfN5OAtplUTQPtqst93XV2rkLrUX1fujO NP2X2J/JyyfARmu6fJ/CDF042CCI1c6xew== X-Received: by 2002:a63:5d44:: with SMTP id o4mr3552930pgm.409.1603837098358; Tue, 27 Oct 2020 15:18:18 -0700 (PDT) Received: from google.com ([2620:15c:2ce:0:a6ae:11ff:fe11:4abb]) by smtp.gmail.com with ESMTPSA id s131sm3183027pgc.18.2020.10.27.15.18.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 15:18:17 -0700 (PDT) Date: Tue, 27 Oct 2020 15:18:14 -0700 From: Fangrui Song To: Ard Biesheuvel Cc: Nick Desaulniers , LKML , Linux ARM , Will Deacon , Catalin Marinas , Jessica Yu , Kees Cook , Geert Uytterhoeven , clang-built-linux , linux-toolchains@vger.kernel.org Subject: Re: [PATCH] module: use hidden visibility for weak symbol references Message-ID: <20201027221814.rkm73l5dtyysvagj@google.com> References: <20201027151132.14066-1-ardb@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org One nit about ".got" in the message: Reviewed-by: Fangrui Song On 2020-10-27, Nick Desaulniers wrote: >+ Fangrui > >On Tue, Oct 27, 2020 at 8:11 AM Ard Biesheuvel wrote: >> >> 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, .got -> .got.plt be2881824ae9eb92 does not ASSERT on .got (it can). Strangely *(.got) is placed in .text in arch/arm64/kernel/vmlinux.lds.S I think that line can be removed. On x86, aarch64 and many other archs, the start of .got.plt is the GOT base. .got is not needed (ppc/arm/riscv use .got instead of .got.plt as the GOT base anchor). >> 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). Confirmed. >> 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. Yes, the R_AARCH64_CALL26 relocation referencing an undefined weak symbol causes one .plt entry and one .got.plt 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 >> > > >-- >Thanks, >~Nick Desaulniers