Received: by 10.223.185.116 with SMTP id b49csp150666wrg; Tue, 20 Feb 2018 17:58:19 -0800 (PST) X-Google-Smtp-Source: AH8x226a+jk7B9W0N1J1jav9zsXF8Eyo2cM5eJrEvAUEUWo9mkL5+n20Nup1Oioh5Rzrxhmx3AGJ X-Received: by 10.98.65.198 with SMTP id g67mr1578865pfd.127.1519178299546; Tue, 20 Feb 2018 17:58:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519178299; cv=none; d=google.com; s=arc-20160816; b=f5eMqsV6um8Ow2k5+DL2UtThqAPkKmic+E8zjiUNIy3eWuZfvQC3aWwhGwQeXTtKiU KAeBPL2XA4WLC6V7OqEGKmBtq1DcT3Mlp8oVVNf1YzIbFKjB2nfKmMbYw88aQoWjVbNm DMCxsTbHbuTnrsBDJBqf9xXtHkrcrpziodqZqptQoa7wGte+3Hgv8cuOhs0uWEwvDaj3 vtuKvcHaMf7sjA5j+sItyDKqXQKraKbU8GgyEfPRdRMtZJRXSscYQHAMEZXqS86aTDyS vj/ILHNqYnzdINsfevUUICvWD1mU7D7/VcqqrUj+UFVA8ghP6JAqHqs5VC5oCllJdw7v cG2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dmarc-filter :arc-authentication-results; bh=A6YwefsHKJAmA4RC1dPZwY26dUCVM4O6+De3kfNUiOQ=; b=ZQ83zLDTz76PuGHuKoKbJd+pVPyKmexDc0b2gDNfANy5ab9bLocv0tei2cHnjLU19j 2tN4U2YEmHNg+8Sv1MkD7nMFOY2itjxCqlyJZisgvT/Lng6veoHj1Ipre+dkyrHNkBHC WL31A8nejmWpnBxQy/i1iAMf4gxtt3/7nJ8H96IGR3O0+5MvS+tI/6mwZOZtU9LJoeDM EBxHQ0QpQEMHNqQZFYTfgMVqQB1xIj1BR3qfIh8aIxr+tjFjDO81bfhj8L+C8o8DUvbr u1Zfs/Jjj2eASEvMV/vZ2UwSsSU/3lG3Z096pxOb+/6ElcPTSQAw/WdnEBLQXu9mJZ1/ XFrA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z124si657630pgb.811.2018.02.20.17.58.05; Tue, 20 Feb 2018 17:58:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751578AbeBUB44 (ORCPT + 99 others); Tue, 20 Feb 2018 20:56:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:33506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751338AbeBUB4y (ORCPT ); Tue, 20 Feb 2018 20:56:54 -0500 Received: from mail-it0-f51.google.com (mail-it0-f51.google.com [209.85.214.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 69CEC2179F for ; Wed, 21 Feb 2018 01:56:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 69CEC2179F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=luto@kernel.org Received: by mail-it0-f51.google.com with SMTP id v186so463033itc.5 for ; Tue, 20 Feb 2018 17:56:54 -0800 (PST) X-Gm-Message-State: APf1xPCe3dTRDwFZd/q2t/faY6Vm+WMLGIz5sorFhV4xdLhlD6k691b/ /8aXSsYaZU9dcBXfbLYDdzt8+Vtounk4hyw/kOZhFQ== X-Received: by 10.36.46.23 with SMTP id i23mr1335689ita.55.1519178213750; Tue, 20 Feb 2018 17:56:53 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.137.101 with HTTP; Tue, 20 Feb 2018 17:56:33 -0800 (PST) In-Reply-To: <20180220163142.15366a82a7bece715b997597@linux-foundation.org> References: <20180117055015.GA15256@beast> <20180220163142.15366a82a7bece715b997597@linux-foundation.org> From: Andy Lutomirski Date: Wed, 21 Feb 2018 01:56:33 +0000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] fork: Allow stack to be wiped on fork To: Andrew Morton Cc: Kees Cook , Andy Lutomirski , Jann Horn , Ingo Molnar , Laura Abbott , Thomas Gleixner , Al Viro , Sahara , "Levin, Alexander (Sasha Levin)" , Michal Hocko , Andrea Arcangeli , "Kirill A. Shutemov" , LKML , Kernel Hardening Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 21, 2018 at 12:31 AM, Andrew Morton wrote: > On Tue, 16 Jan 2018 21:50:15 -0800 Kees Cook wrote: > >> One of the classes of kernel stack content leaks is exposing the contents >> of prior heap or stack contents when a new process stack is allocated. >> Normally, those stacks are not zeroed, and the old contents remain in >> place. With some types of stack content exposure flaws, those contents >> can leak to userspace. Kernels built with CONFIG_CLEAR_STACK_FORK will >> no longer be vulnerable to this, as the stack will be wiped each time >> a stack is assigned to a new process. There's not a meaningful change >> in runtime performance; it almost looks like it provides a benefit. >> >> Performing back-to-back kernel builds before: >> Run times: 157.86 157.09 158.90 160.94 160.80 >> Mean: 159.12 >> Std Dev: 1.54 >> >> With CONFIG_CLEAR_STACK_FORK=y: >> Run times: 159.31 157.34 156.71 158.15 160.81 >> Mean: 158.46 >> Std Dev: 1.46 >> >> ... >> >> --- a/arch/Kconfig >> +++ b/arch/Kconfig >> @@ -904,6 +904,14 @@ config VMAP_STACK >> the stack to map directly to the KASAN shadow map using a formula >> that is incorrect if the stack is in vmalloc space. >> >> +config CLEAR_STACK_FORK >> + bool "Clear the kernel stack at each fork" >> + help >> + To resist stack content leak flaws, this clears newly allocated >> + kernel stacks to keep previously freed heap or stack contents >> + from being present in the new stack. This has almost no >> + measurable performance impact. >> + > > It would be much nicer to be able to control this at runtime rather > than compile-time. Why not a /proc tunable? We could always use more > of those ;) /proc/sys/kernel/hardening_features_that_cost_essentially_nothing? Seriously, though, why don't we just enable it unconditionally? It wouldn't surprise me if it really is a speedup on more workloads than it slows down -- it'll fill the kernel stack into the CPU cache with exclusive ownership very quickly (streamily and without actually reading from memory, I imagine, at least on new enough CPUs) rather than grabbing each cache line one by one as they get used.