Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp264102pxf; Thu, 25 Mar 2021 03:39:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVQcTlxc6S8eybL6LXuHPBidVJPkgnL9E92ImAaaBkDeKGveMUeW99Ov6FbfHXFUxM5kPx X-Received: by 2002:a17:906:7150:: with SMTP id z16mr8498768ejj.103.1616668779061; Thu, 25 Mar 2021 03:39:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616668779; cv=none; d=google.com; s=arc-20160816; b=ytRs3EgGO3GpfVmVZS0BsscR8Ku3mTqdmt3zvodWr+jBKN9N3+gE94ZSKqEmQ6bgew bzpDbt2Pb38xCif64kHY56j1YxV4YkDyN1oDqDSVOcCXp5Rmn1kwAFBJ0qSqe0Agl73S QSkx+aO6cAHDRuh7bkYkUVMSqMQM7iVxMaGR2vRVYgC5vKeQZeVh82pDu0Q3r/PiwP1f ghpH1fr8h9Ghbht+CIbLIn14dnxU2EQEHy3I0eAmxv1v1QTMBN2LWI1BFDtmey6p6n3W KOiigxWMJMtQMYLE4LPQnISxq9sWPcPerPO2r5exO6MD0XayQetSmxcV2MFkVPbDRjbX JBRg== 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; bh=BaHoQwnfERYtIt87dRD7Gjzy27FQyBIiWEzrfq5Frcs=; b=OCRza/WGlKsNXoNVt8Q9jU0nV2Ao1/chHVS+DUVoihgagvlGFNip4grAi/+DRpu/Rp hQXDCHPpy8wkpzsngJzJGcroR0Ts/Com7f4gs/MngSksSHdfXBnngTNY1XyqQQ5iYfqO cUCqZ9dOYMOrJHGnIPmkWxMChMxr9bu6M9QyrYnDp0KXAXK7mFu8Vw60hIwgQNvr7TaC fWTpGYZe/uYirOsVq2KZmafBkI2KNmfRqGSDnxp6XGVVAW127vh3ct+S1V7+cFKZ+v+H LBkzoC4gGlf5Kx0ozI72UNU5GuGLgAwrNUGj5loUzS5u4iZCxCSEXU8ofqBNPtU7CpOW zM8w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l23si3811745edv.176.2021.03.25.03.39.15; Thu, 25 Mar 2021 03:39:39 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229979AbhCYKiQ (ORCPT + 99 others); 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: linux-kernel@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 >