[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <8327eb93-b378-4b98-9994-06640edf7e68@intel.com>
Date: Wed, 10 Jul 2024 06:42:07 +0200
From: Przemek Kitszel <przemyslaw.kitszel@...el.com>
To: Kees Cook <kees@...nel.org>, Marco Elver <elver@...gle.com>
CC: "Christoph Lameter (Ampere)" <cl@...two.org>, Vlastimil Babka
<vbabka@...e.cz>, Jann Horn <jannh@...gle.com>, Tony Luck
<tony.luck@...el.com>, Nick Desaulniers <ndesaulniers@...gle.com>, "Miguel
Ojeda" <ojeda@...nel.org>, Nathan Chancellor <nathan@...nel.org>, Hao Luo
<haoluo@...gle.com>, Pekka Enberg <penberg@...nel.org>, David Rientjes
<rientjes@...gle.com>, Joonsoo Kim <iamjoonsoo.kim@....com>, Andrew Morton
<akpm@...ux-foundation.org>, Roman Gushchin <roman.gushchin@...ux.dev>,
Hyeonggon Yoo <42.hyeyoo@...il.com>, "Guilherme G. Piccoli"
<gpiccoli@...lia.com>, Mark Rutland <mark.rutland@....com>, Jakub Kicinski
<kuba@...nel.org>, Petr Pavlu <petr.pavlu@...e.com>, Alexander Lobakin
<aleksander.lobakin@...el.com>, Tony Ambardar <tony.ambardar@...il.com>,
<linux-kernel@...r.kernel.org>, <linux-mm@...ck.org>,
<linux-hardening@...r.kernel.org>
Subject: Re: [RFC][PATCH 0/4] slab: Allow for type introspection during
allocation
On 7/10/24 01:28, Kees Cook wrote:
> On Tue, Jul 09, 2024 at 11:02:55PM +0200, Marco Elver wrote:
>> On Tue, 9 Jul 2024 at 22:28, Kees Cook <kees@...nel.org> wrote:
>>>
>>> On Tue, Jul 09, 2024 at 10:26:32AM -0700, Christoph Lameter (Ampere) wrote:
>>>> On Mon, 8 Jul 2024, Kees Cook wrote:
>>>>
>>>>>
>>>>> obj = kmalloc(obj, gfp);
>>>>
>>>> Could we avoid repeating "obj" in this pattern?
>>>>
>>>> F.e.
>>>>
>>>> KMALLOC(obj, gfp);
>>>
>>> This appears to be the common feedback, which is good! :) And we can
>>> still have it return "obj" as well, so it could still be used in
>>> "return" statements, etc. I will work up a new RFC...
>>
>> More macros like this only obfuscate the code further. The name would
>> become something that makes it really clear there's an assignment.
>>
>> assign_kmalloc(obj, gfp)
>>
>> There may be better options. Also ALLCAPS could be avoided here, as we
>> have done with other language-like features (vs. pure constants).
>
> So, in looking a code patterns, it seems what we really want more than
> returning the object that was allocated is actually returning the size
> of the allocation size requested. i.e.:
>
> info->size = struct_size(ptr, flex_member, count);
> info->obj = kmalloc(info->size, gfp);
>
> would become:
>
> info->size = kmalloc(info->obj, flex_member, count, gfp);
>
> -Kees
>
that will work out also for the (IMO) most common case of checking if
the allocation succeeded:
if (!kmalloc(my_foo, flex_part, count, gfp))
return -ENOMEM;
Powered by blists - more mailing lists