Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932219Ab2HQITS (ORCPT ); Fri, 17 Aug 2012 04:19:18 -0400 Received: from sd-mail-sa-02.sanoma.fi ([158.127.18.162]:45707 "EHLO sd-mail-sa-02.sanoma.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754332Ab2HQISa (ORCPT ); Fri, 17 Aug 2012 04:18:30 -0400 Message-ID: <20120817111826.15226265ph07g70g@www.81.fi> Date: Fri, 17 Aug 2012 11:18:26 +0300 From: Jussi Kivilinna To: David Daney Cc: "Kasatkin, Dmitry" , herbert@gondor.hengli.com.au, linux-crypto , LKML , linux-security-module Subject: Re: on stack dynamic allocations References: <502D6691.5010101@gmail.com> In-Reply-To: <502D6691.5010101@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; DelSp="Yes"; format="flowed" Content-Disposition: inline Content-Transfer-Encoding: 7bit User-Agent: Internet Messaging Program (IMP) H3 (4.3.7) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1179 Lines: 41 Quoting David Daney : > 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! > Quick look shows that largest crypto_shash_descsize() would be with hmac+s390/sha512, 16 + 332 = 348. Crypto-api also prevents registering shash with descsize larger than (PAGE_SIZE / 8). -Jussi -- 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/