lkml.org 
[lkml]   [2008]   [Jul]   [16]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
/
DateWed, 16 Jul 2008 14:35:10 +0800
FromHerbert Xu <>
SubjectRe: BUG: unable to handle kernel NULL pointer dereference at 000000000000000e (reset_prng_context)
On Tue, Jul 15, 2008 at 11:17:34PM -0700, Andrew Morton wrote:
>
> On error the function will sometimes return -EFOO and other times will
> just return -1.  This is inconsistent and makes the error returns
> rather less useful than they could be.  I'd suggest that it be switched
> to -1 throughout or, better, to consistently use appropriate error codes.

Yes -1 should be replaced with a more meaningful error.
> 
> > +struct prng_context *alloc_prng_context(void)
> > +{
> > +	struct prng_context *ctx=kzalloc(sizeof(struct prng_context), GFP_KERNEL);
> > +
> > +	spin_lock_init(&ctx->prng_lock);
> > +
> > +	if (reset_prng_context(ctx, NULL, NULL, NULL, NULL)) {
> > +		kfree(ctx);
> > +		ctx = NULL;
> > +	}
> > +
> > +	dbgprint(KERN_CRIT "returning context %p\n",ctx);
> > +	return ctx;
> > +}
> > +
> > +EXPORT_SYMBOL_GPL(alloc_prng_context);
> > +
> > +void free_prng_context(struct prng_context *ctx)
> > +{
> > +	crypto_free_blkcipher(ctx->tfm);
> > +	kfree(ctx);
> > +}
> > +EXPORT_SYMBOL_GPL(free_prng_context);
> > +
> > +int reset_prng_context(struct prng_context *ctx,
> > +		       unsigned char *key, unsigned char *iv,
> > +		       unsigned char *V, unsigned char *DT)
> > +{
> > +	int ret;
> > +	int iv_len;
> > +	int rc = -EFAULT;
> > +
> > +	spin_lock(&ctx->prng_lock);
> > +	ctx->flags |= PRNG_NEED_RESET;
> > +
> > +	if (key)
> > +		memcpy(ctx->prng_key,key,strlen(ctx->prng_key));
> > +	else
> > +		ctx->prng_key = DEFAULT_PRNG_KEY;
> 
> This is very strange.  In one case we'll copy a string onto existing
> storage at ctx->prng_key.  In the other case we'll *modify*
> ctx->prng_key directly.

Indeed this is bogus.  We shouldn't store either the key or the
IV in the context since the tfm already holds a copy.

Neil, please remove prng_key and prng_iv completely.

> We don't support \0's in the key or the IV.  I assume that's OK?

No the caller should supply the length instead.

Thanks,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

\
 
 \ /
  Last update: 2008-07-16 08:39    [from the cache]
©2003-2008