From nobody Sat Feb 7 21:08:18 2026 Received: from mail18.out.titan.email (mail18.out.titan.email [3.64.226.212]) (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 5FCD61FF7AD for ; Fri, 17 Jan 2025 13:09:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=3.64.226.212 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737119366; cv=none; b=q3bvZ6cRRiKNYY+yAxyGfoKt5j+jcOEEt0yo1G/2dMIAYwYuS4HZfM8alKt8X034Nx2tPFq5qhQIXw8/yTaNfFY7FmbRaqthIaKWFSGNtz0ybdRJ+yVkNheW3Q8xGjTk6whuw9vxSbi9SobmU7zcfj3g7u9v4jLjrIbQ0GgESuE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737119366; c=relaxed/simple; bh=GoL8elr1g+v9QVwcLmr7gtwKfIKEgObjpBU6EDehYeE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j+HJvZksPgyw8kRI9WUDljek5kL3UEMyDgAMiCbZ3fUZHiI0LOO8VCqUbdnDdTo22KBXjDieYuyOJ7h7XpejrRUsrg7fUD97lcdsPADoL0ehJJq5+v7Mt6B0GOhCKX2JO8vL9RueAGuzmCDJ3YbIj0zXAlk2oTKWBATaLBC7YjI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=techsingularity.net; spf=pass smtp.mailfrom=techsingularity.net; dkim=pass (1024-bit key) header.d=techsingularity.net header.i=@techsingularity.net header.b=Y6vlzjVM; arc=none smtp.client-ip=3.64.226.212 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=techsingularity.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=techsingularity.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=techsingularity.net header.i=@techsingularity.net header.b="Y6vlzjVM" Received: from smtp-out0101.titan.email (localhost [127.0.0.1]) by smtp-out0101.titan.email (Postfix) with ESMTP id 80932A009B; Fri, 17 Jan 2025 13:03:59 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=2rFrjKhCOLgXm9a/3DoxLHhn5CHHMWAoj6SakG580bw=; c=relaxed/relaxed; d=techsingularity.net; h=to:cc:subject:from:message-id:date:in-reply-to:references:mime-version:from:to:cc:subject:date:message-id:in-reply-to:references:reply-to; q=dns/txt; s=titan1; t=1737119039; v=1; b=Y6vlzjVMCJ3cZmPLJA88USrvWVVrM7jdpCl11/6uLbjj9qSHS6WUji2cl4FNKOyyMwZNzoEi zZf5HTTHVkHFGw6tg48WzdRCv0+S5dWi8U+Dj+llcrQqWc/jPg6PkMPu1BbliPUhs64+aq6J/RC NhaVEcqa5Lybqn7J1UlwZ748= Received: from mail.blacknight.com (ip-84-203-196-66.broadband.digiweb.ie [84.203.196.66]) by smtp-out0101.titan.email (Postfix) with ESMTPA id 20583A0049; Fri, 17 Jan 2025 13:03:59 +0000 (UTC) Feedback-ID: :mgorman@techsingularity.net:techsingularity.net:flockmailId From: Mel Gorman To: Kees Cook Cc: Daniel Micay , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Mel Gorman Subject: [PATCH 1/3] mm: security: Move hardened usercopy under 'Kernel hardening options' Date: Fri, 17 Jan 2025 13:03:35 +0000 Message-ID: <20250117130337.4716-2-mgorman@techsingularity.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250117130337.4716-1-mgorman@techsingularity.net> References: <20250117130337.4716-1-mgorman@techsingularity.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-F-Verdict: SPFVALID X-Titan-Src-Out: 1737119039409530807.9138.3900322166364608842@prod-euc1-smtp-out1002. X-CMAE-Score: 0 X-CMAE-Analysis: v=2.4 cv=UdNXSrSN c=1 sm=1 tr=0 ts=678a553f a=jU4EnjUUC1PH4wSjvv7Pww==:117 a=jU4EnjUUC1PH4wSjvv7Pww==:17 a=CEWIc4RMnpUA:10 a=R_Myd5XaAAAA:8 a=KkbEisfxgXDdCi-76G0A:9 a=L2g4Dz8VuBQ37YGmWQah:22 X-Virus-Scanned: ClamAV using ClamSMTP Content-Type: text/plain; charset="utf-8" There is a submenu for 'Kernel hardening options' under "Security". Move HARDENED_USERCOPY under the hardening options as it is clearly related. Signed-off-by: Mel Gorman Acked-by: Paul Moore --- security/Kconfig | 12 ------------ security/Kconfig.hardening | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/security/Kconfig b/security/Kconfig index 28e685f53bd1..fe7346dc4bc3 100644 --- a/security/Kconfig +++ b/security/Kconfig @@ -159,18 +159,6 @@ config LSM_MMAP_MIN_ADDR this low address space will need the permission specific to the systems running LSM. =20 -config HARDENED_USERCOPY - bool "Harden memory copies between kernel and userspace" - imply STRICT_DEVMEM - help - This option checks for obviously wrong memory regions when - copying memory to/from the kernel (via copy_to_user() and - copy_from_user() functions) by rejecting memory ranges that - are larger than the specified heap object, span multiple - separately allocated pages, are not on the process stack, - or are part of the kernel text. This prevents entire classes - of heap overflow exploits and similar kernel memory exposures. - config FORTIFY_SOURCE bool "Harden common str/mem functions against buffer overflows" depends on ARCH_HAS_FORTIFY_SOURCE diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening index c9d5ca3d8d08..00e6e2ed0c43 100644 --- a/security/Kconfig.hardening +++ b/security/Kconfig.hardening @@ -279,6 +279,22 @@ config ZERO_CALL_USED_REGS =20 endmenu =20 +menu "String manipulation" + +config HARDENED_USERCOPY + bool "Harden memory copies between kernel and userspace" + imply STRICT_DEVMEM + help + This option checks for obviously wrong memory regions when + copying memory to/from the kernel (via copy_to_user() and + copy_from_user() functions) by rejecting memory ranges that + are larger than the specified heap object, span multiple + separately allocated pages, are not on the process stack, + or are part of the kernel text. This prevents entire classes + of heap overflow exploits and similar kernel memory exposures. + +endmenu + menu "Hardening of kernel data structures" =20 config LIST_HARDENED --=20 2.43.0 From nobody Sat Feb 7 21:08:18 2026 Received: from mail15.out.titan.email (mail15.out.titan.email [3.64.226.209]) (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 6BA951FCFDA for ; Fri, 17 Jan 2025 13:04:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=3.64.226.209 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737119054; cv=none; b=kKoNNAJo5S7LRtkGFMkT7GdLPw8vZvIuGYkl6k4RpMXotU91qZ9YhWG9uKILYXxxwBsnm7rey6k7pmBWC41C425BNrJLAFTa86p0YqdukI6TxKJDM+5FoLPNpzCV1n0u0sL1LG8MrwUtCluC5dEbgGHTY9CbLM5L2Zfo3dD6bO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737119054; c=relaxed/simple; bh=S8aAvA4WXylpoHYDraXmDyFyKQB1xkjAujdcxdVXe5o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VrP/XqPbM8WoaflDCiDHbE3QIdfv6WoHph6gm89YZoAsliqIxy1x5IqYjAIrHwt23rfcSafOFbJrd+kADBnecBCxmDCa3ueqRM9TKIxb9iGn8ja3JbQUV8Z0FoAyngkI3AeOTOUk1MGwDelg29CXpg53BDjlkuexPDhwmA3BM8E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=techsingularity.net; spf=pass smtp.mailfrom=techsingularity.net; dkim=pass (1024-bit key) header.d=techsingularity.net header.i=@techsingularity.net header.b=gJ4NSDNA; arc=none smtp.client-ip=3.64.226.209 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=techsingularity.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=techsingularity.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=techsingularity.net header.i=@techsingularity.net header.b="gJ4NSDNA" Received: from smtp-out0101.titan.email (localhost [127.0.0.1]) by smtp-out0101.titan.email (Postfix) with ESMTP id 05F57A003F; Fri, 17 Jan 2025 13:04:10 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=zkWsMh2rOl4BCLRjhpJXqDH/Wyon9reMiWbC/Z8CYjo=; c=relaxed/relaxed; d=techsingularity.net; h=subject:date:message-id:in-reply-to:mime-version:to:from:cc:references:from:to:cc:subject:date:message-id:in-reply-to:references:reply-to; q=dns/txt; s=titan1; t=1737119049; v=1; b=gJ4NSDNA8Zj9CqrlCbMMh+GrCxMXoHfjo9Sn6aHshF6F6tS0qJdApsHUAfA1jQCwVgw3GWOm Drb6lGWzQE70Z+vig5dzVpxEMV/QMWjBU4GT4egKG0ezptlGy1bTQ6x0eKHZxaqk0j4LhzfjnzC aqrFBkpBWiLoI2ITlKpsE1bs= Received: from mail.blacknight.com (ip-84-203-196-66.broadband.digiweb.ie [84.203.196.66]) by smtp-out0101.titan.email (Postfix) with ESMTPA id 8A489A0049; Fri, 17 Jan 2025 13:04:09 +0000 (UTC) Feedback-ID: :mgorman@techsingularity.net:techsingularity.net:flockmailId From: Mel Gorman To: Kees Cook Cc: Daniel Micay , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Mel Gorman Subject: [PATCH 2/3] mm: security: Allow default HARDENED_USERCOPY to be set at compile time Date: Fri, 17 Jan 2025 13:03:36 +0000 Message-ID: <20250117130337.4716-3-mgorman@techsingularity.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250117130337.4716-1-mgorman@techsingularity.net> References: <20250117130337.4716-1-mgorman@techsingularity.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-F-Verdict: SPFVALID X-Titan-Src-Out: 1737119049859662939.9138.8876070193937651565@prod-euc1-smtp-out1002. X-CMAE-Score: 0 X-CMAE-Analysis: v=2.4 cv=UdNXSrSN c=1 sm=1 tr=0 ts=678a5549 a=jU4EnjUUC1PH4wSjvv7Pww==:117 a=jU4EnjUUC1PH4wSjvv7Pww==:17 a=CEWIc4RMnpUA:10 a=R_Myd5XaAAAA:8 a=0z80O7jHjOjBg2F2ajAA:9 a=L2g4Dz8VuBQ37YGmWQah:22 X-Virus-Scanned: ClamAV using ClamSMTP Content-Type: text/plain; charset="utf-8" HARDENED_USERCOPY defaults to on if enabled at compile time. Allow hardened_usercopy=3D default to be set at compile time similar to init_on_alloc=3D and init_on_free=3D. The intent is that hardening options that can be disabled at runtime can set their default at build time. Signed-off-by: Mel Gorman Suggested-by: Kees Cook --- Documentation/admin-guide/kernel-parameters.txt | 4 +++- mm/usercopy.c | 3 ++- security/Kconfig.hardening | 8 ++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 3872bc6ec49d..5d759b20540a 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1773,7 +1773,9 @@ allocation boundaries as a proactive defense against bounds-checking flaws in the kernel's copy_to_user()/copy_from_user() interface. - on Perform hardened usercopy checks (default). + The default is determined by + CONFIG_HARDENED_USERCOPY_DEFAULT_ON. + on Perform hardened usercopy checks. off Disable hardened usercopy checks. =20 hardlockup_all_cpu_backtrace=3D diff --git a/mm/usercopy.c b/mm/usercopy.c index 83c164aba6e0..4cf33305347a 100644 --- a/mm/usercopy.c +++ b/mm/usercopy.c @@ -255,7 +255,8 @@ void __check_object_size(const void *ptr, unsigned long= n, bool to_user) } EXPORT_SYMBOL(__check_object_size); =20 -static bool enable_checks __initdata =3D true; +static bool enable_checks __initdata =3D + IS_ENABLED(CONFIG_HARDENED_USERCOPY_DEFAULT_ON); =20 static int __init parse_hardened_usercopy(char *str) { diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening index 00e6e2ed0c43..537a6431892e 100644 --- a/security/Kconfig.hardening +++ b/security/Kconfig.hardening @@ -293,6 +293,14 @@ config HARDENED_USERCOPY or are part of the kernel text. This prevents entire classes of heap overflow exploits and similar kernel memory exposures. =20 +config HARDENED_USERCOPY_DEFAULT_ON + bool "Harden memory copies by default" + depends on HARDENED_USERCOPY + default n + help + This has the effect of setting "hardened_usercopy=3Don" on the kernel + command line. This can be disabled with "hardened_usercopy=3Doff". + endmenu =20 menu "Hardening of kernel data structures" --=20 2.43.0 From nobody Sat Feb 7 21:08:18 2026 Received: from mail16.out.titan.email (mail16.out.titan.email [3.64.226.210]) (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 E70411FDE1B for ; Fri, 17 Jan 2025 13:04:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=3.64.226.210 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737119064; cv=none; b=HCcUpoIQL3ginRZSwCKVi6KrXBDLztdybIH4DWj8YxD/xme9eZ1OuY8SpSA8OeDoKCkD9IM3/B+vJloxP3/uePYFKrIiD7WH/hX5ha2vg80khRN6xnd9h/UwXSJ/i70TlyJz8Sr4UkIBZ1uoPuAMSi9QsXOjguLrc8R2hral1mY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737119064; c=relaxed/simple; bh=JWxVpo51IRHFVSNtBf3Wmjv1JWsZY7WzUS0vwKR00ig=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jq4jhHNgBAlEGJEVhNjiDwVrwu2p3PC7cP+1K8HXbIxAd2Uaamm3tM9+PfPGxerFyMEAiJl5MU8PAGTd1BjHt66RwbYeE5jZqu80n/iRtH8fuyNdjLcMqf2lwXJAR/cnOduBL3slbBFUUOzXlEZOF0hZvmLfGqcFp/UE0YFoXd0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=techsingularity.net; spf=pass smtp.mailfrom=techsingularity.net; dkim=pass (1024-bit key) header.d=techsingularity.net header.i=@techsingularity.net header.b=Wo9ErUa6; arc=none smtp.client-ip=3.64.226.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=techsingularity.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=techsingularity.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=techsingularity.net header.i=@techsingularity.net header.b="Wo9ErUa6" Received: from smtp-out0101.titan.email (localhost [127.0.0.1]) by smtp-out0101.titan.email (Postfix) with ESMTP id 74593A0049; Fri, 17 Jan 2025 13:04:20 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=VRt5ySVbtyE/C8GSIvo3UXJKgyg0wAqCy+j1mZK4ExM=; c=relaxed/relaxed; d=techsingularity.net; h=cc:date:message-id:from:to:subject:mime-version:in-reply-to:references:from:to:cc:subject:date:message-id:in-reply-to:references:reply-to; q=dns/txt; s=titan1; t=1737119060; v=1; b=Wo9ErUa68zJl79s6WtL753o+Ok/useI3YjFfh7DVAe+b3sIgiEPzjFuqJbDrM1XVRWHn88JJ 8cbZcFGH8ia0oM3HRXFyzCkkRYCQ9uE8SmWyx2duydD9EIqcOHZP0NNuoTY38t74Dg+uTyu0GoH gRiyea3d3wNUarjH5OoqqIgg= Received: from mail.blacknight.com (ip-84-203-196-66.broadband.digiweb.ie [84.203.196.66]) by smtp-out0101.titan.email (Postfix) with ESMTPA id 0ECE3A00A9; Fri, 17 Jan 2025 13:04:20 +0000 (UTC) Feedback-ID: :mgorman@techsingularity.net:techsingularity.net:flockmailId From: Mel Gorman To: Kees Cook Cc: Daniel Micay , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, Mel Gorman Subject: [PATCH 3/3] fortify: Move FORTIFY_SOURCE under 'Kernel hardening options' Date: Fri, 17 Jan 2025 13:03:37 +0000 Message-ID: <20250117130337.4716-4-mgorman@techsingularity.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250117130337.4716-1-mgorman@techsingularity.net> References: <20250117130337.4716-1-mgorman@techsingularity.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-F-Verdict: SPFVALID X-Titan-Src-Out: 1737119060349003360.9138.2734723736871645562@prod-euc1-smtp-out1002. X-CMAE-Score: 0 X-CMAE-Analysis: v=2.4 cv=UdNXSrSN c=1 sm=1 tr=0 ts=678a5554 a=jU4EnjUUC1PH4wSjvv7Pww==:117 a=jU4EnjUUC1PH4wSjvv7Pww==:17 a=CEWIc4RMnpUA:10 a=NEAV23lmAAAA:8 a=R_Myd5XaAAAA:8 a=Q9Z_rya5RYYz_BbIbTgA:9 a=L2g4Dz8VuBQ37YGmWQah:22 X-Virus-Scanned: ClamAV using ClamSMTP Content-Type: text/plain; charset="utf-8" FORTIFY_SOURCE is a hardening option both at build and runtime. Move it under 'Kernel hardening options'. Signed-off-by: Mel Gorman --- security/Kconfig | 9 --------- security/Kconfig.hardening | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/security/Kconfig b/security/Kconfig index fe7346dc4bc3..bca84f839fbe 100644 --- a/security/Kconfig +++ b/security/Kconfig @@ -159,15 +159,6 @@ config LSM_MMAP_MIN_ADDR this low address space will need the permission specific to the systems running LSM. =20 -config FORTIFY_SOURCE - bool "Harden common str/mem functions against buffer overflows" - depends on ARCH_HAS_FORTIFY_SOURCE - # https://github.com/llvm/llvm-project/issues/53645 - depends on !CC_IS_CLANG || !X86_32 - help - Detect overflows of buffers in common string and memory functions - where the compiler can determine and validate the buffer sizes. - config STATIC_USERMODEHELPER bool "Force all usermode helper calls through a single binary" help diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening index 537a6431892e..8d005fe154ef 100644 --- a/security/Kconfig.hardening +++ b/security/Kconfig.hardening @@ -301,6 +301,15 @@ config HARDENED_USERCOPY_DEFAULT_ON This has the effect of setting "hardened_usercopy=3Don" on the kernel command line. This can be disabled with "hardened_usercopy=3Doff". =20 +config FORTIFY_SOURCE + bool "Harden common str/mem functions against buffer overflows" + depends on ARCH_HAS_FORTIFY_SOURCE + # https://github.com/llvm/llvm-project/issues/53645 + depends on !CC_IS_CLANG || !X86_32 + help + Detect overflows of buffers in common string and memory functions + where the compiler can determine and validate the buffer sizes. + endmenu =20 menu "Hardening of kernel data structures" --=20 2.43.0