mempool: Use kmalloc_size_roundup() to match ksize() usage
Subsystems (2)
PATCH 1/1 mempool: Use kmalloc_size_roundup() to match ksize() usage
Round up allocations with kmalloc_size_roundup() so that mempool's use of ksize() is always accurate and no special handling of the memory is needed by KASAN, UBSAN_BOUNDS, nor FORTIFY_SOURCE.
--- mm/mempool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/mempool.c +1 -1
@@ -526,7 +526,7 @@ EXPORT_SYMBOL(mempool_free_slab);*/ void *mempool_kmalloc (gfp_t gfp_mask,void *pool_data) { -size_t size = (size_t )pool_data; +size_t size =kmalloc_size_roundup ((size_t )pool_data);return kmalloc (size, gfp_mask); }EXPORT_SYMBOL (mempool_kmalloc);
Signature · 1 line
2.34.1
Andrew Morton
maintainerQuoted 3 lines · On Tue, 18 Oct 2022 02:03:29 -0700 Kees Cook <[email protected]> wrote:
Round up allocations with
kmalloc_size_roundup()so that mempool's use ofksize()is always accurate and no special handling of the memory is needed by KASAN,UBSAN_BOUNDS, norFORTIFY_SOURCE.
Confused. If the special handling is not needed, why doesn't the patch removed the no longer needed special handling?
Quoted 16 lines
mm/mempool.c +1
-1@@ -526,7 +526,7 @@ EXPORT_SYMBOL(mempool_free_slab);*/ void *mempool_kmalloc (gfp_t gfp_mask,void *pool_data) { -size_t size = (size_t )pool_data; +size_t size =kmalloc_size_roundup ((size_t )pool_data);return kmalloc (size, gfp_mask); }EXPORT_SYMBOL (mempool_kmalloc);Signature · 1 line
2.34.1
Quoted 8 lines · Andrew Morton
Quoted 3 lines · On Tue, 18 Oct 2022 02:03:29 -0700 Kees Cook <[email protected]> wrote:
Round up allocations with
kmalloc_size_roundup()so that mempool's use ofksize()is always accurate and no special handling of the memory is needed by KASAN,UBSAN_BOUNDS, norFORTIFY_SOURCE.Confused. If the special handling is not needed, why doesn't the patch removed the no longer needed special handling?
The special handling is in the ksize() implementation, so it can't be removed[1] until all the ksize()-affected users are updated to see their true allocation sizes first.
[1] https://lore.kernel.org/lkml/[email protected]/
Signature · 1 line
Kees Cook
Vlastimil Babka (SUSE)
maintainerQuoted 7 lines · Kees Cook
Quoted 6 lines · Andrew Morton
Quoted 3 lines · On Tue, 18 Oct 2022 02:03:29 -0700 Kees Cook <[email protected]> wrote:
Round up allocations with
kmalloc_size_roundup()so that mempool's use ofksize()is always accurate and no special handling of the memory is needed by KASAN,UBSAN_BOUNDS, norFORTIFY_SOURCE.
Quoted 8 lines
Quoted 2 lines
Confused. If the special handling is not needed, why doesn't the patch removed the no longer needed special handling?
The special handling is in the
ksize()implementation, so it can't be removed[1] until all the ksize()-affected users are updated to see their true allocation sizes first.
But in the previous version I was wondering if we can just stop doing ksize()-like poison handling in mempool completely, if no mempool consumers call ksize() to expand their use of the allocated objects. You seemed to agree but this version is uncahnged?
Quoted 15 lines · Vlastimil Babka (SUSE)
Quoted 14 lines · Kees Cook
Quoted 8 lines · Andrew Morton
Quoted 3 lines · On Tue, 18 Oct 2022 02:03:29 -0700 Kees Cook <[email protected]> wrote:
Round up allocations with
kmalloc_size_roundup()so that mempool's use ofksize()is always accurate and no special handling of the memory is needed by KASAN,UBSAN_BOUNDS, norFORTIFY_SOURCE.Confused. If the special handling is not needed, why doesn't the patch removed the no longer needed special handling?
The special handling is in the
ksize()implementation, so it can't be removed[1] until all the ksize()-affected users are updated to see their true allocation sizes first.
Quoted 8 lines
Quoted 1 line
But in the previous version I was wondering if we can just stop doing ksize()-like poison handling in mempool completely, if no mempool consumers call
ksize()to expand their use of the allocated objects. You seemed to agree but this version is uncahnged?
Oops, yes. This failed to get on my TODO list. New version coming!
Signature · 1 line
Kees Cook