Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4950251pxv; Tue, 20 Jul 2021 15:18:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoSZ432dmdxAOx2jK2eCYfl6VPkRbrYGl7vJqPSBVFHKBCHv9Hd4XjvMntnJC+gPcniBOl X-Received: by 2002:a05:6402:5142:: with SMTP id n2mr44384588edd.10.1626819501710; Tue, 20 Jul 2021 15:18:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626819501; cv=none; d=google.com; s=arc-20160816; b=c/SgMwdtd8PqpgEAJIpA+Mcodd51eq7DtPCGrUrjVfysidTb3+zJjhzGAY4m5wLYs2 rEcb/ql8bJ3HdFjGyiAwcoOCLSr3XR5G2lNwupPMTjdO+SL9mzYvCa6qcEO8TGnN1CKU Imjbo/1WzYaSNJ73gnkZJwRC6CyBE/OrK0ozmyXNbZ/qNAvb5UZ1bE06bQWdxuskiIcL 7aPFqXXGhuz9melu+q7pdQ8hjODHQ4QTkWg6h12vTpN3JkbVBJLSqXkQlIQgAm8XT3X5 pYhbIGBFW4+YzTpNQIiPYZetHYYmZSD6UqYCpGAcciSUMnPCIBI5NED2hQUhCeHJIV9w 5mdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=cxXdwyf86/iBd4y3nxKbGfWmpLYKe5FEr/5hOz+4xlA=; b=Km4p21FB7kJOFRF5L3SeY9zmaC0E1dizU7EP7iJdul0NLriddpJqA5jm9H8hidT6xp FbqJMfDHIjo2zG4JCSrdM81kQ5ELjJ5NhZ/OwhNcxIDVweNGhT5KWxrcCOou6q9lMh0K rMkMaxCxHi2/aH8CesBhtL2XQGj8K/xippWXCcuQ+mXydqR9Yeih6FRjcNnW/6miKFJ1 5MgBLzeqyTmDrdaQ5qqbVN/NSuPCU7mrpb0/Om/8ju8oaJKpOLcU6DZeSz8zCn44lO5V 5NEvAySsPjvVCzuWmiFCnDxo+73n9tTWbq1d4UadCTiXqkPZnXwZ7OvYQTVCfb84KK+4 0QMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iCwQ6QDK; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p23si26898758edw.135.2021.07.20.15.17.55; Tue, 20 Jul 2021 15:18:21 -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=@kernel.org header.s=k20201202 header.b=iCwQ6QDK; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233300AbhGTVeQ (ORCPT + 99 others); Tue, 20 Jul 2021 17:34:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:51498 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230441AbhGTVdd (ORCPT ); Tue, 20 Jul 2021 17:33:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 89BEE61004; Tue, 20 Jul 2021 22:13:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626819236; bh=C9xEUpcszWLTz7G41tiUMq/T9ZUtgRdO9miCXuErFAI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=iCwQ6QDKbh4e8g/K0osooLvKZkiaAMJ2oNiYhzQNUNfAuxqVUzeTrb1yf7TPmlLDg sY+7dmKGhZR/FjKYc6QUD16dVjp2ZB3pmUKBwEWwQhatxJnA7dK/zKEQBVzAxab2NP jG1u9nMG1LOWkqpXOLe4lHZGaQJ1OYDDxivsqJjAY9F+Li4SavlT1bBNvKWh2ZwBJV c2J1HgvuuslUa4p6PmZ+rd/A5IGhGHfXOZ/utSipTatuniGEWxdoHqEJKqxSnGIQSI wPpBJa7W51aT7+VUhHr+xWBL0Cv5/FZsfBwtLP/Q3ATmU2kjnR9ZPks65rxK9VdoiL lTmCfWPAQAFrA== Date: Tue, 20 Jul 2021 17:16:17 -0500 From: "Gustavo A. R. Silva" To: Kees Cook Cc: linux-hardening@vger.kernel.org, glider@google.com, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, clang-built-linux@googlegroups.com Subject: Re: [PATCH] hardening: Clarify Kconfig text for auto-var-init Message-ID: <20210720221617.GA94423@embeddedor> References: <20210720215957.3446719-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210720215957.3446719-1-keescook@chromium.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 20, 2021 at 02:59:57PM -0700, Kees Cook wrote: > 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 Acked-by: Gustavo A. R. Silva Thanks! -- Gustavo > --- > 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 >