Skip to content

Commit df90f6c

Browse files
committed
slab: fix clearing freelist in free_deferred_objects()
defer_free() links pending objects using the slab's freelist offset which is fine as they are not free yet. free_deferred_objects() then clears this pointer to avoid confusing the debugging consistency checks that may be enabled for the cache. However, with CONFIG_SLAB_FREELIST_HARDENED, even the NULL pointer needs to be encoded appropriately using set_freepointer(), otherwise it's decoded as something else and triggers the consistency checks, as found by the kernel test robot. Use set_freepointer() to prevent the issue. Fixes: af92793 ("slab: Introduce kmalloc_nolock() and kfree_nolock().") Reported-and-tested-by: kernel test robot <oliver.sang@intel.com> Closes: https://lore.kernel.org/oe-lkp/202510101652.7921fdc6-lkp@intel.com Acked-by: Alexei Starovoitov <ast@kernel.org> Reviewed-by: Harry Yoo <harry.yoo@oracle.com> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
1 parent 3a86608 commit df90f6c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

mm/slub.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6443,15 +6443,16 @@ static void free_deferred_objects(struct irq_work *work)
64436443
slab = virt_to_slab(x);
64446444
s = slab->slab_cache;
64456445

6446+
/* Point 'x' back to the beginning of allocated object */
6447+
x -= s->offset;
6448+
64466449
/*
64476450
* We used freepointer in 'x' to link 'x' into df->objects.
64486451
* Clear it to NULL to avoid false positive detection
64496452
* of "Freepointer corruption".
64506453
*/
6451-
*(void **)x = NULL;
6454+
set_freepointer(s, x, NULL);
64526455

6453-
/* Point 'x' back to the beginning of allocated object */
6454-
x -= s->offset;
64556456
__slab_free(s, slab, x, x, 1, _THIS_IP_);
64566457
}
64576458

0 commit comments

Comments
 (0)