Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030510Ab2HPVbE (ORCPT ); Thu, 16 Aug 2012 17:31:04 -0400 Received: from mail-gg0-f174.google.com ([209.85.161.174]:55863 "EHLO mail-gg0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030362Ab2HPVbB (ORCPT ); Thu, 16 Aug 2012 17:31:01 -0400 Message-ID: <502D6691.5010101@gmail.com> Date: Thu, 16 Aug 2012 14:30:57 -0700 From: David Daney User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120717 Thunderbird/14.0 MIME-Version: 1.0 To: "Kasatkin, Dmitry" CC: herbert@gondor.hengli.com.au, linux-crypto , LKML , linux-security-module Subject: Re: on stack dynamic allocations References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 912 Lines: 36 On 08/16/2012 02:20 PM, Kasatkin, Dmitry wrote: > Hello, > > Some places in the code uses variable-size allocation on stack.. > For example from hmac_setkey(): > > struct { > struct shash_desc shash; > char ctx[crypto_shash_descsize(hash)]; > } desc; > > > sparse complains > > CHECK crypto/hmac.c > crypto/hmac.c:57:47: error: bad constant expression > > I like it instead of kmalloc.. > > But what is position of kernel community about it? If you know that the range of crypto_shash_descsize(hash) is bounded, just use the upper bound. If the range of crypto_shash_descsize(hash) is unbounded, then the stack will overflow and ... BOOM! David Daney -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/