From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2EC1C433E7 for ; Wed, 14 Oct 2020 22:55:31 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2E8412078A for ; Wed, 14 Oct 2020 22:55:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="f+2vcjvN"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="QpUrFNEH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2E8412078A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jFTEcY6hjdPrmmcjsR1A0fpE5MkO/a16z1rFYGpyhO4=; b=f+2vcjvN8i7vZX1eT0nk9PtZq SE/MQueFOalahw2nCjmxdwwFOKcYy9wJ9qJd3XsjaK4CX41h8n2rEY4c51xHr2dsqe04QVpEG6RV1 pJqxJxzMnJ/a+DodWNCgP9RslsQ+Lu2JaTVn+XGt/jX7yVQpX30Ysmu9MwnwgBNhC2ronE57T9Ez1 1ODn6JHna3ar/mcY/ltsmPms2uceljVoKEP2rDZ5GwA0zZb/2Zr16hS39UyAIcj+cTNedFzZX5AOp 5dvTkep4vNQgjWrWmIyMoSo9HJRBlgiyPHiX7wZ6LyqRxwr/sVo2M1s7lVRm13IlB0oaTm9eIJWE+ J2R16di9w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kSpem-0005K4-SR; Wed, 14 Oct 2020 22:54:04 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kSpek-0005Eu-Ts for linux-arm-kernel@lists.infradead.org; Wed, 14 Oct 2020 22:54:03 +0000 Received: by mail-pl1-x641.google.com with SMTP id v12so469945ply.12 for ; Wed, 14 Oct 2020 15:54:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Q8SxKFJ37keEA3fcjeZ0MUjIlmAhyy2Ds4RMjo12YH0=; b=QpUrFNEHB+eD+KCRl2HFxnlSp1vyTwWjRHJ5V7CaCjVOqpSlZIknEXyWQPVpbQ+cM1 3i42ZiG9dAhIxqD8odiXtSLMX3J6wsygKL5cMccgJlHcYjee0k8wg7sSqGzv5GnU6ZI3 skUQeZ1p5r7C9RZcDY+bIpWwe/Uz2In5VWAfQ= 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=Q8SxKFJ37keEA3fcjeZ0MUjIlmAhyy2Ds4RMjo12YH0=; b=E/qOcHUvubEMN096uz1swkDYO6VB2qJU+L9C89Ts9p/feoEzl1Vpgd1Fhg3h1F0RL3 3VOuFmwJWu7USMBEC0S5KojEYMqJ53SG2a03Fkr60HBFO1l4R+/gaawSs7uzXI+wWiKa C+ILNAs9eGcLc/T4lzgyHSDUcfI5ED8zkeT86gZx/E0SbhXiEi9dXCMknJsh2AUZYJCr M1xWOnnnZuuNQqErA8gWAPzTn4pq5PlzsWO5jYf1v9XePk+pacAQRTVDIgKKDE008pRa sZeVh7ujuq6qR7tB5p/dKZpIZedVKzN/31GOtxcNX7oS/TD7flaVxVgzXGoOMET3jpkk HGDA== X-Gm-Message-State: AOAM531fw7yX9/9prkFsAH6CKgY72tnXTh2ZPD1c7UVJZEAFj9+jtomB crsYvYIEnIkhfsPEpA3XwYva6w== X-Google-Smtp-Source: ABdhPJwJ4ghnrKefm3Ds7OP+vaaqBOqNCgcbWcY/kWoZDzqVnqAP2a2SLXiCE9xOBsgOh/pHszIHUg== X-Received: by 2002:a17:90a:cb91:: with SMTP id a17mr1300337pju.220.1602716041061; Wed, 14 Oct 2020 15:54:01 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id k11sm643943pjs.18.2020.10.14.15.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Oct 2020 15:54:00 -0700 (PDT) Date: Wed, 14 Oct 2020 15:53:59 -0700 From: Kees Cook To: Masahiro Yamada Subject: Re: [PATCH v6 16/25] init: lto: fix PREL32 relocations Message-ID: <202010141552.9172003F6A@keescook> References: <20201013003203.4168817-1-samitolvanen@google.com> <20201013003203.4168817-17-samitolvanen@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201013003203.4168817-17-samitolvanen@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201014_185402_975427_0A8665CA X-CRM114-Status: GOOD ( 21.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, x86@kernel.org, "Paul E. McKenney" , kernel-hardening@lists.openwall.com, Peter Zijlstra , Greg Kroah-Hartman , linux-kbuild@vger.kernel.org, Nick Desaulniers , linux-kernel@vger.kernel.org, Steven Rostedt , clang-built-linux@googlegroups.com, Sami Tolvanen , linux-pci@vger.kernel.org, Will Deacon , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Oct 12, 2020 at 05:31:54PM -0700, Sami Tolvanen wrote: > 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 This is another independent improvement... this could land before the other portions of the series. -Kees > --- > 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.1011.ga647a8990f-goog > -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel