The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v3] selinux: hooks: use kmalloc() to allocate path buffer
@ 2026-05-31 16:58 Mike Rapoport
  2026-06-01 18:11 ` Paul Moore
  2026-06-02 13:51 ` Stephen Smalley
  0 siblings, 2 replies; 6+ messages in thread
From: Mike Rapoport @ 2026-05-31 16:58 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>
---
v3:
get the args in the right order

v2:
* 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..a2ebdd649016 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;
 }
 
-- 
2.53.0


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

* Re: [PATCH v3] selinux: hooks: use kmalloc() to allocate path buffer
  2026-05-31 16:58 [PATCH v3] selinux: hooks: use kmalloc() to allocate path buffer Mike Rapoport
@ 2026-06-01 18:11 ` Paul Moore
  2026-06-02 10:20   ` Mike Rapoport
  2026-06-02 13:51 ` Stephen Smalley
  1 sibling, 1 reply; 6+ messages in thread
From: Paul Moore @ 2026-06-01 18:11 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Stephen Smalley, David Laight, Ondrej Mosnacek,
	Venkat Rao Bagalkote, selinux, linux-kernel

On Sun, May 31, 2026 at 12:58 PM 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>
> ---
> v3:
> get the args in the right order
>
> v2:
> * explicitly use kmalloc() with PATH_MAX
>
>  security/selinux/hooks.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Considering the problems with the first two versions of this patch I
have to ask what sort of testing you've done on this?  I know it's a
trivial patch, but we're on v3 ...

-- 
paul-moore.com

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

* Re: [PATCH v3] selinux: hooks: use kmalloc() to allocate path buffer
  2026-06-01 18:11 ` Paul Moore
@ 2026-06-02 10:20   ` Mike Rapoport
  2026-06-03 16:08     ` Paul Moore
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Rapoport @ 2026-06-02 10:20 UTC (permalink / raw)
  To: Paul Moore
  Cc: Stephen Smalley, David Laight, Ondrej Mosnacek,
	Venkat Rao Bagalkote, selinux, linux-kernel

On Mon, Jun 01, 2026 at 02:11:11PM -0400, Paul Moore wrote:
> On Sun, May 31, 2026 at 12:58 PM 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>
> > ---
> > v3:
> > get the args in the right order
> >
> > v2:
> > * explicitly use kmalloc() with PATH_MAX
> >
> >  security/selinux/hooks.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> Considering the problems with the first two versions of this patch I
> have to ask what sort of testing you've done on this?  I know it's a
> trivial patch, but we're on v3 ...

Boot of fedora on an arm64 VM with 64K page size kernel.
 
> -- 
> paul-moore.com

-- 
Sincerely yours,
Mike.

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

* Re: [PATCH v3] selinux: hooks: use kmalloc() to allocate path buffer
  2026-05-31 16:58 [PATCH v3] selinux: hooks: use kmalloc() to allocate path buffer Mike Rapoport
  2026-06-01 18:11 ` Paul Moore
@ 2026-06-02 13:51 ` Stephen Smalley
  1 sibling, 0 replies; 6+ messages in thread
From: Stephen Smalley @ 2026-06-02 13:51 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Paul Moore, David Laight, Ondrej Mosnacek, Venkat Rao Bagalkote,
	selinux, linux-kernel

On Sun, May 31, 2026 at 12:58 PM 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>

Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>

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

* Re: [PATCH v3] selinux: hooks: use kmalloc() to allocate path buffer
  2026-06-02 10:20   ` Mike Rapoport
@ 2026-06-03 16:08     ` Paul Moore
  2026-06-04  5:29       ` Mike Rapoport
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Moore @ 2026-06-03 16:08 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Stephen Smalley, David Laight, Ondrej Mosnacek,
	Venkat Rao Bagalkote, selinux, linux-kernel

On Tue, Jun 2, 2026 at 6:20 AM Mike Rapoport <rppt@kernel.org> wrote:
> On Mon, Jun 01, 2026 at 02:11:11PM -0400, Paul Moore wrote:
> > On Sun, May 31, 2026 at 12:58 PM 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>
> > > ---
> > > v3:
> > > get the args in the right order
> > >
> > > v2:
> > > * explicitly use kmalloc() with PATH_MAX
> > >
> > >  security/selinux/hooks.c | 6 +++---
> > >  1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > Considering the problems with the first two versions of this patch I
> > have to ask what sort of testing you've done on this?  I know it's a
> > trivial patch, but we're on v3 ...
>
> Boot of fedora on an arm64 VM with 64K page size kernel.

Given the minimal testing, the problems with the previous versions,
and the fact that we are at -rc6, I'm going to hold this for the next
dev cycle.

-- 
paul-moore.com

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

* Re: [PATCH v3] selinux: hooks: use kmalloc() to allocate path buffer
  2026-06-03 16:08     ` Paul Moore
@ 2026-06-04  5:29       ` Mike Rapoport
  0 siblings, 0 replies; 6+ messages in thread
From: Mike Rapoport @ 2026-06-04  5:29 UTC (permalink / raw)
  To: Paul Moore
  Cc: Stephen Smalley, David Laight, Ondrej Mosnacek,
	Venkat Rao Bagalkote, selinux, linux-kernel

On Wed, Jun 03, 2026 at 12:08:04PM -0400, Paul Moore wrote:
> On Tue, Jun 2, 2026 at 6:20 AM Mike Rapoport <rppt@kernel.org> wrote:
> > On Mon, Jun 01, 2026 at 02:11:11PM -0400, Paul Moore wrote:
> > > On Sun, May 31, 2026 at 12:58 PM 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>
> > > > ---
> > > > v3:
> > > > get the args in the right order
> > > >
> > > > v2:
> > > > * explicitly use kmalloc() with PATH_MAX
> > > >
> > > >  security/selinux/hooks.c | 6 +++---
> > > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > >
> > > Considering the problems with the first two versions of this patch I
> > > have to ask what sort of testing you've done on this?  I know it's a
> > > trivial patch, but we're on v3 ...
> >
> > Boot of fedora on an arm64 VM with 64K page size kernel.
> 
> Given the minimal testing, the problems with the previous versions,
> and the fact that we are at -rc6, I'm going to hold this for the next
> dev cycle.

Fair enough :)
 
> -- 
> paul-moore.com

-- 
Sincerely yours,
Mike.

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

end of thread, other threads:[~2026-06-04  5:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-31 16:58 [PATCH v3] selinux: hooks: use kmalloc() to allocate path buffer Mike Rapoport
2026-06-01 18:11 ` Paul Moore
2026-06-02 10:20   ` Mike Rapoport
2026-06-03 16:08     ` Paul Moore
2026-06-04  5:29       ` Mike Rapoport
2026-06-02 13:51 ` Stephen Smalley

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