Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4109932pxk; Tue, 29 Sep 2020 14:49:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdWwyhx+2Wn7XuAh103t09k8eeeKvh1K6MuQw8IiButcUF2pdmKIyPxqr4taJ+32U2VtVc X-Received: by 2002:a05:6402:1b9a:: with SMTP id cc26mr5432828edb.30.1601416197200; Tue, 29 Sep 2020 14:49:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601416197; cv=none; d=google.com; s=arc-20160816; b=aCLyj8NarsHEMZ2Xl7SxlSmu7jBg7kDigd7s0veidIVVPsqLsuRz+rbNox3zdiOfFJ 6rd7tcEPG65J+fp1FmgRHPHWr166ERJzu95VinPpTNWrr9bztbh+D7yFFIlkP/IEQX80 ZFmrOV+zMW4x8nBLxB5+A43uHpldhg4FyW8iSo2U0OaFATJlxPwJt2XwUotWtrZ2ZlEM hnFa3AetsPh+2LgEvvxbqysKlckaLvmYgOo92NC9KIM03r3UeFmIw0M3ge9fYCp1qi42 EHmSx/sKfp99FecI/H/PbqWwHC3JyjHkg+M77UYSxn5Yd78QJOcY4yj7Z8+zYDW3MEKD tFgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=/vP7q5BBB0uTfRm2AgwdilGSRfsWzFPQ2WkTiyoFr6c=; b=YUAiiENfiSioNofBeWWl8IQbdc2N76E5H1OiYIA+W4zWdQ4i/SRA5j8Ip01J4UL7tr E79RKizGWfeNBtFgNmB5ml2OpuIk/GCShbIKgnz9obKuPf9cnTdfOopfEG7TUgQJ5K8m Ay6IAhGnC5db+56AkY/oLIr23x7hmLjDTup201Lfg8vSQMF7QexxeZf187V7lUAb8qeT 72fACSthmWx50slkTVASvXolJbxpCvxaBs8Lz8ZSX1IYgIWqS+PS59c0PIHnABdfqJhY FqjedAzHqPMK8hVEvcqfUcoKmRNMN29fqJRRBFWZ7Kd7OmKnI8IUlJHAgV3ESqsCkTX6 T41Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=b55hwPid; 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 mb18si3800049ejb.680.2020.09.29.14.49.34; Tue, 29 Sep 2020 14:49:57 -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=b55hwPid; 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 S1729031AbgI2Vrv (ORCPT + 99 others); Tue, 29 Sep 2020 17:47:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729050AbgI2VrW (ORCPT ); Tue, 29 Sep 2020 17:47:22 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96B7FC0613D5 for ; Tue, 29 Sep 2020 14:47:14 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id 135so4878520pfu.9 for ; Tue, 29 Sep 2020 14:47:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=/vP7q5BBB0uTfRm2AgwdilGSRfsWzFPQ2WkTiyoFr6c=; b=b55hwPidpBtwXSYzPL7nG9/Vda7JuMVr/EGJixbfG0vXQwUBtPjkDoj3MJOTqZMsWM vzguUIrKQvSlcJMS9LcTLx25efyz9HzS/XNyEl+Vmt3JZFYWS9Xi9CW480UD18Iv8V/8 Zv0q3PdFWw+MxCu1kPSRKo5b5kauZeRMwrGkfiXKdlBUKbyUb+Mx09RiNdFeO5g1b1k/ MGs4GivcBr1kLWAINFKbVMCXqvyatQdyLKZ3K2d+FSPXYNUWpizBFCZ7ExOm+k6gsGZr 9pRIvsrPB/pkdVgUtISLhxoJY5If1dpdNi3Vrr64TIoPSMdOxtuHEgcrwzGEARSD2d7Y rM6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=/vP7q5BBB0uTfRm2AgwdilGSRfsWzFPQ2WkTiyoFr6c=; b=tehSUSO28EuWuR6en26TQNt3z+DrB4Z9lfskKAuS35M2ezW7ZfxvU6BftcHyKY3eJq lsD1tOsAuKICovcDS455UZ378mh1BftUM2O5alGY2VZHRNT93a4fbSkbBZ852g0RFOtI QZLnCzyHYTXO/NgDGwjht6XEK5ePRlqmz4crGywTYpKATGAdeoed6HvD62fpN6SbTBTZ XXBslDaTQQkK7GFv31T7JZ0s9ztBtOS9yNtMHVfLuA5gkhmX+VXigYpsj1tmKttveatg WzyqjAGrF9rRzO6XnL9TxKxGivymOQcxunNf/ijtxyCdo28VggwE+O+Zy4I4I20YfKj4 QFJg== X-Gm-Message-State: AOAM532WDqJjavfbtrXPqSKxcxLshxXIMIya+Uf/ybWfrQJL0m+PMvvx 5E+Qhb6Y+UHglUpzF9y91J6l0TNw+WdzoVUgbaM= Sender: "samitolvanen via sendgmr" X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:f693:9fff:fef4:1b6d]) (user=samitolvanen job=sendgmr) by 2002:a63:e813:: with SMTP id s19mr4805529pgh.33.1601416033950; Tue, 29 Sep 2020 14:47:13 -0700 (PDT) Date: Tue, 29 Sep 2020 14:46:20 -0700 In-Reply-To: <20200929214631.3516445-1-samitolvanen@google.com> Message-Id: <20200929214631.3516445-19-samitolvanen@google.com> Mime-Version: 1.0 References: <20200929214631.3516445-1-samitolvanen@google.com> X-Mailer: git-send-email 2.28.0.709.gb0816b6eb0-goog Subject: [PATCH v4 18/29] init: lto: fix PREL32 relocations From: Sami Tolvanen To: Masahiro Yamada , Will Deacon , Steven Rostedt Cc: Peter Zijlstra , Greg Kroah-Hartman , "Paul E. McKenney" , Kees Cook , Nick Desaulniers , clang-built-linux@googlegroups.com, kernel-hardening@lists.openwall.com, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, x86@kernel.org, Sami Tolvanen Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With LTO, the compiler can rename static functions to avoid global naming collisions. As initcall functions are typically static, renaming can break references to them in inline assembly. This change adds a global stub with a stable name for each initcall to fix the issue when PREL32 relocations are used. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook --- include/linux/init.h | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/include/linux/init.h b/include/linux/init.h index af638cd6dd52..cea63f7e7705 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -209,26 +209,49 @@ extern bool initcall_debug; */ #define __initcall_section(__sec, __iid) \ #__sec ".init.." #__iid + +/* + * With LTO, the compiler can rename static functions to avoid + * global naming collisions. We use a global stub function for + * initcalls to create a stable symbol name whose address can be + * taken in inline assembly when PREL32 relocations are used. + */ +#define __initcall_stub(fn, __iid, id) \ + __initcall_name(initstub, __iid, id) + +#define __define_initcall_stub(__stub, fn) \ + int __init __stub(void); \ + int __init __stub(void) \ + { \ + return fn(); \ + } \ + __ADDRESSABLE(__stub) #else #define __initcall_section(__sec, __iid) \ #__sec ".init" + +#define __initcall_stub(fn, __iid, id) fn + +#define __define_initcall_stub(__stub, fn) \ + __ADDRESSABLE(fn) #endif #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS -#define ____define_initcall(fn, __name, __sec) \ - __ADDRESSABLE(fn) \ +#define ____define_initcall(fn, __stub, __name, __sec) \ + __define_initcall_stub(__stub, fn) \ asm(".section \"" __sec "\", \"a\" \n" \ __stringify(__name) ": \n" \ - ".long " #fn " - . \n" \ + ".long " __stringify(__stub) " - . \n" \ ".previous \n"); #else -#define ____define_initcall(fn, __name, __sec) \ +#define ____define_initcall(fn, __unused, __name, __sec) \ static initcall_t __name __used \ __attribute__((__section__(__sec))) = fn; #endif #define __unique_initcall(fn, id, __sec, __iid) \ ____define_initcall(fn, \ + __initcall_stub(fn, __iid, id), \ __initcall_name(initcall, __iid, id), \ __initcall_section(__sec, __iid)) -- 2.28.0.709.gb0816b6eb0-goog