Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1163818imm; Wed, 1 Aug 2018 11:14:16 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfU6ryGVkIYYxl9TZmJknHg1tsDLF47/fcR8L3DfmNYTnBqutzdisS+PuegFrMI3apNNB1X X-Received: by 2002:a63:3089:: with SMTP id w131-v6mr1852531pgw.79.1533147256083; Wed, 01 Aug 2018 11:14:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533147256; cv=none; d=google.com; s=arc-20160816; b=f3Xi1hIIzbBHIhVfEgG29aEm+cWuVwNGrPhb1h0qnWZuBUHcxC/90wwmo7FMmUDMoF y3x1rTfDqNOYAEYyxULf9Kx0FOVEF8m3U6oXAauI9I5OccOxZNyOQfl2hnBHgY7i0m0S w+1cRZ21sZ8buxQZOe2gNHaj3NbSyg7wVFx169BhwRl/mzT8Nz9OwcH/PmjB0PBHz6WI DNK0zGz0aRiPS6/DRsbeSWVI7SF/cs3YjSRRggqo8BtauWn/Vf9+1zWAMxLuXTvx53Ab Yl3JUBrAIS2xCIYlZ3vKYTF4xCdOCo7sXoeQkVBmakinWd8+20sNH1vrItOfNsnqyUGD M4tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=EHbGpO1j8xVGomtRgCgYyfdpXSbSt/0yjK0PeXVWYqc=; b=p50ol3IkBxTfvybTTfBRifBxnJJuRJGH+2c4JZfdMsiJiCgwfo0dCdE24F4MGtF0Q4 sQlQVc5S/DUcGNA85PFsDcw3R8G2iVq4D2uGi7GLvRrR1NoG6mRGxu9yJSmygvYHMNE1 d/+Y9DCUWbwm/cjmGlkuQPJFxLsQ1z/awegtmRaCJG9dBTnl27WK0ibDE1jDNWQZ5eSx dMOFiQTbY74zgLf0XG5rPt8BAVOzRndis9jhWG5oratxel0MWn3+xa+i3T+JzdyYi+xz RAC2qxiZ4NLMeJ7dHli+sNVdsriqoMH9crvVRBT/tPUSYXe+r9hCg0thW7C0pC7WxHf7 mQ9A== 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 y40-v6si8021278pla.229.2018.08.01.11.14.01; Wed, 01 Aug 2018 11:14:16 -0700 (PDT) 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 S1732476AbeHAT7a (ORCPT + 99 others); Wed, 1 Aug 2018 15:59:30 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49812 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405670AbeHATIe (ORCPT ); Wed, 1 Aug 2018 15:08:34 -0400 Received: from localhost (D57E6652.static.ziggozakelijk.nl [213.126.102.82]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B94161326; Wed, 1 Aug 2018 17:11:48 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kees Cook , Michal Hocko , Andrew Morton , Andy Lutomirski , Laura Abbott , Rasmus Villemoes , Mel Gorman , Linus Torvalds Subject: [PATCH 4.14 001/246] fork: unconditionally clear stack on fork Date: Wed, 1 Aug 2018 18:48:31 +0200 Message-Id: <20180801165011.771687701@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801165011.700991984@linuxfoundation.org> References: <20180801165011.700991984@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kees Cook commit e01e80634ecdde1dd113ac43b3adad21b47f3957 upstream. One of the classes of kernel stack content leaks[1] 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. In the face of stack content exposure flaws, those contents can leak to userspace. Fixing this will make the kernel no longer vulnerable to these flaws, 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 and after: Run times: 159.31 157.34 156.71 158.15 160.81 Mean: 158.46 Std Dev: 1.46 Instead of making this a build or runtime config, Andy Lutomirski recommended this just be enabled by default. [1] A noisy search for many kinds of stack content leaks can be seen here: https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=linux+kernel+stack+leak I did some more with perf and cycle counts on running 100,000 execs of /bin/true. before: Cycles: 218858861551 218853036130 214727610969 227656844122 224980542841 Mean: 221015379122.60 Std Dev: 4662486552.47 after: Cycles: 213868945060 213119275204 211820169456 224426673259 225489986348 Mean: 217745009865.40 Std Dev: 5935559279.99 It continues to look like it's faster, though the deviation is rather wide, but I'm not sure what I could do that would be less noisy. I'm open to ideas! Link: http://lkml.kernel.org/r/20180221021659.GA37073@beast Signed-off-by: Kees Cook Acked-by: Michal Hocko Reviewed-by: Andrew Morton Cc: Andy Lutomirski Cc: Laura Abbott Cc: Rasmus Villemoes Cc: Mel Gorman Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- include/linux/thread_info.h | 6 +----- kernel/fork.c | 3 +-- 2 files changed, 2 insertions(+), 7 deletions(-) --- a/include/linux/thread_info.h +++ b/include/linux/thread_info.h @@ -43,11 +43,7 @@ enum { #define THREAD_ALIGN THREAD_SIZE #endif -#if IS_ENABLED(CONFIG_DEBUG_STACK_USAGE) || IS_ENABLED(CONFIG_DEBUG_KMEMLEAK) -# define THREADINFO_GFP (GFP_KERNEL_ACCOUNT | __GFP_ZERO) -#else -# define THREADINFO_GFP (GFP_KERNEL_ACCOUNT) -#endif +#define THREADINFO_GFP (GFP_KERNEL_ACCOUNT | __GFP_ZERO) /* * flag set/clear/test wrappers --- a/kernel/fork.c +++ b/kernel/fork.c @@ -215,10 +215,9 @@ static unsigned long *alloc_thread_stack if (!s) continue; -#ifdef CONFIG_DEBUG_KMEMLEAK /* Clear stale pointers from reused stack. */ memset(s->addr, 0, THREAD_SIZE); -#endif + tsk->stack_vm_area = s; return s->addr; }