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]
Date:	Mon, 13 Feb 2012 14:27:55 -0600 (CST)
From:	Christoph Lameter <cl@...ux.com>
To:	Dan Carpenter <dan.carpenter@...cle.com>
cc:	Xi Wang <xi.wang@...il.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Jesper Juhl <jj@...osbits.net>, Jens Axboe <axboe@...nel.dk>,
	Pekka Enberg <penberg@...nel.org>,
	linux-kernel@...r.kernel.org, Matt Mackall <mpm@...enic.com>,
	David Rientjes <rientjes@...gle.com>
Subject: Re: [PATCH RFC v2] slab: introduce kmalloc_array

On Mon, 13 Feb 2012, Dan Carpenter wrote:

>
> The point was that there are a bunch of places where we have had
> integer overflows caused by doing kmalloc(x * sizeof(struct whatever)).
> For kzalloc(x * sizeof(struct whatever)), you just write it like
> kcalloc(x, sizeof(struct whatever)) and avoid the overflow, but we
> don't have a non-zeroing version of kcalloc() to do that.
>
> Probably once we have the kmalloc_array() and people start using it,
> we get a bunch of overflow checking automatically and it's a kernel
> hardenning thing.  As well we could remove the duplicative checking
> so it's a cleanup.

Could you just do a macro that can be used in any location where the
size of an array needs to be calculation. For example:

	SAFE_ARRAY_SIZE(<nr>,<struct>)

So you'd do

	kmalloc_node(SAFE_ARRAY_SIZE(10, struct page), 2, GFP_KERNEL)

or if you want multiple dimensions

	SAFE_ARRAY_SIZE_2(<nr1>,<nr2>,<struct>)

?

> > If you add these variants then please think
> > about the necessity to add other variants (like the kmalloc_node() NUMA
> > call) etc in the future.
> >
>
> We don't have a kcalloc_node(), so I don't think this is likely to
> be a big issue.

Yes and so if you need to allocate on a particular node then you need to
do the calculation manually and therefore may not check for overflows.

Get rid of kcalloc and replace it with

	kzalloc(SAFE_ARRAY_SIZE(x, y), ....)

?


--
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