LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Kees Cook <keescook@google.com>
Cc: Matthew Wilcox <mawilcox@microsoft.com>,
Linux-MM <linux-mm@kvack.org>,
LKML <linux-kernel@vger.kernel.org>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>
Subject: Re: *alloc API changes
Date: Mon, 7 May 2018 04:39:02 -0700 [thread overview]
Message-ID: <20180507113902.GC18116@bombadil.infradead.org> (raw)
In-Reply-To: <CAGXu5jLbbts6Do5JtX8+fij0m=wEZ30W+k9PQAZ_ddOnpuPHZA@mail.gmail.com>
On Fri, May 04, 2018 at 09:24:56PM -0700, Kees Cook wrote:
> On Fri, May 4, 2018 at 8:46 PM, Matthew Wilcox <willy@infradead.org> wrote:
> The only fear I have with the saturating helpers is that we'll end up
> using them in places that don't recognize SIZE_MAX. Like, say:
>
> size = mul(a, b) + 1;
>
> then *poof* size == 0. Now, I'd hope that code would use add(mul(a,
> b), 1), but still... it makes me nervous.
That's reasonable. So let's add:
#define ALLOC_TOO_BIG (PAGE_SIZE << MAX_ORDER)
(there's a presumably somewhat obsolete CONFIG_FORCE_MAX_ZONEORDER on some
architectures which allows people to configure MAX_ORDER all the way up
to 64. That config option needs to go away, or at least be limited to
a much lower value).
On x86, that's 4k << 11 = 8MB. On PPC, that might be 64k << 9 == 32MB.
Those values should be relatively immune to further arithmetic causing
an additional overflow.
> Good point. Though it does kind of creep me out to let a known-bad
> size float around in the allocator until it decides to reject it. I
> would think an early:
>
> if (unlikely(size == SIZE_MAX))
> return NULL;
>
> would have virtually no cycle count difference...
I don't think it should go in the callers though ... where it goes in
the allocator is up to the allocator maintainers ;-)
> > I'd rather have a mul_ab(), mul_abc(), mul_ab_add_c(), etc. than nest
> > calls to mult().
>
> Agreed. I think having exactly those would cover almost everything,
> and the two places where a 4-factor product is needed could just nest
> them. (bikeshed: the very common mul_ab() should just be mul(), IMO.)
>
> > Nono, Linus had the better proposal, struct_size(p, member, n).
>
> Oh, yes! I totally missed that in the threads.
so we're agreed on struct_size(). I think rather than the explicit 'mul',
perhaps we should have array_size() and array3_size().
> Right, no. I think if we can ditch *calloc() and _array() by using
> saturating helpers, we'll have the API in a much better form:
>
> kmalloc(foo * bar, GFP_KERNEL);
> into
> kmalloc_array(foo, bar, GFP_KERNEL);
> into
> kmalloc(mul(foo, bar), GFP_KERNEL);
kmalloc(array_size(foo, bar), GFP_KERNEL);
> and the fun
>
> kzalloc(sizeof(*header) + count * sizeof(*header->element), GFP_KERNEL);
> into
> kzalloc(struct_size(header, element, count), GFP_KERNEL);
>
> modulo all *alloc* families...
>
> ?
I think we're broadly in agreement here!
next prev parent reply other threads:[~2018-05-07 11:39 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-05 1:08 Kees Cook
2018-05-05 3:46 ` Matthew Wilcox
2018-05-05 4:24 ` Kees Cook
2018-05-07 11:39 ` Matthew Wilcox [this message]
2018-05-07 16:03 ` Kees Cook
2018-05-07 20:19 ` Matthew Wilcox
2018-05-07 20:27 ` Kees Cook
2018-05-07 20:49 ` Matthew Wilcox
2018-05-07 21:15 ` Kees Cook
2018-05-07 21:48 ` John Johansen
2018-05-07 21:41 ` Rasmus Villemoes
2018-05-07 22:56 ` Kees Cook
2018-05-05 4:30 ` Matthew Wilcox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180507113902.GC18116@bombadil.infradead.org \
--to=willy@infradead.org \
--cc=keescook@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux@rasmusvillemoes.dk \
--cc=mawilcox@microsoft.com \
--subject='Re: *alloc API changes' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).