Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp848714pxb; Wed, 6 Apr 2022 01:50:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyC3jRvw/NDK4fn6mEqtplUvnHmkwvN6Tt5gZX9yJ647yFXeyo5PGH6FSUVbXKtpXzCVA/4 X-Received: by 2002:a63:7e43:0:b0:374:75ce:4d80 with SMTP id o3-20020a637e43000000b0037475ce4d80mr6314626pgn.589.1649235039073; Wed, 06 Apr 2022 01:50:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649235039; cv=none; d=google.com; s=arc-20160816; b=XkSqmYdDiD3ZXK5aedcEnT6CvpQU676T2qc1XfBGKomOnkBREUq82Hj8lzgI6b6EXI e9rJUv2X8xt7jQ9/PgBZzEvOdFwbkXpfIjI5Ee1vorhuYfKdhf2YctWTilJ00W/X+x5C yGQ811MlgS+p/1hP3tE2YmJkN4LPXfVj03piZkbagt/DDNv2LkTXbNhoNYQOqxiWhqWK SCOwsAS3c81FVr3bpwwp8HTboHnQB4/6Y87GX2sT92ua5Hq5x2hPpfSyVF6dqbe2QerL RC2m2Z9wRalA1yLQed8AAsqPwE4vzNZMEwcLHcHV6C+VVUZc7qYB5+551eIUsE4CsZPw cLUw== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Ex7BqlrTi5qkeIo57to/b5FLM7fl0uyTyws4U9bqDac=; b=rBNTOYwhWFcvqMeOIdo3gIcefn1bekU+5SZSu1McBIqF13l5SuBGubAcM0uY6XS0fJ ZPfAmnouMKGcu9AJAspK+GJTiPGfZG2HYDxZ9bKzMpO6L36stuLiGoGIXhxOW78MWBuy vdjgTrUwisYyY3MLYsTgHPZVu4wt/AY2IXkFRblud56G6ztiG5dDHiJ4ghOTTw3qSJbb o8HQI5sMayivdLcuo1UD/7XrMYimtGI1Go44uDkkv60Xuuj4uKP5MJ2al/R2l0EZsVFr mfbyfHlChTaEqwHhGBiV+mf8qYj9ZEi6zF5wiHWdDbMql1HZ/8h17UcO4M7Fvx+mrBkt OYnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uEIBisQv; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id t18-20020a63a612000000b003829aca2624si15136361pge.460.2022.04.06.01.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 01:50:39 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uEIBisQv; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 441E25933FE; Wed, 6 Apr 2022 01:35:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233005AbiDFCtj (ORCPT + 99 others); Tue, 5 Apr 2022 22:49:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1585494AbiDEX76 (ORCPT ); Tue, 5 Apr 2022 19:59:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D73C5403D7 for ; Tue, 5 Apr 2022 15:20:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B10C76190D for ; Tue, 5 Apr 2022 22:20:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DA40C385A0; Tue, 5 Apr 2022 22:20:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649197242; bh=qJghuGy/OuEqalpvRzR2kBCn0g3XnrF0PtfYrf8Qnho=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=uEIBisQvUi2erYjNPoIy9BoeCr8KLxb26lSWeFpx5gGe2SeeYU9nkopCf90wWxg/v RyV8YdIEIh5Pu9r3D8Pg78/08K26fFvnn0ONOh/Xxo1xBUxsGOr6clGX1QfidivmUG 35huDiCvB6dke3UbzIWt3oYTUC8FXIk5LMn6GIrkkZbtJI1j41EM8LUMBepuGwHNMZ u7wO/3lkKQfQIQh+tLoJ1WCYX0dQVXYgB3kOKydJ5KWyFtR2QLMtNLszbFXl4O4/xF dVpadq7flnYzS03d2nU5ql5kg5L0MoDQCYJKxDvs3tpguA+64XRZwvZ4eQQDV+9ZVA JV1ntbdelGbZg== Date: Tue, 5 Apr 2022 15:20:39 -0700 From: Nathan Chancellor To: Sami Tolvanen Cc: Kees Cook , Catalin Marinas , Mark Rutland , Masahiro Yamada , Nick Desaulniers , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH v2] cfi: Use __builtin_function_start Message-ID: References: <20220405221618.633743-1-samitolvanen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220405221618.633743-1-samitolvanen@google.com> X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 05, 2022 at 03:16:18PM -0700, Sami Tolvanen wrote: > Clang 14 added support for the __builtin_function_start function, > which allows us to implement the function_nocfi macro without > architecture-specific inline assembly and in a way that also works > with static initializers. > > Change CONFIG_CFI_CLANG to depend on Clang >= 14, define > function_nocfi using __builtin_function_start, and remove the arm64 > inline assembly implementation. > > Link: https://github.com/llvm/llvm-project/commit/ec2e26eaf63558934f5b73a6e530edc453cf9508 > Link: https://github.com/ClangBuiltLinux/linux/issues/1353 > Signed-off-by: Sami Tolvanen > Reviewed-by: Nick Desaulniers > Reviewed-by: Mark Rutland > Tested-by: Mark Rutland > Acked-by: Will Deacon # arm64 Reviewed-by: Nathan Chancellor > --- > v2: > - Changed CFI_CLANG to depend on Clang 14 instead of > __builtin_function_start. > - Squashed all three patches into one. > > --- > arch/Kconfig | 5 +---- > arch/arm64/include/asm/compiler.h | 16 ---------------- > include/linux/compiler-clang.h | 10 ++++++++++ > 3 files changed, 11 insertions(+), 20 deletions(-) > > diff --git a/arch/Kconfig b/arch/Kconfig > index 29b0167c088b..c1627bce4a3a 100644 > --- a/arch/Kconfig > +++ b/arch/Kconfig > @@ -723,10 +723,7 @@ config ARCH_SUPPORTS_CFI_CLANG > config CFI_CLANG > bool "Use Clang's Control Flow Integrity (CFI)" > depends on LTO_CLANG && ARCH_SUPPORTS_CFI_CLANG > - # Clang >= 12: > - # - https://bugs.llvm.org/show_bug.cgi?id=46258 > - # - https://bugs.llvm.org/show_bug.cgi?id=47479 > - depends on CLANG_VERSION >= 120000 > + depends on CLANG_VERSION >= 140000 > select KALLSYMS > help > This option enables Clang’s forward-edge Control Flow Integrity > diff --git a/arch/arm64/include/asm/compiler.h b/arch/arm64/include/asm/compiler.h > index dc3ea4080e2e..6fb2e6bcc392 100644 > --- a/arch/arm64/include/asm/compiler.h > +++ b/arch/arm64/include/asm/compiler.h > @@ -23,20 +23,4 @@ > #define __builtin_return_address(val) \ > (void *)(ptrauth_clear_pac((unsigned long)__builtin_return_address(val))) > > -#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)); \ > - addr; \ > -}) > -#endif > - > #endif /* __ASM_COMPILER_H */ > diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h > index babb1347148c..c84fec767445 100644 > --- a/include/linux/compiler-clang.h > +++ b/include/linux/compiler-clang.h > @@ -69,6 +69,16 @@ > #define __nocfi __attribute__((__no_sanitize__("cfi"))) > #define __cficanonical __attribute__((__cfi_canonical_jump_table__)) > > +#if defined(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) __builtin_function_start(x) > +#endif > + > /* > * Turn individual warnings and errors on and off locally, depending > * on version. > -- > 2.35.1.1094.g7c7d902a7c-goog >