Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp2199885lqa; Tue, 30 Apr 2024 10:37:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWbm6aa/Q8grCzPq3ggF/aFgk2Je7GARffX4JCvZPxnsSFd4w/+l2H+ko4cVhvSM3YbMDY01dkYp5la3g4/qvOPW9HuWW9+q6yZa23EKw== X-Google-Smtp-Source: AGHT+IGPUT7vIVgZd58t4K9uDucxVFgOyc6MY+QrX47PTQMfQfprTq9Y7wzpNDqY766hBB2IvPsQ X-Received: by 2002:a05:620a:ec9:b0:790:600a:34d7 with SMTP id x9-20020a05620a0ec900b00790600a34d7mr11113506qkm.54.1714498634405; Tue, 30 Apr 2024 10:37:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714498634; cv=pass; d=google.com; s=arc-20160816; b=AC57kkXcMR/JMyB7RrBOdqmtTgp3krdVUKDhgH2M5YwBqQyV+mKhJp2VaOvJW97GT0 pOEYat1xoAXpSrMxGDF4c9aaKL9fSZ9Gets/MMJpoSStm9tIIyPHW0I8+S3U5Cs95biO 2CO45hajFxQxmtfpWXUIrptnP2MvDvoEt0jzMxasXdIS9KzvC8UIzRovgvCfAWLXNvxG OyznDn2RG47s6UaXRpupYqLzl0LQ4nO9a9v68rcT4KNOSJvw/1WhSQpCqvtXnKgeLlCM FxE4Ei2N7m7ia0sXdkRM2Hc7ob0KuJXQfxLhXZgZ3iMLSD2CfmIID7RMMjY1Y4t1xrEn jZaw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=H7TCEkmJU5v9XbqMkMv7vhbRAU+5JxBsl8E5GjM9uj8=; fh=/+/1bDGzVfGLc+hvtuO7Q2gB+cdjM6gdnpfMj044FSI=; b=HNCpepKWjbNuqGj2vE2c3rs8lbcfUsSqUvqh3XEy3AwFBW9fxeLZHFER6gWS6TZ+sJ 2fWSGboI3+CiqChJxxiCcNZAKLbUl91vQc7RMKB9iBfMDb8OOxqCGkEWPjEAXHzAIcDs 4d5S1CvBLmPQLHcM5ovo6XYcSF1NWBxlFXkawGb8WaoeCr8zlWwW8WpAvBJ0vXn31N6u EuTd7zIdXsHSA1QX4YYVY5IVUxmKL5HPILSjVd1EZ09xWH6/tRUuy7U/01fOBNI9dvEk on/vfdWTRjJjnAG9Oz5ps5K/ItGPkLSt8+aYV+y7bV5DFSbKk/vmgbxZZWVoOFFkuH2m ne6g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ftHtMFai; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-164524-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164524-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id w11-20020ac87e8b000000b0043c5cc6adf0si1451703qtj.370.2024.04.30.10.37.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 10:37:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-164524-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ftHtMFai; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-164524-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164524-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 239E41C229D2 for ; Tue, 30 Apr 2024 17:37:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2AADF1802BC; Tue, 30 Apr 2024 17:37:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ftHtMFai" Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7F7B1802B5 for ; Tue, 30 Apr 2024 17:37:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714498627; cv=none; b=U0IkUd3OZryiX+YelVcoQ8FOXHRhLSimL6wf7HPHnJzL1SpCu7bPsK7qEWDcUSAv5ZkB3ioMoBw8jtl1Vi0s9nZD7UhaFbiPCv91P/dRnTEOKZPfGEhVcQOPzJocgF/evOnZnlDkvGxKQku5E6uHefxaDydbJpbeOfGxOrOkWfw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714498627; c=relaxed/simple; bh=HwleHbMmvyClSw2hkCjqzzitfJIFUgKSvCPPJPbOXUI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=JyDJ1GjaPhYo+wZf8EuhuZR+80mLy+G3BkPP/LJOLPTvhYtX4+lSmdUHivVtmUDsrWWMciASXa3JOWSNG9Q0+r5YzvQt54l/RgS4tIRGhuYA8Cl4+QEF0t5pNUjq/qNYfaaUIxaZBncCQM/eZsARaW4svSWS4rPO4/zWQpR+FWU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=ftHtMFai; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1eab16dcfd8so51869985ad.0 for ; Tue, 30 Apr 2024 10:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1714498624; x=1715103424; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=H7TCEkmJU5v9XbqMkMv7vhbRAU+5JxBsl8E5GjM9uj8=; b=ftHtMFaipxj1hya2+OVkgdkd2QSO3ryMoAfBnkywgVaRrfaqGZL08O474COmBBxSWC mbqrsACYOo7wb81W8kMSBXyqih1lnGo7UHAR+hJhXVyxTqTtf7E1v9xNUwlMG+XHeYY0 b7Udlsl8Wzmvg8yzMJs/DckhvgShi1agj9Iw4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714498624; x=1715103424; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=H7TCEkmJU5v9XbqMkMv7vhbRAU+5JxBsl8E5GjM9uj8=; b=Q/0ZT1MJR/08DPXCcMWIiZlyLmI1TJW+oMA8WJBFCSsezR6uCxBJcKNLoCzcntbp2j rGhjl8orflPkcA5gB9BKoBgDdrmBv5ChWQsgQcGwVu4j81jUXvodycPibNXeiWhn7m2H PxOwqSV9knJmd2TjNJee3Gty5IYGi1jP7fPYzHdXja3NJl0J9RZsVIig+CcbyvOIYhrB zsFtxbnZIXv2gTkvfyUcN8du0A8W23R0dqtoPwhjmmUfBoigaRXgqskXRWwT0wbjHayD kfYPmDzrwkrI+1FajdtEKmx9unnsZj7unrfXXourunzMhoEAxXzj2/pg3nEwol9hhs4L pFrg== X-Forwarded-Encrypted: i=1; AJvYcCUVnwMevuquzkJ1vCwPXcxvzEIbtCggMgW+xzr9Yi2Te6Kxb+TCDmj19jmQEJ3f/hRQZ0YHd4Dmeg/41GWkfzZbu9gIX88nbyUbi5WS X-Gm-Message-State: AOJu0YwTljSdCyMNRUvX/R1Hos3mGpzs0bQWvgGxjZwdtydTIYDNiqBW hsD+EBmDm/UQ4RqqNf78l7fIoBc5lCxRYdzOPvlhsTmzdhtNn5zwPHIf7q/41g== X-Received: by 2002:a17:902:eac4:b0:1ec:76a6:ea9 with SMTP id p4-20020a170902eac400b001ec76a60ea9mr98049pld.26.1714498624229; Tue, 30 Apr 2024 10:37:04 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id i12-20020a17090320cc00b001eab1258197sm10400741plb.144.2024.04.30.10.37.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 10:37:03 -0700 (PDT) From: Kees Cook To: Nathan Chancellor Cc: Kees Cook , "Gustavo A. R. Silva" , Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Nick Desaulniers , Bill Wendling , Justin Stitt , linux-kernel@vger.kernel.org, x86@kernel.org, linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev Subject: [PATCH v2] hardening: Enable KCFI and some other options Date: Tue, 30 Apr 2024 10:37:00 -0700 Message-Id: <20240430173657.it.699-kees@kernel.org> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2768; i=keescook@chromium.org; h=from:subject:message-id; bh=HwleHbMmvyClSw2hkCjqzzitfJIFUgKSvCPPJPbOXUI=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBmMSw8JAuEaLHzrMs+I0z2zE2/9ONfTrWuUhxfB nUIns+oImyJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZjEsPAAKCRCJcvTf3G3A JhTEEACOGEhRbFkij9Hg8wOi94RhI/kWW1frkUHlY6k9hvRUHCG4HdzS1hJHcBlfpZuXkJ8j3ub qAINSRxOpsnxez1sFGK5iy91hNbeRGXyJ5znmwbewZssGCdDyRs99mhcp2+zJJgcOGltMW5q44d C1e3GA22dEyNX7IKQneeJpm5SaZbKusp72+3dNQcpkQOc4stcvPbT+b28JZdM+gnuryWpkgwhuS ozeSggCI0N6FD0P0HXnFp0tQKEDDINxCW0wIyg07WLruf+R5CRt5jLkZFPN46KcygR5668GeDzS ToWYc44Tk88mmSaxTKzPN0afz12vfTuPkrf1+Z6QjOagPIWLEvWW0JtqXVjiw3Tc9qphdzOah/k /SQY3iG3kgMJ7y8oh4dPMutI5Ustzk8Vj0rmka0bFaM78u+LC9Ha5grFnsvD17eh9mLFPtn8K75 YJi9wR7tyyCpnFjSUr/5231n8Y9Q9u+K2TalZMppSa1E2QaDg6giY4ZK3LKPsbDCfPkjyggWTR4 kHXXHnz9MGksi/hKRITQ/Aq3qpVYyKOBChuMppK9xOqjLZRs/gosEDqtYVjN3nsbGcxnKyOgE+L wLHf2ApifK8pF64VYy9at8D0ixOjL8IoywKA39+LMBkzyfENJD+IN+4MRqcigX77oUDCIuuYgtI ySSnPDH nd/DoKkA== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit Add some stuff that got missed along the way: - CONFIG_UNWIND_PATCH_PAC_INTO_SCS=y so SCS vs PAC is hardware selectable. - CONFIG_X86_KERNEL_IBT=y while a default, just be sure. - CONFIG_CFI_CLANG=y globally. (And disable FINEIBT since it isn't as secure as straight KCFI.) - CONFIG_PAGE_TABLE_CHECK=y for userspace mapping sanity. Reviewed-by: Nathan Chancellor Signed-off-by: Kees Cook --- v2: move CONFIG_CFI_CLANG=y to global config v1: https://lore.kernel.org/all/20240426222940.work.884-kees@kernel.org/ --- arch/arm64/configs/hardening.config | 1 + arch/x86/configs/hardening.config | 6 ++++++ kernel/configs/hardening.config | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/arch/arm64/configs/hardening.config b/arch/arm64/configs/hardening.config index b0e795208998..24179722927e 100644 --- a/arch/arm64/configs/hardening.config +++ b/arch/arm64/configs/hardening.config @@ -5,6 +5,7 @@ CONFIG_ARM64_SW_TTBR0_PAN=y # Software Shadow Stack or PAC CONFIG_SHADOW_CALL_STACK=y +CONFIG_UNWIND_PATCH_PAC_INTO_SCS=y # Pointer authentication (ARMv8.3 and later). If hardware actually supports # it, one can turn off CONFIG_STACKPROTECTOR_STRONG with this enabled. diff --git a/arch/x86/configs/hardening.config b/arch/x86/configs/hardening.config index 7b497f3b7bc3..bf3d31618e12 100644 --- a/arch/x86/configs/hardening.config +++ b/arch/x86/configs/hardening.config @@ -10,5 +10,11 @@ CONFIG_INTEL_IOMMU_DEFAULT_ON=y CONFIG_INTEL_IOMMU_SVM=y CONFIG_AMD_IOMMU=y +# Enforce CET Indirect Branch Tracking in the kernel. +CONFIG_X86_KERNEL_IBT=y + # Enable CET Shadow Stack for userspace. CONFIG_X86_USER_SHADOW_STACK=y + +# When CONFIG_CFI_CLANG is enabled, disable weaker FINEIBT landing pads. +# CONFIG_FINEIBT is not set diff --git a/kernel/configs/hardening.config b/kernel/configs/hardening.config index 7a5bbfc024b7..47e6564129c3 100644 --- a/kernel/configs/hardening.config +++ b/kernel/configs/hardening.config @@ -23,6 +23,10 @@ CONFIG_SLAB_FREELIST_HARDENED=y CONFIG_SHUFFLE_PAGE_ALLOCATOR=y CONFIG_RANDOM_KMALLOC_CACHES=y +# Sanity check userspace page table mappings. +CONFIG_PAGE_TABLE_CHECK=y +CONFIG_PAGE_TABLE_CHECK_ENFORCED=y + # Randomize kernel stack offset on syscall entry. CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT=y @@ -81,6 +85,10 @@ CONFIG_SECCOMP_FILTER=y # Provides some protections against SYN flooding. CONFIG_SYN_COOKIES=y +# Enable Kernel Control Flow Integrity (currently Clang only). +CONFIG_CFI_CLANG=y +# CONFIG_CFI_PERMISSIVE is not set + # Attack surface reduction: do not autoload TTY line disciplines. # CONFIG_LDISC_AUTOLOAD is not set -- 2.34.1