Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754586AbeAHRuy (ORCPT + 1 other); Mon, 8 Jan 2018 12:50:54 -0500 Received: from mail-co1nam03on0087.outbound.protection.outlook.com ([104.47.40.87]:47841 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751767AbeAHRuw (ORCPT ); Mon, 8 Jan 2018 12:50:52 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jayachandran.Nair@cavium.com; Date: Mon, 8 Jan 2018 09:50:45 -0800 From: Jayachandran C To: Will Deacon Cc: linux-arm-kernel@lists.infradead.org, lorenzo.pieralisi@arm.com, ard.biesheuvel@linaro.org, marc.zyngier@arm.com, catalin.marinas@arm.com, linux-kernel@vger.kernel.org, labbott@redhat.com, christoffer.dall@linaro.org Subject: Re: [v2,03/11] arm64: Take into account ID_AA64PFR0_EL1.CSV3 Message-ID: <20180108175044.GC180149@jc-sabre> References: <1515157961-20963-4-git-send-email-will.deacon@arm.com> <20180108072253.GA178830@jc-sabre> <20180108170624.GT25869@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180108170624.GT25869@arm.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: MWHPR19CA0064.namprd19.prod.outlook.com (10.173.117.26) To CO2PR0701MB1061.namprd07.prod.outlook.com (10.160.8.140) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d81dfcfd-7de6-436d-4b70-08d556c05ae6 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020);SRVR:CO2PR0701MB1061; X-Microsoft-Exchange-Diagnostics: 1;CO2PR0701MB1061;3:GUXwtrlPneFHG8oY60Lmcot32PCD2HogLsZuMjdYXMD3vww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TnT6aPvbzzzVHFq7dgLTQEcBu+sUof1DkKsWJDyLr/SNAUeZDK2w3by0OvL2pHMLsijTIz/3a/2PZA7AD+5H1lJVtldbxpO7kSOkxtdiUKg4z7WFuy6G/ZyjrAln8YPpT8Tn5m+btpfB6Rs0hd4Un1aeyIwkjOsmGe2O4BIeSDg88AOMDl1qujkdb+8ZovBd6MdWup9/Hsie3HRVCzF1tkIugFmMiKxE2U/dBn7GRM5sZeo0xDFV0f91gxQ/wH+yKag6+wQgpQMyav9D/5JYNwWNVR8cHLCWiIpJIFfjrmndfaNdOeLb0YTz/OPQ/Edb83XPv2q58IXtTnln4x7n0Q8wQJXAKuBJItQfUNV5KEKEEC4puWaMBQ/sS95m5cHJAvCp5Bip8Bk6GIECr/SSdAYOOIa1VSsVGHY7JWPkA=;4:eb8I55pyaWrGQcVPVBSWtBZKLWTxZHOnG7Z/txf4lCqMOVHSYgNm8SFEBe4xD0VhVUdRpHH3rFcxBvsRjY4zf8DM6zvHXSl6hC86g+dZ0saTmqASLc/bGsepyYKe4+8xD/cQbmG/fm96RvkMBIZGWidI0QKnEPhb072mD+AkQjuIzkHdLoOaQv22qxUXSmc1Fj1gQR6jFqcli3zyA4auqxx+yNISMSfdYyO1S1tDwO80pItWIasK4Q5wgFW/9F9MeAQ+P1G88nAvcSr+bPXXJ073WpUL4aX/6Wv0376gRnjfRKdZoHUpGLfaGtKXZMHq X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040470)(2401047)(8121501046)(5005006)(3231023)(944501075)(93006095)(10201501046)(3002001)(6041268)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(6072148)(201708071742011);SRVR:CO2PR0701MB1061;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:CO2PR0701MB1061; X-Forefront-PRVS: 054642504A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(366004)(39860400002)(346002)(396003)(39380400002)(376002)(199004)(189003)(24454002)(87496004)(55016002)(81166006)(8676002)(81156014)(9686003)(6246003)(25786009)(4326008)(7736002)(305945005)(47776003)(97736004)(16586007)(478600001)(53936002)(58126008)(66066001)(16526018)(229853002)(72206003)(316002)(33896004)(6666003)(83506002)(23726003)(6916009)(33716001)(42882006)(68736007)(6496006)(2950100002)(59450400001)(33656002)(386003)(52116002)(3846002)(6116002)(1076002)(76176011)(2906002)(50466002)(106356001)(105586002)(8936002)(5660300001)(18370500001)(107986001);DIR:OUT;SFP:1101;SCL:1;SRVR:CO2PR0701MB1061;H:jc-sabre;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CO2PR0701MB1061;23:GBRkI4ybZMMtnkuKqXVCuYZ3FenhNQ89/UbbGMs?= =?us-ascii?Q?LomsHge6kumvvIlzs7/pale69ZpEpW7VJu9gY0BoIBHmZufAGUFvz14BQxxR?= =?us-ascii?Q?KHmqOex94hAWiiCkGmRkzr58HcNSbxUXtVlzcwA9HsnauU15ytO4axsh0cf3?= =?us-ascii?Q?Xf6t8rLBk5of4JrpTHkH5Pl4H0UPneLaaDcEC2aKz3rAbAZLuUdhE2NIuATo?= =?us-ascii?Q?tMHyZegt1x9idkZiqPTKm6ckiIUL966DYsPHUBAfnFINArB3PYlfR5DYbWwO?= =?us-ascii?Q?ZDitIGPFIqqZlHfAVVhd8KsFs0FXEmSs3svc0seMLS1YV0LtILNvD0FTkSS8?= =?us-ascii?Q?JHeAId41OgPxVdAELGTwNFz9+mm9CoL+YGCRQazRThP8X1Y4SIG7qda4P//j?= =?us-ascii?Q?mIGarJmOtIJCVTKI/M2wrJKnIzTTayXE/332PwpFqtgpEeAkBGoY5WlHu/IV?= =?us-ascii?Q?H5mkICeYA+aTRPe6DIx8tH8TBEk4XqRbYL0nKYjPTeEUjkHmSFONVK5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bkrRzDSp+byhIiINj7r/X86pE66fQmYRthj/i3Gzf69de7qBTfdZrpg48J7z3K1ElumVT28vwXTktT7nDLzxErgyYg3eVXVYxYddKPH8BgVek33AhQzsmHcHx3COTekM54Prxnb2nxn3/QVf3xP98nQvLFHUdM3GgcjsMV1IUEEwUAR5HzIri63iMJIaYZ+iPHdWYA8R0dcZigs19DiV1OgU9DNjA1SOxqwg695AzC1nppb0BCgV/wyercFonH+MIzFjK/RWe9KS1Fo/5xpstmirlv6UeW67JcEtgMQljPWDC5HPUTvX8q7ka+hLnVzryMtX01ZQtY=;5:3+J7uGToB+EJBo6k8qIPEIW46I0CHgLWAF0nixtrnh6l4cxh4IwlQKHtxc9HCk2r7kxxRNgGBTAoBtbl58PXP5O+8fbTvOqNQoHRG+yxEouIbGpgAEUeYNq9WWsLZqSOvF7PNpI+AFxi/1qM5EkLQMwEMYc+shmYl9TW/5tjMsQ=;24:/2Lbtr6T5lPt2PW69YtL+IT5TovLrrpNBxf4atQvWrIujqs8FREOU0u/O3Ou4z5ihgwof1tfci2VC9jFAPg6dAWgSRv0IM/eFOn6IBay7oo=;7:WP9/bbG3hDFaYhWiQgWHL7XCeeUYtLrzfJeTd7h7UpPDqdICKyPWSANVcHApmwtyClGHNShogI/875DgjfApzc/Y+vFbdV+n9gAoDBvsF85b0Ps4fxXVTrb4AxiRwF30Zld0uETlHwKet8hoCOacwwNyAYeoJbSqMzmFN1ThL0HHg27L6zNyLcT7aOLB7D+DRt/HcHBx1PEUZPeZa+4S0HKZ2+JfG7t1uYiHApUn0utqbT5fDI2zAUJA1Drk4Zdn SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jan 2018 17:50:49.7482 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d81dfcfd-7de6-436d-4b70-08d556c05ae6 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO2PR0701MB1061 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On Mon, Jan 08, 2018 at 05:06:24PM +0000, Will Deacon wrote: > On Sun, Jan 07, 2018 at 11:24:02PM -0800, Jayachandran C wrote: > > On Fri, Jan 05, 2018 at 01:12:33PM +0000, Will Deacon wrote: > > > For non-KASLR kernels where the KPTI behaviour has not been overridden > > > on the command line we can use ID_AA64PFR0_EL1.CSV3 to determine whether > > > or not we should unmap the kernel whilst running at EL0. > > > > > > Reviewed-by: Suzuki K Poulose > > > Signed-off-by: Will Deacon > > > --- > > > arch/arm64/include/asm/sysreg.h | 1 + > > > arch/arm64/kernel/cpufeature.c | 8 +++++++- > > > 2 files changed, 8 insertions(+), 1 deletion(-) > > > > > > diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h > > > index 08cc88574659..ae519bbd3f9e 100644 > > > --- a/arch/arm64/include/asm/sysreg.h > > > +++ b/arch/arm64/include/asm/sysreg.h > > > @@ -437,6 +437,7 @@ > > > #define ID_AA64ISAR1_DPB_SHIFT 0 > > > > > > /* id_aa64pfr0 */ > > > +#define ID_AA64PFR0_CSV3_SHIFT 60 > > > #define ID_AA64PFR0_SVE_SHIFT 32 > > > #define ID_AA64PFR0_GIC_SHIFT 24 > > > #define ID_AA64PFR0_ASIMD_SHIFT 20 > > > diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c > > > index 9f0545dfe497..d723fc071f39 100644 > > > --- a/arch/arm64/kernel/cpufeature.c > > > +++ b/arch/arm64/kernel/cpufeature.c > > > @@ -145,6 +145,7 @@ static const struct arm64_ftr_bits ftr_id_aa64isar1[] = { > > > }; > > > > > > static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = { > > > + ARM64_FTR_BITS(FTR_HIDDEN, FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64PFR0_CSV3_SHIFT, 4, 0), > > > ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_SVE_SHIFT, 4, 0), > > > ARM64_FTR_BITS(FTR_HIDDEN, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_GIC_SHIFT, 4, 0), > > > S_ARM64_FTR_BITS(FTR_VISIBLE, FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_ASIMD_SHIFT, 4, ID_AA64PFR0_ASIMD_NI), > > > @@ -851,6 +852,8 @@ static int __kpti_forced; /* 0: not forced, >0: forced on, <0: forced off */ > > > static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, > > > int __unused) > > > { > > > + u64 pfr0 = read_sanitised_ftr_reg(SYS_ID_AA64PFR0_EL1); > > > + > > > /* Forced on command line? */ > > > if (__kpti_forced) { > > > pr_info_once("kernel page table isolation forced %s by command line option\n", > > > @@ -862,7 +865,9 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, > > > if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) > > > return true; > > > > > > - return false; > > > + /* Defer to CPU feature registers */ > > > + return !cpuid_feature_extract_unsigned_field(pfr0, > > > + ID_AA64PFR0_CSV3_SHIFT); > > > > If I read this correctly, this enables KPTI on all processors without the CSV3 > > set (which seems to be a future capability). > > > > Turning on KPTI has a small but significant overhead, so I think we should turn > > it off on processors that are not vulnerable to CVE-2017-5754. Can we add something > > like this: > > > > --->8 > > diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c > > index 19ed09b..202b037 100644 > > --- a/arch/arm64/kernel/cpufeature.c > > +++ b/arch/arm64/kernel/cpufeature.c > > @@ -862,6 +862,13 @@ static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, > > return __kpti_forced > 0; > > } > > > > + /* Don't force KPTI for CPUs that are not vulnerable */ > > + switch (read_cpuid_id() & MIDR_CPU_MODEL_MASK) { > > + case MIDR_CAVIUM_THUNDERX2: > > + case MIDR_BRCM_VULCAN: > > + return false; > > + } > > + > > KASLR aside (I agree with Marc on that), I did consider an MIDR whitelist, > but it gets nasty for big.LITTLE systems if maxcpus= is used and we see a > non-whitelisted CPU after we've booted. At this point, we can't actually > bring the thing online. > > You could make the argument that if you're passing maxcpus= then you can just > easily pass kpti= as well, but I wasn't sure. The code above should be a reasonable addition for getting the default right. If by any chance these CPUs are shown to be vulnerable to timing attacks that can bypass KASLR, we will need to move the change below the line: if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) return true; The current code, which is purely based on future capability does not handle CPUs without the vulnerablility properly. Can we fix this? Thanks, JC