linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mempool: Use kmalloc_size_roundup() to match ksize() usage
@ 2022-10-18  9:03 Kees Cook
  2022-10-18 22:51 ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Kees Cook @ 2022-10-18  9:03 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Kees Cook, linux-mm, linux-kernel, linux-hardening

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.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 mm/mempool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/mempool.c b/mm/mempool.c
index 96488b13a1ef..0f3107b28e6b 100644
--- a/mm/mempool.c
+++ b/mm/mempool.c
@@ -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);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] mempool: Use kmalloc_size_roundup() to match ksize() usage
  2022-10-18  9:03 [PATCH] mempool: Use kmalloc_size_roundup() to match ksize() usage Kees Cook
@ 2022-10-18 22:51 ` Andrew Morton
  2022-10-19  5:37   ` Kees Cook
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2022-10-18 22:51 UTC (permalink / raw)
  To: Kees Cook; +Cc: linux-mm, linux-kernel, linux-hardening

On Tue, 18 Oct 2022 02:03:29 -0700 Kees Cook <keescook@chromium.org> wrote:

> 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.

Confused.  If the special handling is not needed, why doesn't the patch
removed the no longer needed special handling?

> 
> diff --git a/mm/mempool.c b/mm/mempool.c
> index 96488b13a1ef..0f3107b28e6b 100644
> --- a/mm/mempool.c
> +++ b/mm/mempool.c
> @@ -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);
> -- 
> 2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mempool: Use kmalloc_size_roundup() to match ksize() usage
  2022-10-18 22:51 ` Andrew Morton
@ 2022-10-19  5:37   ` Kees Cook
  2022-10-24 18:03     ` Vlastimil Babka (SUSE)
  0 siblings, 1 reply; 5+ messages in thread
From: Kees Cook @ 2022-10-19  5:37 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel, linux-hardening

On Tue, Oct 18, 2022 at 03:51:37PM -0700, Andrew Morton wrote:
> On Tue, 18 Oct 2022 02:03:29 -0700 Kees Cook <keescook@chromium.org> wrote:
> 
> > 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.
> 
> 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/20220923202822.2667581-16-keescook@chromium.org/

-- 
Kees Cook


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mempool: Use kmalloc_size_roundup() to match ksize() usage
  2022-10-19  5:37   ` Kees Cook
@ 2022-10-24 18:03     ` Vlastimil Babka (SUSE)
  2022-10-25 22:55       ` Kees Cook
  0 siblings, 1 reply; 5+ messages in thread
From: Vlastimil Babka (SUSE) @ 2022-10-24 18:03 UTC (permalink / raw)
  To: Kees Cook, Andrew Morton; +Cc: linux-mm, linux-kernel, linux-hardening

On 10/19/22 07:37, Kees Cook wrote:
> On Tue, Oct 18, 2022 at 03:51:37PM -0700, Andrew Morton wrote:
>> On Tue, 18 Oct 2022 02:03:29 -0700 Kees Cook <keescook@chromium.org> wrote:
>> 
>> > 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.
>> 
>> 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/20220923202822.2667581-16-keescook@chromium.org/

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?

https://lore.kernel.org/all/f4fc52c4-7c18-1d76-0c7a-4058ea2486b9@suse.cz/




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mempool: Use kmalloc_size_roundup() to match ksize() usage
  2022-10-24 18:03     ` Vlastimil Babka (SUSE)
@ 2022-10-25 22:55       ` Kees Cook
  0 siblings, 0 replies; 5+ messages in thread
From: Kees Cook @ 2022-10-25 22:55 UTC (permalink / raw)
  To: Vlastimil Babka (SUSE)
  Cc: Andrew Morton, linux-mm, linux-kernel, linux-hardening

On Mon, Oct 24, 2022 at 08:03:34PM +0200, Vlastimil Babka (SUSE) wrote:
> On 10/19/22 07:37, Kees Cook wrote:
> > On Tue, Oct 18, 2022 at 03:51:37PM -0700, Andrew Morton wrote:
> >> On Tue, 18 Oct 2022 02:03:29 -0700 Kees Cook <keescook@chromium.org> wrote:
> >> 
> >> > 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.
> >> 
> >> 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/20220923202822.2667581-16-keescook@chromium.org/
> 
> 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?
> 
> https://lore.kernel.org/all/f4fc52c4-7c18-1d76-0c7a-4058ea2486b9@suse.cz/

Oops, yes. This failed to get on my TODO list. New version coming!

-- 
Kees Cook


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-25 22:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-18  9:03 [PATCH] mempool: Use kmalloc_size_roundup() to match ksize() usage Kees Cook
2022-10-18 22:51 ` Andrew Morton
2022-10-19  5:37   ` Kees Cook
2022-10-24 18:03     ` Vlastimil Babka (SUSE)
2022-10-25 22:55       ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).