lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1253319020.3364.180.camel@calx>
Date:	Fri, 18 Sep 2009 19:10:20 -0500
From:	Matt Mackall <mpm@...enic.com>
To:	Roel Kluin <roel.kluin@...il.com>
Cc:	Andrew Morton <akpm@...ux-foundation.org>,
	LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] random: kmalloc failure ignored in init_std_data()

On Sat, 2009-09-19 at 01:03 +0200, Roel Kluin wrote:
> Clean up and error out if kmalloc() fails.

No thanks. Let's instead make it so it can't fail by building the array
into the statically allocated pool structures.

> Signed-off-by: Roel Kluin <roel.kluin@...il.com>
> ---
> Found with sed: http://kernelnewbies.org/roelkluin
> 
> Build tested. Please review
> 
> diff --git a/drivers/char/random.c b/drivers/char/random.c
> index d8a9255..8a68be8 100644
> --- a/drivers/char/random.c
> +++ b/drivers/char/random.c
> @@ -939,7 +939,7 @@ EXPORT_SYMBOL(get_random_bytes);
>   * data into the pool to prepare it for use. The pool is not cleared
>   * as that can only decrease the entropy in the pool.
>   */
> -static void init_std_data(struct entropy_store *r)
> +static int init_std_data(struct entropy_store *r)
>  {
>  	ktime_t now;
>  	unsigned long flags;
> @@ -952,16 +952,35 @@ static void init_std_data(struct entropy_store *r)
>  	mix_pool_bytes(r, &now, sizeof(now));
>  	mix_pool_bytes(r, utsname(), sizeof(*(utsname())));
>  	/* Enable continuous test in fips mode */
> -	if (fips_enabled)
> +	if (fips_enabled) {
>  		r->last_data = kmalloc(EXTRACT_SIZE, GFP_KERNEL);
> +		if (r->last_data == NULL)
> +			return -ENOMEM;
> +	}
> +	return 0;
>  }
>  
>  static int rand_initialize(void)
>  {
> -	init_std_data(&input_pool);
> -	init_std_data(&blocking_pool);
> -	init_std_data(&nonblocking_pool);
> +	int ret;
> +	ret = init_std_data(&input_pool);
> +	if (ret != 0)
> +		return ret;
> +
> +	ret = init_std_data(&blocking_pool);
> +	if (ret != 0)
> +		goto free_ip_ld;
> +
> +	ret = init_std_data(&nonblocking_pool);
> +	if (ret != 0)
> +		goto free_bp_ld;
> +
>  	return 0;
> +free_bp_ld:
> +	kfree(blocking_pool.last_data);
> +free_ip_ld:
> +	kfree(input_pool.last_data);
> +	return ret;
>  }
>  module_init(rand_initialize);
>  
> @@ -1160,8 +1179,8 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
>  		/* Clear the entropy pool counters. */
>  		if (!capable(CAP_SYS_ADMIN))
>  			return -EPERM;
> -		rand_initialize();
> -		return 0;
> +		retval = rand_initialize();
> +		return retval;
>  	default:
>  		return -EINVAL;
>  	}

-- 
http://selenic.com : development and support for Mercurial and Linux


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ