Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp590112lqm; Wed, 1 May 2024 09:34:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUZAyHPtzCj3bckBeaxHIkF/WmC4DMZ8W5dUyS1bHXVCr56W4tSuIv0r0QT0M5XJUdfyEs9K1REqt+f7T0mrUXcvl2KPYh8OCyLEXQOXA== X-Google-Smtp-Source: AGHT+IFWjme6Zk5NTZcmQ3/HXdARW9E7a0x4pbIvBC3DhpVAQIpC5yHNhEiPGr9BkE2vBGvuLvfi X-Received: by 2002:a17:902:ce8b:b0:1eb:5222:f13e with SMTP id f11-20020a170902ce8b00b001eb5222f13emr3529000plg.8.1714581248393; Wed, 01 May 2024 09:34:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714581248; cv=pass; d=google.com; s=arc-20160816; b=YqTMcfJRbYqmrJrujZHPGFjB+s6p14dCNaXlsKLi93sKlZKiLS11eYhW0HwoJz4QWt cV//lRH64WusHncr8i0iKeAWhbinsl36fpfFXvv+Ov8a4fRKVR1SdFmsHKMJt1sA/ysC MHb2NCUqDzrPl/8zarPANR06h6ve4UFcKLbubtxFP+BsJyIZgvkucsTDMphZj+UmsbA+ ZbRISOcbzjzzljNKQnnffEt4w5YUr3Y0RCe67iFrXtKjzUw0OxDy3h0qW/A9dg2vSpiH GKBdgjZ5DCDMBmpvrQQ4WV0V0xdkFos2PEfW1zY5MG2iJajbsLc87bwHguERdT2r+zh1 D2LA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=PtXb/p5Ub0HDY3Ytd+ELOF76LYoj1brIec9JtHNXK44=; fh=clRSLQ/2yVil+iGuk2qeeBoLXFDsbzPe3fecBNhiib4=; b=PxQzZjj1N6tEOJvzkfmVX+VSgfo1xakaBJKKHCilI3w3bEfTe0i8tiEvefZ5ZMNDKC qEJb81EMnugWKlShHk85YKl2W5ygxTsshREHR6ZNcCtBKHRngPGvNgH5X5e2yWyfQ6aX nIu8UXnhDUMAeQ+dob6oiVYUvaqDEVEF7budk9a0BE3YEu2GQV5+UXUlyPQyWicHJaSa fMVmaxQTS2jsJZ+QLggvigS1m9BWewfqfqRfaXt3Fyh39FyKqRkh9VbAERkCcNb6Hoys soQM0jecmuqS7nco/ccWDGkjGRI2qQYtMjWKGsip4z+j+Fo5LS0BcezHi2e3uTV2q1l5 uJjQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="kyJQWB/C"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-165584-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165584-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q18-20020a170902f79200b001eb5323f9dfsi8986673pln.233.2024.05.01.09.34.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 09:34:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-165584-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="kyJQWB/C"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-165584-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165584-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id ABD9E281AB6 for ; Wed, 1 May 2024 16:33:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C9DDF1802E; Wed, 1 May 2024 16:33:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kyJQWB/C" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF17A14A81; Wed, 1 May 2024 16:33:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714581198; cv=none; b=HMdSavHMr9e5MVqZfjL8lSsu4RwmJIFCoad1df9Gp3dKrrF8nRccM6mrqPqelWgEG+OO9Uj0o6mwfL5WoW0WLpOICmB9NxYRy/Fo+XWXYZLw4XrQKtsk1ATOsMyFLyDQUEK/4YPQbsPPOpALCBdvXhT+cU2pHhhgXrJMKxKZBvg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714581198; c=relaxed/simple; bh=YsbiyCkWKx45NRwGZjUByWsT1FcLXkinPMoGZRzJENY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=O2wQY/cmCB6SqcgKNafKW+dGiWj0lDV92LwPG6gIsZ5YvFyP1os2Pp1dPU/55ayktpzfmxdfqHH8uuzNkjZlNeI1FHSH6r4BgYC3pnjMC4VscWBy4FXIMEzPjtshK4L0cdjkPN/A5NKdogrkr6czPj4vtVzn+oq0JoWRLg1Mx9o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kyJQWB/C; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9843DC072AA; Wed, 1 May 2024 16:33:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714581197; bh=YsbiyCkWKx45NRwGZjUByWsT1FcLXkinPMoGZRzJENY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kyJQWB/C/UPy4hQuJX7qWfmVqfUZv95MxBh5sX9ggF10yALKt3+gJ4E59JuVdphYn +PmVOsc9zIbTDydsLQoRwu32kcNi9awZ4m3i1xCWZsJf1guGKFWK/WTZ9s4jYZJIXS T6YNrqkcpcK0TXH8s1N4YpzOOTcTZBy0JMufDRmwywwcsqwU6Hl3roNxLh9K1KOLrz NWunAfeQyYBTe/LSnFu9WE3dg8+4WscGoLSUgRR1+C0F4me78dC07h6wx2sv6zDiD6 sIcNZ1h7xp7TjjXv1LPwkarBqN2efPN0ZOUbEZbr+cpSNdsyxTu/NUc1rznKDJibJt fw65B/KbapeVg== Date: Wed, 1 May 2024 09:33:14 -0700 From: Nathan Chancellor To: Kees Cook Cc: Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Alexei Starovoitov , Sami Tolvanen , Josh Poimboeuf , Juergen Gross , Breno Leitao , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] x86/alternatives: Make FineIBT mode Kconfig selectable Message-ID: <20240501163314.GA2472577@dev-arch.thelio-3990X> References: <20240501000218.work.998-kees@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240501000218.work.998-kees@kernel.org> On Tue, Apr 30, 2024 at 05:02:22PM -0700, Kees Cook wrote: > Since FineIBT performs checking at the destination, it is weaker against > attacks that can construct arbitrary executable memory contents. As such, > some system builders want to run with FineIBT disabled by default. Allow > the "cfi=kcfi" boot param mode to be selectable through Kconfig via the > newly introduced CONFIG_CFI_AUTO_DEFAULT. > > Signed-off-by: Kees Cook I verified that flipping the configuration does indeed change the default and that 'cfi=' could still be used to override whatever choice was made at compile time. This patch was a perfect excuse to put my new CET enabled test machine to work. Reviewed-by: Nathan Chancellor Tested-by: Nathan Chancellor CFI_DEFAULT_AUTO reads a little bit better to me personally but I am not looking to get into painting today :) > --- > Cc: Peter Zijlstra > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: Dave Hansen > Cc: x86@kernel.org > Cc: "H. Peter Anvin" > Cc: Alexei Starovoitov > Cc: Sami Tolvanen > Cc: Nathan Chancellor > Cc: Josh Poimboeuf > --- > arch/x86/Kconfig | 9 +++++++++ > arch/x86/include/asm/cfi.h | 2 +- > arch/x86/kernel/alternative.c | 8 ++++---- > 3 files changed, 14 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig > index 4fff6ed46e90..d5cf52d2f6a8 100644 > --- a/arch/x86/Kconfig > +++ b/arch/x86/Kconfig > @@ -2424,6 +2424,15 @@ config STRICT_SIGALTSTACK_SIZE > > Say 'N' unless you want to really enforce this check. > > +config CFI_AUTO_DEFAULT > + bool "Attempt to use FineIBT by default at boot time" > + depends on FINEIBT > + default y > + help > + Attempt to use FineIBT by default at boot time. If enabled, > + this is the same as booting with "cfi=auto". If disabled, > + this is the same as booting with "cfi=kcfi". > + > source "kernel/livepatch/Kconfig" > > endmenu > diff --git a/arch/x86/include/asm/cfi.h b/arch/x86/include/asm/cfi.h > index 7cd752557905..31d19c815f99 100644 > --- a/arch/x86/include/asm/cfi.h > +++ b/arch/x86/include/asm/cfi.h > @@ -93,7 +93,7 @@ > * > */ > enum cfi_mode { > - CFI_DEFAULT, /* FineIBT if hardware has IBT, otherwise kCFI */ > + CFI_AUTO, /* FineIBT if hardware has IBT, otherwise kCFI */ > CFI_OFF, /* Taditional / IBT depending on .config */ > CFI_KCFI, /* Optionally CALL_PADDING, IBT, RETPOLINE */ > CFI_FINEIBT, /* see arch/x86/kernel/alternative.c */ > diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c > index 45a280f2161c..e8d0892d89cf 100644 > --- a/arch/x86/kernel/alternative.c > +++ b/arch/x86/kernel/alternative.c > @@ -902,8 +902,8 @@ void __init_or_module apply_seal_endbr(s32 *start, s32 *end) { } > > #endif /* CONFIG_X86_KERNEL_IBT */ > > -#ifdef CONFIG_FINEIBT > -#define __CFI_DEFAULT CFI_DEFAULT > +#ifdef CONFIG_CFI_AUTO_DEFAULT > +#define __CFI_DEFAULT CFI_AUTO > #elif defined(CONFIG_CFI_CLANG) > #define __CFI_DEFAULT CFI_KCFI > #else > @@ -1011,7 +1011,7 @@ static __init int cfi_parse_cmdline(char *str) > } > > if (!strcmp(str, "auto")) { > - cfi_mode = CFI_DEFAULT; > + cfi_mode = CFI_AUTO; > } else if (!strcmp(str, "off")) { > cfi_mode = CFI_OFF; > cfi_rand = false; > @@ -1271,7 +1271,7 @@ static void __apply_fineibt(s32 *start_retpoline, s32 *end_retpoline, > "FineIBT preamble wrong size: %ld", fineibt_preamble_size)) > return; > > - if (cfi_mode == CFI_DEFAULT) { > + if (cfi_mode == CFI_AUTO) { > cfi_mode = CFI_KCFI; > if (HAS_KERNEL_IBT && cpu_feature_enabled(X86_FEATURE_IBT)) > cfi_mode = CFI_FINEIBT; > -- > 2.34.1 >