Re: [PATCH v2] selinux: hooks: use kmalloc() to allocate path buffer

From: Mike Rapoport

Date: Sun May 31 2026 - 12:55:38 EST


On Sun, May 31, 2026 at 05:18:11PM +0100, David Laight wrote:
> On Sun, 31 May 2026 18:15:02 +0300
> Mike Rapoport <rppt@xxxxxxxxxx> wrote:
>
> > From: "Mike Rapoport (Microsoft)" <rppt@xxxxxxxxxx>
> >
> > selinux_genfs_get_sid() allocates memory for a path with __get_free_page().
> >
> > Such usage does not require a "page" and the size of the buffer should
> > actually be PATH_MAX which may be less than PAGE_SIZE on some
> > architectures.
> >
> > Replace __get_free_page() for allocation of a path buffer with kmalloc()
> > and make it explicit that the buffer size is PATH_MAX.
> >
> > Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
> > ---
> > v2 changes:
> > * explicitly use kmalloc() with PATH_MAX
> >
> > security/selinux/hooks.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> > index 0f704380a8c8..19493198ece1 100644
> > --- a/security/selinux/hooks.c
> > +++ b/security/selinux/hooks.c
> > @@ -1336,11 +1336,11 @@ static int selinux_genfs_get_sid(struct dentry *dentry,
> > struct super_block *sb = dentry->d_sb;
> > char *buffer, *path;
> >
> > - buffer = (char *)__get_free_page(GFP_KERNEL);
> > + buffer = kmalloc(GFP_KERNEL, PATH_MAX);
>
> At least get the args in the right order.

oops


--
Sincerely yours,
Mike.