From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
To: Kees Cook <kees@kernel.org>, Marco Elver <elver@google.com>
Cc: "Christoph Lameter (Ampere)" <cl@gentwo.org>,
Vlastimil Babka <vbabka@suse.cz>, Jann Horn <jannh@google.com>,
Tony Luck <tony.luck@intel.com>,
Nick Desaulniers <ndesaulniers@google.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Hao Luo <haoluo@google.com>, Pekka Enberg <penberg@kernel.org>,
David Rientjes <rientjes@google.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>,
Andrew Morton <akpm@linux-foundation.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Hyeonggon Yoo <42.hyeyoo@gmail.com>,
"Guilherme G. Piccoli" <gpiccoli@igalia.com>,
Mark Rutland <mark.rutland@arm.com>,
Jakub Kicinski <kuba@kernel.org>,
Petr Pavlu <petr.pavlu@suse.com>,
Alexander Lobakin <aleksander.lobakin@intel.com>,
Tony Ambardar <tony.ambardar@gmail.com>,
<linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
<linux-hardening@vger.kernel.org>
Subject: Re: [RFC][PATCH 0/4] slab: Allow for type introspection during allocation
Date: Wed, 10 Jul 2024 06:42:07 +0200 [thread overview]
Message-ID: <8327eb93-b378-4b98-9994-06640edf7e68@intel.com> (raw)
In-Reply-To: <202407091626.055933E3@keescook>
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@kernel.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;
prev parent reply other threads:[~2024-07-10 4:42 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-08 19:18 Kees Cook
2024-07-08 19:18 ` [RFC][PATCH 1/4] compiler_types: Add integral/pointer type helper macros Kees Cook
2024-07-08 19:18 ` [RFC][PATCH 2/4] slab: Detect negative size values and saturate Kees Cook
2024-07-09 6:57 ` Przemek Kitszel
2024-07-09 16:09 ` Kees Cook
2024-07-08 19:18 ` [RFC][PATCH 3/4] slab: Allow for type introspection during allocation Kees Cook
2024-07-08 19:18 ` [RFC][PATCH 4/4] pstore: Replace classic kmalloc code pattern with typed argument Kees Cook
2024-07-09 7:06 ` Przemek Kitszel
2024-07-09 16:32 ` Kees Cook
2024-07-09 16:57 ` [RFC][PATCH 0/4] slab: Allow for type introspection during allocation Roman Gushchin
2024-07-09 18:57 ` Kees Cook
2024-07-09 17:26 ` Christoph Lameter (Ampere)
2024-07-09 20:28 ` Kees Cook
2024-07-09 21:02 ` Marco Elver
2024-07-09 23:28 ` Kees Cook
2024-07-10 4:42 ` Przemek Kitszel [this message]
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=8327eb93-b378-4b98-9994-06640edf7e68@intel.com \
--to=przemyslaw.kitszel@intel.com \
--cc=42.hyeyoo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=aleksander.lobakin@intel.com \
--cc=cl@gentwo.org \
--cc=elver@google.com \
--cc=gpiccoli@igalia.com \
--cc=haoluo@google.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=jannh@google.com \
--cc=kees@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mark.rutland@arm.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=ojeda@kernel.org \
--cc=penberg@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=tony.ambardar@gmail.com \
--cc=tony.luck@intel.com \
--cc=vbabka@suse.cz \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®