Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4936830pxv; Tue, 20 Jul 2021 15:03:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykucKirn70irSmDAS+kgZc4oWHutJx8xY3sDZwoX9UMnKcjaeZO6HuhYh1Smhipnptz7Q0 X-Received: by 2002:aa7:c5da:: with SMTP id h26mr43778228eds.109.1626818604099; Tue, 20 Jul 2021 15:03:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626818604; cv=none; d=google.com; s=arc-20160816; b=YTSy9t3mD8DAaSYDBuLHcys8pkbh8ndaf36aI2LeiFCO538OO1XzBle5C7c/s6CQU1 GI/HzvWjjmQ5MaRjbXm6YG/nrARzBzPQ/54eCKA4WAPO2s2eFgs0NSVjkBn8QQjbyYmr xmQ6DwNQU2bFkqZGAcWdsX1X1aHog0qpGtkHox5P+yD5d+j5ME7lp3hDi+q1D/CXpJ77 /w5XDOk3bkEaR9EKUyVqzURtPc1ong8JX91oLUAvjBq/pUfcD6Ru5OoeLGDzmJ5mYwUt tvntsz2J6a3jyZkl3a7Mh8c6SEimJRB8+lX030aZ49By5JTd2HW0vdhhLtHPxKDHuMk9 ssXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=WyxGUW8l0i1+27gVKNpxMIuSdpPKu6kJDnkVFPaL1B8=; b=UEUkY3exUhTS2QFsQZPc0+NvcM+mlrLttrJ49gTeZuWMPjl0jwEFv+Xoweb725DLRc LDExQ2eZk3/DIJydlEQMAk4GXLXK9she6kc+1TDjstskC/Fa9wDy4ExpkYSmonWI9/yl sEOs4KB61iRHRM9xANyKQOvJDeH97VnZGkBnz1WzY8iHcngPnEsqO/6yWIfxjZT+pjIU fB7SeNIJ/aMR8uvXCllk3lzOC0VHoxat7zdHlqSw4faLc+UjFKJmeOmL/DUSAUn+Imhr a090lkvJKuPuULlr7Ag+/6yWk1MOO9Lob7rD3McZeUofqM0xojrhuCx8E4667R/2L9hO t3JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CvGYL7R+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id sd11si27035133ejb.511.2021.07.20.15.02.57; Tue, 20 Jul 2021 15:03:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CvGYL7R+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230123AbhGTVTf (ORCPT + 99 others); Tue, 20 Jul 2021 17:19:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230039AbhGTVT0 (ORCPT ); Tue, 20 Jul 2021 17:19:26 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 582BDC061762 for ; Tue, 20 Jul 2021 15:00:03 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id cu14so531340pjb.0 for ; Tue, 20 Jul 2021 15:00:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WyxGUW8l0i1+27gVKNpxMIuSdpPKu6kJDnkVFPaL1B8=; b=CvGYL7R+ixxU/JIlmN6/TJdMXXXXBl4WApNx0WZ/sQ60gmly7rRjWn5rEs/7RcgL8+ 48a66pvoeTtIOcO4Yj/ISKAz00K3YYrzUYzvTtWhiQMdzEx0SMkmZvjNddi27ZygyNgz VF3+NsdsEEmtRvjR7ZOmSMnN7Cylp8rFHYI5U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WyxGUW8l0i1+27gVKNpxMIuSdpPKu6kJDnkVFPaL1B8=; b=HKu5eCqEX46en+GLknD8GRvV0AmvoRWKnEtk+h6soxWxVf4tgMJ9yB42VwkT+WZUte joIbUCGD1w4zWwRBU0xleoeeZAYlHJxQ5YbE2NYdchOTnJ9xlUIYAXwylJuXm8FSYKTP xp2Fc9WCwZ0IQxCXGqRfs5JLLlDg/89wR/yFoQBowWD0QoRg0BV9rhXPxbPIeyKZr8my fqSWr9wMTeh2M23schU8n8fSztNhROWrpVw69ANsmv3IZpNjPhsEjUEUL9t1Itmw4UZf DNFVOKefLyvL55krkh5CapzL1lS04HafC1VOyMNGtEse2XuoDAUoJ3BmsJL+7+QG7c7h S7UA== X-Gm-Message-State: AOAM531Yza22OzWjA15mEDeX5X9+zxTCeLRj5xDmhKg3+TfztzNPwW6y YBpBEBgfS3Xb7RIxGtTKQZnJmQ== X-Received: by 2002:a17:90a:c8b:: with SMTP id v11mr505781pja.114.1626818401485; Tue, 20 Jul 2021 15:00:01 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id e16sm28694557pgl.54.2021.07.20.15.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 15:00:00 -0700 (PDT) From: Kees Cook To: linux-hardening@vger.kernel.org Cc: Kees Cook , glider@google.com, "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, clang-built-linux@googlegroups.com Subject: [PATCH] hardening: Clarify Kconfig text for auto-var-init Date: Tue, 20 Jul 2021 14:59:57 -0700 Message-Id: <20210720215957.3446719-1-keescook@chromium.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4689; h=from:subject; bh=Z2jIdIqSWFjGjbsnH0q1H4OQWdcOHIzxX0E/vHpuz2Y=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBg90dclov0B+zGzREFyMibbwv9l5oqr9QJrpcMBRsN hb++VKyJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYPdHXAAKCRCJcvTf3G3AJvpfD/ 48Gq6fxhiEccbjQyQe+7IJXzIsYGWv+awOpA5DqwDe5ctfyYW5icxUSVx+Clzkn60bS8MOF5HK64Zs zu2EN8WIVWI53o/I7n8yieURnaJhOWRaodHPfz6sO8dvn3ddQAG2LF18ckn+L532AKdvPnDGhGHFDR Ez7EcJQoM2jNCTffA+Z7joyraqV4sL590QVJ6mB6CWtxsy2rB8JRIv73xRyHtajtELy3TJ9fExNdDZ ZIA26rgLKetjgMSKtz45O4khEwF0biQzfJw/pev0HXIzTOs5LZ+oxWMKyMM5dU9/77VKgTx6FDd9OE /Un9lPGCZKWTkGdyOUTXo4LNX2DYldun1e7zJ6Y73mo0HY//kluFhjJx/A84aNfge+v8JufRdH7ymD woQcwoMBkyRAWQFy4Jd/S91LPhyp1NA1uXoc4M8ZXvePbBtG201Awb2fCaYEAuXm7TiR18GmAtRqsB XR3rfGyHFvi/qRNpjBfAnvgOL2UY/r9TYrKZhNBEsMcIWpGLKjT6Jtlqf8MmXHsuNVElcnIPRCgom9 wdrabjtlA41UUFPBGhgsEF76FSR3UPI2v3gL/T+jL7RjJp++1nTkK5M38G1RKo8Zfda0wK3qcLIaVU vs2ym4j9tzZ8qvAreuqUY7R+rhMNrO4+Iyo4eQ8M6ZhUT9i1aYIRpPQ0uhQw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Clarify the details around the automatic variable initialization modes available. Specifically this details the values used for pattern init and expands on the rationale for zero init safety. Additionally makes zero init the default when available. Signed-off-by: Kees Cook --- security/Kconfig.hardening | 52 +++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening index 023aea5e117c..90cbaff86e13 100644 --- a/security/Kconfig.hardening +++ b/security/Kconfig.hardening @@ -29,6 +29,7 @@ choice prompt "Initialize kernel stack variables at function entry" default GCC_PLUGIN_STRUCTLEAK_BYREF_ALL if COMPILE_TEST && GCC_PLUGINS default INIT_STACK_ALL_PATTERN if COMPILE_TEST && CC_HAS_AUTO_VAR_INIT_PATTERN + default INIT_STACK_ALL_ZERO if CC_HAS_AUTO_VAR_INIT_PATTERN default INIT_STACK_NONE help This option enables initialization of stack variables at @@ -39,11 +40,11 @@ choice syscalls. This chooses the level of coverage over classes of potentially - uninitialized variables. The selected class will be + uninitialized variables. The selected class of variable will be initialized before use in a function. config INIT_STACK_NONE - bool "no automatic initialization (weakest)" + bool "no automatic stack variable initialization (weakest)" help Disable automatic stack variable initialization. This leaves the kernel vulnerable to the standard @@ -80,7 +81,7 @@ choice and is disallowed. config GCC_PLUGIN_STRUCTLEAK_BYREF_ALL - bool "zero-init anything passed by reference (very strong)" + bool "zero-init everything passed by reference (very strong)" depends on GCC_PLUGINS depends on !(KASAN && KASAN_STACK) select GCC_PLUGIN_STRUCTLEAK @@ -91,33 +92,44 @@ choice of uninitialized stack variable exploits and information exposures. + As a side-effect, this keeps a lot of variables on the + stack that can otherwise be optimized out, so combining + this with CONFIG_KASAN_STACK can lead to a stack overflow + and is disallowed. + config INIT_STACK_ALL_PATTERN - bool "0xAA-init everything on the stack (strongest)" + bool "pattern-init everything (strongest)" depends on CC_HAS_AUTO_VAR_INIT_PATTERN help - Initializes everything on the stack with a 0xAA - pattern. This is intended to eliminate all classes - of uninitialized stack variable exploits and information - exposures, even variables that were warned to have been - left uninitialized. + Initializes everything on the stack (including padding) + with a specific debug value. This is intended to eliminate + all classes of uninitialized stack variable exploits and + information exposures, even variables that were warned about + having been left uninitialized. Pattern initialization is known to provoke many existing bugs related to uninitialized locals, e.g. pointers receive - non-NULL values, buffer sizes and indices are very big. + non-NULL values, buffer sizes and indices are very big. The + pattern is situation-specific; Clang on 64-bit uses 0xAA + repeating for all types and padding except float and double + which use 0xFF repeating (-NaN). Clang on 32-bit uses 0xFF + repeating for all types and padding. config INIT_STACK_ALL_ZERO - bool "zero-init everything on the stack (strongest and safest)" + bool "zero-init everything (strongest and safest)" depends on CC_HAS_AUTO_VAR_INIT_ZERO help - Initializes everything on the stack with a zero - value. This is intended to eliminate all classes - of uninitialized stack variable exploits and information - exposures, even variables that were warned to have been - left uninitialized. - - Zero initialization provides safe defaults for strings, - pointers, indices and sizes, and is therefore - more suitable as a security mitigation measure. + Initializes everything on the stack (including padding) + with a zero value. This is intended to eliminate all + classes of uninitialized stack variable exploits and + information exposures, even variables that were warned + about having been left uninitialized. + + Zero initialization provides safe defaults for strings + (immediately NUL-terminated), pointers (NULL), indices + (index 0), and sizes (0 length), so it is therefore more + suitable as a production security mitigation than pattern + initialization. endchoice -- 2.30.2