Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp136771pxf; Tue, 6 Apr 2021 17:22:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQ+o7SH7xrcgIENHCyIXEhPqEvUSe/870UXC6hbhWSzrIqVUXM3+hG+ZTZwi08hi/Ip8s5 X-Received: by 2002:a05:6402:95b:: with SMTP id h27mr1154368edz.93.1617754966156; Tue, 06 Apr 2021 17:22:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617754966; cv=none; d=google.com; s=arc-20160816; b=sl9QuxyqBC0hddzy2AvNaUOq1WCwpBkJWp0f5LM1iVCHWVa/pXvy4P5a9EQT6l6YnH XaPgvMk9EI7pR4DHjm1xEUOaZd7629eCwm6HlfYmd1Zc6PJDKQ4pXwXVFeRf0soXbbji ZAHjgOuSO+pDi0mK+i0AlIyXmp63FAFKwKgd335o5ZEBeJUMg0tF1FaAKSwq/IkHJAJf KNiwTpGp1uiHILax4eT8ZlBZZUkK08MqK9Pm6UkpSjCtDGX2LL/GMouS6ftenflyXRg0 IStcJ2WirpZ+NsvLeUGT83injIzM3QYWtgA4PkB+mI23+8dtkHr5Kjd6pYouiTQaX0hF w2hA== 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=q8Ycajj0kp78JXDEiELXeDa5baqs7WZPtTYlQ/3ohb4=; b=h3gotkpaJxuUOfIRkI5RnfKL9sHbXdjvibQOVyaAqRveDNeWcz02OwiaRF9YxvIZjf SyKwecF731QaU1Uph3/PBNTDQ7imZ1bogspXvj3Mk5nKfyChzp5E+we9ALa91pHeV64S eXWPxZuTQMwZEh/ck6JxPAEtHy91wOR9cMktcjFyhCedp/iKGcwL2uH8QfLbV4TxLEyr Pl9enUSqHp5HeHLP0DmYiqn7FMiuanZ5H4n2uVjLkM3Z2OBEar1tDTeBwfRDgav7SrQx S4Hpos+STJWSBjPH/NBW859jm6CCyh3aTs+1oFCZxL42LENAD9O0JayRrXvBhIEkdoBS 3+QQ== 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 h10si6124853edr.232.2021.04.06.17.22.22; Tue, 06 Apr 2021 17:22:46 -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 S243133AbhDFLhQ (ORCPT + 99 others); Tue, 6 Apr 2021 07:37:16 -0400 Received: from foss.arm.com ([217.140.110.172]:41426 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241774AbhDFLhO (ORCPT ); Tue, 6 Apr 2021 07:37:14 -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 EF9C9101E; Tue, 6 Apr 2021 04:37:05 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 243363F73D; Tue, 6 Apr 2021 04:37:00 -0700 (PDT) Date: Tue, 6 Apr 2021 12:36:57 +0100 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 , Sedat Dilek , Catalin Marinas , 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, clang-built-linux@googlegroups.com Subject: Re: [PATCH v5 12/18] arm64: implement function_nocfi Message-ID: <20210406113657.GC96480@C02TD0UTHF1T.local> References: <20210401233216.2540591-1-samitolvanen@google.com> <20210401233216.2540591-13-samitolvanen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210401233216.2540591-13-samitolvanen@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 01, 2021 at 04:32:10PM -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 function_nocfi() macro, which returns the actual function address > instead. > > Signed-off-by: Sami Tolvanen > Reviewed-by: Kees Cook I think that it's unfortunate that we have to drop to assembly here, but given this is infrequent I agree it's not the end of the world, so: Acked-by: Mark Rutland > --- > 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..b55410afd3d1 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 function_nocfi macro always returns the address of the > + * actual function instead. > + */ > +#define function_nocfi(x) ({ \ > + void *addr; \ > + asm("adrp %0, " __stringify(x) "\n\t" \ > + "add %0, %0, :lo12:" __stringify(x) : "=r" (addr)); \ If it's not too painful, could we please move the asm constrain onto its own line? That makes it slightly easier to read, and aligns with what we've (mostly) done elsewhere in arm64. Not a big deal either way, and the ack stands regardless. Thanks, Mark. > + 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.208.g409f899ff0-goog >