From: Linus Torvalds Subject: Re: [PATCH] lib/sha1: remove memsets and allocate workspace on the stack Date: Mon, 8 Aug 2011 16:50:22 -0700 Message-ID: References: <1312844837-10086-1-git-send-email-msb@chromium.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Cc: linux-kernel@vger.kernel.org, Ramsay Jones , Nicolas Pitre , Joachim Eastwood , Andreas Schwab , Herbert Xu , "David S. Miller" , linux-crypto@vger.kernel.org To: Mandeep Singh Baines Return-path: Received: from smtp1.linux-foundation.org ([140.211.169.13]:34534 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751080Ab1HHXvT (ORCPT ); Mon, 8 Aug 2011 19:51:19 -0400 In-Reply-To: <1312844837-10086-1-git-send-email-msb@chromium.org> Sender: linux-crypto-owner@vger.kernel.org List-ID: On Mon, Aug 8, 2011 at 4:07 PM, Mandeep Singh Baines wrote: > > There is no loss of security due to removing the memset. It would be a > bug for the stack to leak to userspace. However, a defence-in-depth > argument could be made for keeping the clearing of the workspace. So I'm nervous about this just because I can see the security crazies rising up about this. The fact is, in our current code in drivers/char/random.c, we do have a memset() of the workspace buffer on the stack, and any competent compiler should actually just remove it, because it's dead memory (and the compiler can *see* that it's dead memory). Of course, I don't know if gcc does notice that, but it's a prime example of code that "looks" secure, but has absolutely zero actual real security. Getting rid of the memset() is actually better for *real* security, in that at least it's not some kind of pointless security theater. But I can see some people wanting to add a memory barrier or something to force the memset() to actually take place. So I dunno. Arguably it's theoretically possible to find random data on the stack, and maybe it can even be interesting (although I don't think the last 64 bytes of SHA1 state is all that exciting myself). Personally, I consider it unlikely as hell to be relevant to anybody, and anybody who has access to the kernel stack has *much* more direct security holes than some random data that they can use. But the patch still makes me worry about the brouhaha from some people. Linus