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 A5CBBC433ED for ; Tue, 6 Apr 2021 11:27:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6BADF61246 for ; Tue, 6 Apr 2021 11:27:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245502AbhDFL1c (ORCPT ); Tue, 6 Apr 2021 07:27:32 -0400 Received: from foss.arm.com ([217.140.110.172]:41182 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245477AbhDFL13 (ORCPT ); Tue, 6 Apr 2021 07:27:29 -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 43D8E31B; Tue, 6 Apr 2021 04:27:20 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C66723F73D; Tue, 6 Apr 2021 04:27:15 -0700 (PDT) Date: Tue, 6 Apr 2021 12:27:06 +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 03/18] mm: add generic function_nocfi macro Message-ID: <20210406112656.GA96480@C02TD0UTHF1T.local> References: <20210401233216.2540591-1-samitolvanen@google.com> <20210401233216.2540591-4-samitolvanen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210401233216.2540591-4-samitolvanen@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 01, 2021 at 04:32:01PM -0700, Sami Tolvanen wrote: > With CONFIG_CFI_CLANG, the compiler replaces function addresses > in instrumented C code with jump table addresses. This means that > __pa_symbol(function) returns the physical address of the jump table > entry instead of the actual function, which may not work as the jump > table code will immediately jump to a virtual address that may not be > mapped. > > To avoid this address space confusion, this change adds a generic > definition for function_nocfi(), which architectures that support CFI > can override. The typical implementation of would use inline assembly > to take the function address, which avoids compiler instrumentation. > > Signed-off-by: Sami Tolvanen > Reviewed-by: Kees Cook FWIW: Acked-by: Mark Rutland Mark. > --- > include/linux/mm.h | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 8ba434287387..22cce9c7dd05 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -124,6 +124,16 @@ extern int mmap_rnd_compat_bits __read_mostly; > #define lm_alias(x) __va(__pa_symbol(x)) > #endif > > +/* > + * With CONFIG_CFI_CLANG, the compiler replaces function addresses in > + * instrumented C code with jump table addresses. Architectures that > + * support CFI can define this macro to return the actual function address > + * when needed. > + */ > +#ifndef function_nocfi > +#define function_nocfi(x) (x) > +#endif > + > /* > * To prevent common memory management code establishing > * a zero page mapping on a read fault. > -- > 2.31.0.208.g409f899ff0-goog >