From patchwork Tue Apr 30 17:37:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13649794 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 962A7C4345F for ; Tue, 30 Apr 2024 17:37:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=jzKvUqANFIzc44Y19GXFpX9oYa23M8wE9aVXIPHK0HA=; b=INplkUsWxrKCL7 vXJb7/sDpWRdC4DsUDXq5JicBBsIxedUO83AS0FlQlfwM1WD0R4iedtZ3f1xYcgEmXDUlewRw/1s5 hghbUFXuat5nBwcSIWhgY1RofMp6RQS1zfpI71wYuJwMDvXQ66+0TFm1M/nge3z+nXx4uGhC18nJZ 27QASPDX4GqVCVn3pyZf53/MRkcbpHVjtNXgWPFIuMASyvlUjLZ0a9OSQOSD0X8C+OhY2ZnuTElz/ zUjkZDLZhv/hKwCjHg6DFm0n2GfWxdWk+vZpbFhl945Kfr1s+3Nl1xIZr+C8XGZlDwxy08o1OZQsD Ms9FvJwNzUb0wN9xv7rg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1rPi-00000007Rw4-2vbB; Tue, 30 Apr 2024 17:37:10 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1rPf-00000007Rv8-2pTA for linux-arm-kernel@lists.infradead.org; Tue, 30 Apr 2024 17:37:09 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1ec486198b6so7625925ad.1 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=lists.infradead.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=hd+W+Xf5/fvMKA6ZCUOPeXu9E+5HtNo+X8eQkiq5CEltUjNQBwvFEcNpISSq8/AHMj ZKjuWc2CBUliFAz9GzTNRd51X613c0qTYt8BlLM++DIs6T3Y7ovrUX2NFYpRvRlx1bDk tDIiuYGghMEi36kG7AaXNMepfB1rH7Bje2S1g= 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=r/w7jTw7StVxRECiSMCzOUCJOA3cQ+APG4fyoPKzuhDlWr91sP3YsnclUMJfMg6FBL l4HuidsXEVCoWiXGlINNsXKJPUFtBcHRdjYNnS7nWcouBzvNkagwv6dL8qyWBo0matut JQbGCxfY7FY5uurz+1BCm1UdfYRD2lBXYvwn1OkyqejEGun0kSK7JBHSiARpuir6r2iL x7545n5Xf+WgAq74ws2XnJe9I/uw8Wf8zLeFqXQ8df+WI12Vnv1ju6mAUz9RrVcPfLr3 aESM9bGvsiB6Q3HobfQWPDZzt81NTDJj9qDhGfDD7tMZzAQs57M9KW60yh+rQL5vgNEX PzjQ== X-Forwarded-Encrypted: i=1; AJvYcCU8XoDSPnKO0XS+lOIXfERTaWPzju40iEqKPWRdv6BX38aobIs0LZiK1LPtRLbXAunwVsOxxHYF+RtOfVyKQ9YRJEP+BBZUmvngLFAGg9d88GvJO88= X-Gm-Message-State: AOJu0Yx9iWc5MpO7G2gT2HGnxJhPGnulEDXPVVKbcLVv4UM1g0nwTsvY whu4zq6/Sm8TzlB7QBBAgL8ytYJpO+WmdfUqh76OfIZepS+xDZLswfjHqatAdA== X-Google-Smtp-Source: AGHT+IEgJyBdK8IaFbZBEcXMW5JQxffHszntW2uwXu4E0cAx4+VHUvWNNAEX/51rVj/TOrVaFr9SYA== 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240430_103707_724289_9931E292 X-CRM114-Status: GOOD ( 13.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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