Re: [PATCH] mm: Make ksize() a reporting-only function

From: Kees Cook
Date: Tue Oct 25 2022 - 14:38:14 EST


On Tue, Oct 25, 2022 at 01:53:54PM +0200, Vlastimil Babka wrote:
> On 10/22/22 20:08, Kees Cook wrote:
> > With all "silently resizing" callers of ksize() refactored, remove the
> > logic in ksize() that would allow it to be used to effectively change
> > the size of an allocation (bypassing __alloc_size hints, etc). Users
> > wanting this feature need to either use kmalloc_size_roundup() before an
> > allocation, or use krealloc() directly.
> >
> > For kfree_sensitive(), move the unpoisoning logic inline. Replace the
> > some of the partially open-coded ksize() in __do_krealloc with ksize()
> > now that it doesn't perform unpoisoning.
> >
> > [...]
> > Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx>
>
> Acked-by: Vlastimil Babka <vbabka@xxxxxxx>

Thanks!

> > ---
> > This requires at least this be landed first:
> > https://lore.kernel.org/lkml/20221021234713.you.031-kees@xxxxxxxxxx/
>
> Don't we need all parts to have landed first, even if the skbuff one is the
> most prominent?

Yes, though, I suspect there will be some cases we couldn't easily find.

Here are the prerequisites I'm aware of:

in -next:
36875a063b5e ("net: ipa: Proactively round up to kmalloc bucket size")
ab3f7828c979 ("openvswitch: Use kmalloc_size_roundup() to match ksize() usage")
d6dd508080a3 ("bnx2: Use kmalloc_size_roundup() to match ksize() usage")

reviewed, waiting to land (should I take these myself?)
btrfs: send: Proactively round up to kmalloc bucket size
https://lore.kernel.org/lkml/20220923202822.2667581-8-keescook@xxxxxxxxxxxx/
dma-buf: Proactively round up to kmalloc bucket size
https://lore.kernel.org/lkml/20221018090858.never.941-kees@xxxxxxxxxx/

partially reviewed:
igb: Proactively round up to kmalloc bucket size
https://lore.kernel.org/lkml/20221018092340.never.556-kees@xxxxxxxxxx/

unreviewed:
coredump: Proactively round up to kmalloc bucket size
https://lore.kernel.org/lkml/20221018090701.never.996-kees@xxxxxxxxxx/
devres: Use kmalloc_size_roundup() to match ksize() usage
https://lore.kernel.org/lkml/20221018090406.never.856-kees@xxxxxxxxxx/

needs updating:
mempool: Use kmalloc_size_roundup() to match ksize() usage
https://lore.kernel.org/lkml/20221018090323.never.897-kees@xxxxxxxxxx/
bpf: Use kmalloc_size_roundup() to match ksize() usage
https://lore.kernel.org/lkml/20221018090550.never.834-kees@xxxxxxxxxx/

--
Kees Cook