The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2] selinux: hooks: use kmalloc() to allocate path buffer
@ 2026-05-31 15:15 Mike Rapoport
  2026-05-31 16:18 ` David Laight
  0 siblings, 1 reply; 7+ messages in thread
From: Mike Rapoport @ 2026-05-31 15:15 UTC (permalink / raw)
  To: Paul Moore, Stephen Smalley
  Cc: David Laight, Mike Rapoport, Ondrej Mosnacek,
	Venkat Rao Bagalkote, selinux, linux-kernel

From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>

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@kernel.org>
---
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);
 	if (!buffer)
 		return -ENOMEM;
 
-	path = dentry_path_raw(dentry, buffer, PAGE_SIZE);
+	path = dentry_path_raw(dentry, buffer, PATH_MAX);
 	if (IS_ERR(path))
 		rc = PTR_ERR(path);
 	else {
@@ -1361,7 +1361,7 @@ static int selinux_genfs_get_sid(struct dentry *dentry,
 			rc = 0;
 		}
 	}
-	free_page((unsigned long)buffer);
+	kfree(buffer);
 	return rc;
 }
 
-- 
2.53.0


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

* Re: [PATCH v2] selinux: hooks: use kmalloc() to allocate path buffer
  2026-05-31 15:15 Mike Rapoport
@ 2026-05-31 16:18 ` David Laight
  2026-05-31 16:55   ` Mike Rapoport
  0 siblings, 1 reply; 7+ messages in thread
From: David Laight @ 2026-05-31 16:18 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Paul Moore, Stephen Smalley, Ondrej Mosnacek,
	Venkat Rao Bagalkote, selinux, linux-kernel

On Sun, 31 May 2026 18:15:02 +0300
Mike Rapoport <rppt@kernel.org> wrote:

> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> 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@kernel.org>
> ---
> 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.

>  	if (!buffer)
>  		return -ENOMEM;
>  
> -	path = dentry_path_raw(dentry, buffer, PAGE_SIZE);
> +	path = dentry_path_raw(dentry, buffer, PATH_MAX);
>  	if (IS_ERR(path))
>  		rc = PTR_ERR(path);
>  	else {
> @@ -1361,7 +1361,7 @@ static int selinux_genfs_get_sid(struct dentry *dentry,
>  			rc = 0;
>  		}
>  	}
> -	free_page((unsigned long)buffer);
> +	kfree(buffer);
>  	return rc;
>  }
>  


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

* Re: [PATCH v2] selinux: hooks: use kmalloc() to allocate path buffer
  2026-05-31 16:18 ` David Laight
@ 2026-05-31 16:55   ` Mike Rapoport
  0 siblings, 0 replies; 7+ messages in thread
From: Mike Rapoport @ 2026-05-31 16:55 UTC (permalink / raw)
  To: David Laight
  Cc: Paul Moore, Stephen Smalley, Ondrej Mosnacek,
	Venkat Rao Bagalkote, selinux, linux-kernel

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@kernel.org> wrote:
> 
> > From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> > 
> > 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@kernel.org>
> > ---
> > 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.

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

* [PATCH v2] selinux: hooks: use kmalloc() to allocate path buffer
@ 2026-06-30 10:15 Mike Rapoport (Microsoft)
  2026-06-30 10:23 ` Mike Rapoport
  0 siblings, 1 reply; 7+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-06-30 10:15 UTC (permalink / raw)
  To: Paul Moore, Stephen Smalley
  Cc: David Laight, Mike Rapoport, Ondrej Mosnacek, linux-kernel,
	linux-mm, selinux

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.

Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
This is a (tiny) part of larger work of replacing page allocator calls
with kmalloc:

Also in git:
https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git gfp-to-kmalloc/security
---
v4 changes:
* rebase on v7.2-rc1

v3: https://lore.kernel.org/all/20260531165852.1478916-1-rppt@kernel.org
* get the args in the right order

v2: https://lore.kernel.org/all/20260531151502.1467515-1-rppt@kernel.org
* 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 1a713d96206f..d1f089917a82 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(PATH_MAX, GFP_KERNEL);
 	if (!buffer)
 		return -ENOMEM;
 
-	path = dentry_path_raw(dentry, buffer, PAGE_SIZE);
+	path = dentry_path_raw(dentry, buffer, PATH_MAX);
 	if (IS_ERR(path))
 		rc = PTR_ERR(path);
 	else {
@@ -1361,7 +1361,7 @@ static int selinux_genfs_get_sid(struct dentry *dentry,
 			rc = 0;
 		}
 	}
-	free_page((unsigned long)buffer);
+	kfree(buffer);
 	return rc;
 }
 

---
base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
change-id: 20260520-security-6cdd60da7129

Best regards,
--  
Sincerely yours,
Mike.


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

* Re: [PATCH v2] selinux: hooks: use kmalloc() to allocate path buffer
  2026-06-30 10:15 [PATCH v2] selinux: hooks: use kmalloc() to allocate path buffer Mike Rapoport (Microsoft)
@ 2026-06-30 10:23 ` Mike Rapoport
  2026-07-01  1:01   ` Paul Moore
  0 siblings, 1 reply; 7+ messages in thread
From: Mike Rapoport @ 2026-06-30 10:23 UTC (permalink / raw)
  To: Paul Moore, Stephen Smalley
  Cc: David Laight, Ondrej Mosnacek, linux-kernel, linux-mm, selinux

Should have been:

Subject: [PATCH v4] selinux: hooks: use kmalloc() to allocate path buffer

On Tue, Jun 30, 2026 at 01:15:24PM +0300, Mike Rapoport (Microsoft) wrote:
> 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.
> 
> Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> This is a (tiny) part of larger work of replacing page allocator calls
> with kmalloc:
> 
> Also in git:
> https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git gfp-to-kmalloc/security
> ---
> v4 changes:
> * rebase on v7.2-rc1
> 
> v3: https://lore.kernel.org/all/20260531165852.1478916-1-rppt@kernel.org
> * get the args in the right order
> 
> v2: https://lore.kernel.org/all/20260531151502.1467515-1-rppt@kernel.org
> * 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 1a713d96206f..d1f089917a82 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(PATH_MAX, GFP_KERNEL);
>  	if (!buffer)
>  		return -ENOMEM;
>  
> -	path = dentry_path_raw(dentry, buffer, PAGE_SIZE);
> +	path = dentry_path_raw(dentry, buffer, PATH_MAX);
>  	if (IS_ERR(path))
>  		rc = PTR_ERR(path);
>  	else {
> @@ -1361,7 +1361,7 @@ static int selinux_genfs_get_sid(struct dentry *dentry,
>  			rc = 0;
>  		}
>  	}
> -	free_page((unsigned long)buffer);
> +	kfree(buffer);
>  	return rc;
>  }
>  
> 
> ---
> base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
> change-id: 20260520-security-6cdd60da7129
> 
> Best regards,
> --  
> Sincerely yours,
> Mike.
> 

-- 
Sincerely yours,
Mike.

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

* Re: [PATCH v2] selinux: hooks: use kmalloc() to allocate path buffer
  2026-06-30 10:23 ` Mike Rapoport
@ 2026-07-01  1:01   ` Paul Moore
  2026-07-01  6:28     ` Mike Rapoport
  0 siblings, 1 reply; 7+ messages in thread
From: Paul Moore @ 2026-07-01  1:01 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Stephen Smalley, David Laight, Ondrej Mosnacek, linux-kernel,
	linux-mm, selinux

On Tue, Jun 30, 2026 at 6:23 AM Mike Rapoport <rppt@kernel.org> wrote:
>
> Should have been:
>
> Subject: [PATCH v4] selinux: hooks: use kmalloc() to allocate path buffer

No worries, I just merged the v3 patchset, it applied cleanly.

> On Tue, Jun 30, 2026 at 01:15:24PM +0300, Mike Rapoport (Microsoft) wrote:
> > 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.
> >
> > Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
> > Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> > ---
> > This is a (tiny) part of larger work of replacing page allocator calls
> > with kmalloc:
> >
> > Also in git:
> > https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git gfp-to-kmalloc/security
> > ---
> > v4 changes:
> > * rebase on v7.2-rc1
> >
> > v3: https://lore.kernel.org/all/20260531165852.1478916-1-rppt@kernel.org
> > * get the args in the right order
> >
> > v2: https://lore.kernel.org/all/20260531151502.1467515-1-rppt@kernel.org
> > * 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 1a713d96206f..d1f089917a82 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(PATH_MAX, GFP_KERNEL);
> >       if (!buffer)
> >               return -ENOMEM;
> >
> > -     path = dentry_path_raw(dentry, buffer, PAGE_SIZE);
> > +     path = dentry_path_raw(dentry, buffer, PATH_MAX);
> >       if (IS_ERR(path))
> >               rc = PTR_ERR(path);
> >       else {
> > @@ -1361,7 +1361,7 @@ static int selinux_genfs_get_sid(struct dentry *dentry,
> >                       rc = 0;
> >               }
> >       }
> > -     free_page((unsigned long)buffer);
> > +     kfree(buffer);
> >       return rc;
> >  }
> >
> >
> > ---
> > base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
> > change-id: 20260520-security-6cdd60da7129
> >
> > Best regards,
> > --
> > Sincerely yours,
> > Mike.
> >
>
> --
> Sincerely yours,
> Mike.



-- 
paul-moore.com

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

* Re: [PATCH v2] selinux: hooks: use kmalloc() to allocate path buffer
  2026-07-01  1:01   ` Paul Moore
@ 2026-07-01  6:28     ` Mike Rapoport
  0 siblings, 0 replies; 7+ messages in thread
From: Mike Rapoport @ 2026-07-01  6:28 UTC (permalink / raw)
  To: Paul Moore
  Cc: Stephen Smalley, David Laight, Ondrej Mosnacek, linux-kernel,
	linux-mm, selinux

On Tue, Jun 30, 2026 at 09:01:08PM -0400, Paul Moore wrote:
> On Tue, Jun 30, 2026 at 6:23 AM Mike Rapoport <rppt@kernel.org> wrote:
> >
> > Should have been:
> >
> > Subject: [PATCH v4] selinux: hooks: use kmalloc() to allocate path buffer
> 
> No worries, I just merged the v3 patchset, it applied cleanly.

Thanks, Paul! 

-- 
Sincerely yours,
Mike.

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

end of thread, other threads:[~2026-07-01  6:29 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-30 10:15 [PATCH v2] selinux: hooks: use kmalloc() to allocate path buffer Mike Rapoport (Microsoft)
2026-06-30 10:23 ` Mike Rapoport
2026-07-01  1:01   ` Paul Moore
2026-07-01  6:28     ` Mike Rapoport
  -- strict thread matches above, loose matches on Subject: below --
2026-05-31 15:15 Mike Rapoport
2026-05-31 16:18 ` David Laight
2026-05-31 16:55   ` Mike Rapoport

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox