|
Message-ID: <CAGXu5jKXq7--CYgp8Q+k00RjjGJY+o71RMr51NPuWS1eM0KX1w@mail.gmail.com> Date: Wed, 9 May 2018 10:01:41 -0700 From: Kees Cook <keescook@...omium.org> To: Laura Abbott <labbott@...hat.com> Cc: Matthew Wilcox <mawilcox@...rosoft.com>, Rasmus Villemoes <linux@...musvillemoes.dk>, LKML <linux-kernel@...r.kernel.org>, Linux-MM <linux-mm@...ck.org>, Kernel Hardening <kernel-hardening@...ts.openwall.com> Subject: Re: [RFC][PATCH 00/13] Provide saturating helpers for allocation On Wed, May 9, 2018 at 9:08 AM, Laura Abbott <labbott@...hat.com> wrote: > On 05/08/2018 05:42 PM, Kees Cook wrote: >> >> This is a stab at providing three new helpers for allocation size >> calculation: >> >> struct_size(), array_size(), and array3_size(). >> >> These are implemented on top of Rasmus's overflow checking functions, >> and the last 8 patches are all treewide conversions of open-coded >> multiplications into the various combinations of the helper functions. >> >> -Kees >> >> > Obvious question (that might indicate this deserves documentation?) > > What's the difference between > > kmalloc_array(cnt, sizeof(struct blah), GFP_KERNEL); > > and > > kmalloc(array_size(cnt, struct blah), GFP_KERNEL); > > > and when would you use one over the other? If I'm understanding the intentions here, the next set of treewide changes would be to remove *calloc() and *_array() in favor of using the array_size() helper. (i.e. reducing proliferation of allocator helpers in favor of using the *_size() helpers. There are, however, some cases that don't map well to {struct,array,array3}_size(), specifically cases of additions in finding a count. For example, stuff like: kmalloc(sizeof(header) + sizeof(trailing_array) * (count + SOMETHING), gfp...) This gets currently mapped to: kmalloc(struct_size(header, trailing_array, (count + SOMETHING), gfp...) But we run the risk in some cases of having even the addition overflow. I think we need to have a "saturating add" too. Something like: kmalloc(struct_size(header, trailing_array, sat_add(count, SOMETHING), gfp...) It's a bit ugly, but it would cover nearly all the remaining cases... -Kees -- Kees Cook Pixel Security
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.