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=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 64D17C433DB for ; Thu, 25 Mar 2021 10:38:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 12666619B3 for ; Thu, 25 Mar 2021 10:38:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229854AbhCYKiQ (ORCPT ); Thu, 25 Mar 2021 06:38:16 -0400 Received: from foss.arm.com ([217.140.110.172]:46110 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229631AbhCYKiF (ORCPT ); Thu, 25 Mar 2021 06:38:05 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 077AA1424; Thu, 25 Mar 2021 03:38:05 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 023E23F718; Thu, 25 Mar 2021 03:38:00 -0700 (PDT) Date: Thu, 25 Mar 2021 10:37:57 +0000 From: Mark Rutland To: Sami Tolvanen Cc: Kees Cook , Nathan Chancellor , Nick Desaulniers , Masahiro Yamada , Will Deacon , Jessica Yu , Arnd Bergmann , Tejun Heo , "Paul E. McKenney" , Christoph Hellwig , Peter Zijlstra , bpf@vger.kernel.org, linux-hardening@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kbuild@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 12/17] arm64: implement __va_function Message-ID: <20210325103757.GD36570@C02TD0UTHF1T.local> References: <20210323203946.2159693-1-samitolvanen@google.com> <20210323203946.2159693-13-samitolvanen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210323203946.2159693-13-samitolvanen@google.com> Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Tue, Mar 23, 2021 at 01:39:41PM -0700, Sami Tolvanen wrote: > With CONFIG_CFI_CLANG, the compiler replaces function addresses in > instrumented C code with jump table addresses. This change implements > the __va_function() macro, which returns the actual function address > instead. > > Signed-off-by: Sami Tolvanen > Reviewed-by: Kees Cook Is there really no attribute or builtin that can be used to do this without assembly? IIUC from other patches the symbol tables will contain the "real" non-cfi entry points (unless we explciitly asked to make the jump table address canonical), so AFAICT here the compiler should have all the necessary information to generate either the CFI or non-CFI entry point addresses, even if it doesn't expose an interface for that today. It'd be a lot nicer if we could get the compiler to do this for us. Thanks, Mark. > --- > arch/arm64/include/asm/memory.h | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h > index 0aabc3be9a75..9a4887808681 100644 > --- a/arch/arm64/include/asm/memory.h > +++ b/arch/arm64/include/asm/memory.h > @@ -321,6 +321,21 @@ static inline void *phys_to_virt(phys_addr_t x) > #define virt_to_pfn(x) __phys_to_pfn(__virt_to_phys((unsigned long)(x))) > #define sym_to_pfn(x) __phys_to_pfn(__pa_symbol(x)) > > +#ifdef CONFIG_CFI_CLANG > +/* > + * With CONFIG_CFI_CLANG, the compiler replaces function address > + * references with the address of the function's CFI jump table > + * entry. The __va_function macro always returns the address of the > + * actual function instead. > + */ > +#define __va_function(x) ({ \ > + void *addr; \ > + asm("adrp %0, " __stringify(x) "\n\t" \ > + "add %0, %0, :lo12:" __stringify(x) : "=r" (addr)); \ > + addr; \ > +}) > +#endif > + > /* > * virt_to_page(x) convert a _valid_ virtual address to struct page * > * virt_addr_valid(x) indicates whether a virtual address is valid > -- > 2.31.0.291.g576ba9dcdaf-goog >