From: Rustam Kovhaev Date: Thu, 28 Apr 2022 19:39:00 +0000 (-0400) Subject: xfs: use kmem_cache_free() for kmem_cache objects X-Git-Tag: v5.16.0-rc0~39 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=76bbe2c2b8f7ef6fcc2ef00889aa1ecfe89351d5;p=thirdparty%2Fxfsprogs-dev.git xfs: use kmem_cache_free() for kmem_cache objects Source kernel commit c30a0cbd07ecc0eec7b3cd568f7b1c7bb7913f93 For kmalloc() allocations SLOB prepends the blocks with a 4-byte header, and it puts the size of the allocated blocks in that header. Blocks allocated with kmem_cache_alloc() allocations do not have that header. SLOB explodes when you allocate memory with kmem_cache_alloc() and then try to free it with kfree() instead of kmem_cache_free(). SLOB will assume that there is a header when there is none, read some garbage to size variable and corrupt the adjacent objects, which eventually leads to hang or panic. Let's make XFS work with SLOB by using proper free function. Fixes: 9749fee83f38 ("xfs: enable the xfs_defer mechanism to process extents to free") Signed-off-by: Rustam Kovhaev Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Eric Sandeen --- diff --git a/libxfs/defer_item.c b/libxfs/defer_item.c index b18182e95..a985f0280 100644 --- a/libxfs/defer_item.c +++ b/libxfs/defer_item.c @@ -82,7 +82,7 @@ xfs_extent_free_finish_item( error = xfs_free_extent(tp, free->xefi_startblock, free->xefi_blockcount, &free->xefi_oinfo, XFS_AG_RESV_NONE); - kmem_free(free); + kmem_cache_free(xfs_bmap_free_item_zone, free); return error; } @@ -101,7 +101,7 @@ xfs_extent_free_cancel_item( struct xfs_extent_free_item *free; free = container_of(item, struct xfs_extent_free_item, xefi_list); - kmem_free(free); + kmem_cache_free(xfs_bmap_free_item_zone, free); } const struct xfs_defer_op_type xfs_extent_free_defer_type = { @@ -139,7 +139,7 @@ xfs_agfl_free_finish_item( if (!error) error = xfs_free_agfl_block(tp, agno, agbno, agbp, &free->xefi_oinfo); - kmem_free(free); + kmem_cache_free(xfs_bmap_free_item_zone, free); return error; }