Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp381292pxu; Tue, 1 Dec 2020 13:42:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwiUJWYxW9g+AREkOlpikJNTgBl5fWAguuVtGrfoRbR/nmSNsW1p4IuPdA5FiGCOUtDZSFf X-Received: by 2002:a17:906:f117:: with SMTP id gv23mr5068476ejb.196.1606858946031; Tue, 01 Dec 2020 13:42:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606858946; cv=none; d=google.com; s=arc-20160816; b=ENae34/6z+PgmbSz9TcrH5rn8HkztAqzwFOglJ2DftkSjKnBE5GNN0FD6D4Wg/oLXz BHIIzKBxn61XpFR/C+xsyDGRDVG6z0EnqezZEh+6PWENHtAm/FTMMTEtC7DDLI+yfnlc GK1vzM/2MIJvhW2RhfD7UVvWizr5v9nBc76W2W1Powc0yuPyn6eVkN1CqUK/w6OSzwZF Z91VSeEPD7Wdd2tFmBRHbKg6v+/b1ghNlCZ8eBLi7DATbJym2Gw7idTvZZ4Y1qnOhA7f qgVPKtCvd18UT2Aj8h0lnU8ntJwRyQeltemmQuOnh8hGUe6stI15MyVkOZB2bFz1bhkg ECew== 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=9TLfWaf58UYL7wICLMCVVnhaOCpYf+H5DpQSRdiy6Cc=; b=NTS7kuRnxFy5mTZeTM3MVb/8uJspNv5Ge9pgJdpDGl+2hgkU0DzYxuuUTKOn+TS2fI 1H/g9AmOcT38OT1LBTWt5b0f4pQdgkCYIIlQLtKNKHn9qvxgllxxIHm1Mpkw3Wdf0JYj +PsAR3gti0GK6MC/Ud/wcfmr/Ge3q8tDGeb2hjHZP6ZfZC+JwZMyGOzm6tnBNpBWBaPh YY2kQSWKBRne+qWNFsgKbgGlQKIh9rviu+9YvwARBZn/sHaQEmhL64i+RwqQQyfRdPVb GXVG02xMV6jBlVIrzIzChjFxIlpDvgIlGaDL+F4Di1xAU7E1F9VeS3vKT0OTPL4ikMM2 vlag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZHmcfGNp; 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 b4si761027ejv.71.2020.12.01.13.42.03; Tue, 01 Dec 2020 13:42:26 -0800 (PST) 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=ZHmcfGNp; 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 S2388119AbgLAVjI (ORCPT + 99 others); Tue, 1 Dec 2020 16:39:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730355AbgLAVjH (ORCPT ); Tue, 1 Dec 2020 16:39:07 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA1F4C09424A for ; Tue, 1 Dec 2020 13:37:30 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id m186so4009548ybm.22 for ; Tue, 01 Dec 2020 13:37:30 -0800 (PST) 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=9TLfWaf58UYL7wICLMCVVnhaOCpYf+H5DpQSRdiy6Cc=; b=ZHmcfGNpa7ZNviH3Lhbi7/0SDEQ3Jls1Fd4loR1GsDVBD7tyPoyw8FMMexSiO0w9DW 9RjrozMTcLSgrBxEv1Vz8SoUuZs1OCJb++caQa3OdSsaiYW67cFBU7PQ9LNeGNpQOT/K 9NZ2TIpPQb7/71Uv+3b78ioZtiLnITOk2KjhIvpWKQSdMkCVpud7TsnvOO4ORqlpu2u5 nOj1pZxLhS/1QmdqjetYddIidvonWTCSBDRIzR5umGDHjrntwGXK/yd6oSDTP2uLIXdB crW36MjeZXAzVs/1lqNDI0q9ni6fGs696oymio04cAycbm2CdWTbsus3NowlMPBHIFwm bePw== 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=9TLfWaf58UYL7wICLMCVVnhaOCpYf+H5DpQSRdiy6Cc=; b=p9zd8lok51Ba0rmBV7XBW4FI3zLTapmOaWG+YsbnFlat6ATZBrlwc7hAmoS+yZl87s BhHx/3bNNUdDqUlg2I1SGUfB+27HpRWKovQ6HUOLSniOM9PkHXI4ug8zEHMaMboAT/XA G1wJNfnObFcBS1tWl4X2pwXB6WPcxorwX+zKtfKwk/Cx6KWlXQ5A6O+2KGSgpXeLwL1I q3hWEqpZ9OU8Mv5lITIqkXJ8JDm2s77oRmeSumo7P4Rth7+FpBQ1FvWI8BmL/c9a7vWg YhZOfcVaJVDN6yPn8x8LznJT+Tv3kFD0eSJBMX8KS6+upPoqLlJqi2DipN+47YK6xwCn bqTw== X-Gm-Message-State: AOAM533y1SKKvN4bduw9f/ng3nl+64oHOFW6NNiVcEF8DSz3a9U/hJgu AsjUxRd0p0ZjBlwA7oL9kBCeSDoCXOnydSh62FE= 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:a25:cf0a:: with SMTP id f10mr7383764ybg.353.1606858650073; Tue, 01 Dec 2020 13:37:30 -0800 (PST) Date: Tue, 1 Dec 2020 13:36:59 -0800 In-Reply-To: <20201201213707.541432-1-samitolvanen@google.com> Message-Id: <20201201213707.541432-9-samitolvanen@google.com> Mime-Version: 1.0 References: <20201201213707.541432-1-samitolvanen@google.com> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog Subject: [PATCH v8 08/16] init: lto: fix PREL32 relocations From: Sami Tolvanen To: Masahiro Yamada , Steven Rostedt , Will Deacon Cc: Josh Poimboeuf , 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, 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 d466bea7ecba..27b9478dcdef 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.29.2.576.ga3fc446d84-goog