Re: [PATCH] lkdtm: use kmalloc() instead of __get_free_page
From: Mike Rapoport
Date: Sun Jul 26 2026 - 03:06:15 EST
On Thu, Jul 23, 2026 at 09:45:22AM +0100, David Laight wrote:
> On Wed, 22 Jul 2026 23:02:46 +0000
> Mahad Ibrahim <mahad.ibrahim.dev@xxxxxxxxx> wrote:
>
> > lkdtm_debugfs_entry and direct_entry use __get_free_page to allocate a
> > temporary buffer, perform copy_from_user to get the crashtype name,
> > strim() to strip whitespace and find_crashtype to find the corresponding
> > crashtype that is being requested.
> >
> > The lkdtm_debugfs_read uses __get_free_page to allocate a temporary
> > buffer to store all the available crashtypes, and then copy it to
> > userspace.
> >
> > The buffers that are allocated can be allocated with kmalloc as there is
> > nothing special that requires a struct page, or the page allocator.
> >
> > kmalloc() additionally provides a better API that doesn't require ugly
> > casts which obfuscate the code and kfree does not need to know the size
> > of the freed object.
> >
> > Replace use of __get_free_page() with kmalloc().
>
> None of those buffers need to be PAGE_SIZE.
> Even the sanity limit for overlong requests could be 4k.
> The longest 'crashtype->name' is probably about 32 characters, so could
> probably go on stack.
As Arnd said, this is straightforward change, while changing actual
allocation size is more intrusive patch and you can send it if you think
it's worth the churn.
> And can't this code use the sysfs/kernfs wrappers?
>
> David
--
Sincerely yours,
Mike.