On Fri, May 24, 2024 at 03:38:58PM +0200, Vlastimil Babka wrote: > On 4/24/24 11:40 PM, Kees Cook wrote: > > To be able to choose which buckets to allocate from, make the buckets > > available to the lower level kmalloc interfaces by adding them as the > > first argument. Where the bucket is not available, pass NULL, which means > > "use the default system kmalloc bucket set" (the prior existing behavior), > > as implemented in kmalloc_slab(). > > > > Signed-off-by: Kees Cook <keesc...@chromium.org> > > --- > > Cc: Vlastimil Babka <vba...@suse.cz> > > Cc: Christoph Lameter <c...@linux.com> > > Cc: Pekka Enberg <penb...@kernel.org> > > Cc: David Rientjes <rient...@google.com> > > Cc: Joonsoo Kim <iamjoonsoo....@lge.com> > > Cc: Andrew Morton <a...@linux-foundation.org> > > Cc: Roman Gushchin <roman.gushc...@linux.dev> > > Cc: Hyeonggon Yoo <42.hye...@gmail.com> > > Cc: linux...@kvack.org > > Cc: linux-hardening@vger.kernel.org > > --- > > include/linux/slab.h | 16 ++++++++-------- > > lib/fortify_kunit.c | 2 +- > > mm/slab.h | 6 ++++-- > > mm/slab_common.c | 4 ++-- > > mm/slub.c | 14 +++++++------- > > mm/util.c | 2 +- > > 6 files changed, 23 insertions(+), 21 deletions(-) > > > > diff --git a/include/linux/slab.h b/include/linux/slab.h > > index c8164d5db420..07373b680894 100644 > > --- a/include/linux/slab.h > > +++ b/include/linux/slab.h > > @@ -569,8 +569,8 @@ static __always_inline void kfree_bulk(size_t size, > > void **p) > > kmem_cache_free_bulk(NULL, size, p); > > } > > > > -void *__kmalloc_node_noprof(size_t size, gfp_t flags, int node) > > __assume_kmalloc_alignment > > - __alloc_size(1); > > +void *__kmalloc_node_noprof(kmem_buckets *b, size_t size, gfp_t flags, int > > node) > > + __assume_kmalloc_alignment __alloc_size(2); > > #define __kmalloc_node(...) > > alloc_hooks(__kmalloc_node_noprof(__VA_ARGS__)) > > > > void *kmem_cache_alloc_node_noprof(struct kmem_cache *s, gfp_t flags, > > @@ -679,7 +679,7 @@ static __always_inline __alloc_size(1) void > > *kmalloc_node_noprof(size_t size, gf > > kmalloc_caches[kmalloc_type(flags, > > _RET_IP_)][index], > > flags, node, size); > > } > > - return __kmalloc_node_noprof(size, flags, node); > > + return __kmalloc_node_noprof(NULL, size, flags, node); > > This is not ideal as now every kmalloc_node() callsite will now have to add > the NULL parameter even if this is not enabled. Could the new parameter be > only added depending on the respective config?
I felt like it was much simpler to add an argument to the existing call path than to create a duplicate API that had 1 extra argument. However, if you want this behind a Kconfig option, I can redefine the argument list based on that? -- Kees Cook