Re: [PATCH 1/2] debugobjects: Fix NULL pointer dereference in kmem_alloc_batch()

From: Andrew Morton

Date: Sun Nov 08 2026 - 23:56:11 EST


On Mon, 9 Nov 2026 13:12:10 +0900 Sang-Heon Jeon <ekffu200098@xxxxxxxxx> wrote:

> During boot, debug_objects_replace_static_objects() calls
> kmem_alloc_batch() while obj_cache is still NULL.
>
> If kmem_cache_zalloc() fails, kmem_alloc_batch() tries to free the
> allocated objects with free_object_list(). But free_object_list()
> always calls kmem_cache_free() with obj_cache, which causes a NULL
> pointer dereference.
>
> So use the cache passed to kmem_alloc_batch() instead.

Thanks.

We conventionally assume that memory allocations in __init code cannot
fail. Because if they do fail, something has already gone horribly
wrong with the kernel and it simply isn't viable. If an unchecked
allocation results in an oops then that's fine - it was inevitable
anyway.