public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* on stack dynamic allocations
@ 2012-08-16 21:20 Kasatkin, Dmitry
  2012-08-16 21:30 ` David Daney
  0 siblings, 1 reply; 3+ messages in thread
From: Kasatkin, Dmitry @ 2012-08-16 21:20 UTC (permalink / raw)
  To: herbert; +Cc: linux-crypto, LKML, linux-security-module

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?

- Dmitry

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: on stack dynamic allocations
  2012-08-16 21:20 on stack dynamic allocations Kasatkin, Dmitry
@ 2012-08-16 21:30 ` David Daney
  2012-08-17  8:18   ` Jussi Kivilinna
  0 siblings, 1 reply; 3+ messages in thread
From: David Daney @ 2012-08-16 21:30 UTC (permalink / raw)
  To: Kasatkin, Dmitry; +Cc: herbert, linux-crypto, LKML, linux-security-module

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




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: on stack dynamic allocations
  2012-08-16 21:30 ` David Daney
@ 2012-08-17  8:18   ` Jussi Kivilinna
  0 siblings, 0 replies; 3+ messages in thread
From: Jussi Kivilinna @ 2012-08-17  8:18 UTC (permalink / raw)
  To: David Daney
  Cc: Kasatkin, Dmitry, herbert, linux-crypto, LKML,
	linux-security-module

Quoting David Daney <ddaney.cavm@gmail.com>:

> 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-08-17  8:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-16 21:20 on stack dynamic allocations Kasatkin, Dmitry
2012-08-16 21:30 ` David Daney
2012-08-17  8:18   ` Jussi Kivilinna

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox