Skip to contentSkip to conversation

selinux: hooks: use kmalloc() to allocate path buffer

PATCH In review Mike Rapoport 3 participants 7 messages May 31 – Jul 1 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 selinux: hooks: use kmalloc() to allocate path buffer

From: "Mike Rapoport (Microsoft)" <[email protected]>

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.

---
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(-)
security/selinux/hooks.c +3 -3
index 0f704380a8c8..a2ebdd649016 100644
@@ -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;
 }
 
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 17 lines · Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

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.

---
v3:
get the args in the right order

Quoted 5 lines

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 ...

Signature · 1 line
paul-moore.com
#2 lore raw
Quoted 21 lines · Paul Moore
Quoted 20 lines · Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

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.

---
v3:
get the args in the right order

v2:
* explicitly use kmalloc() with PATH_MAX

Quoted 6 lines
Quoted 2 lines
 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.

Quoted 2 lines
Signature · 1 line
paul-moore.com
Signature · 2 lines
Sincerely yours,
Mike.
maintainer
#3 lore raw
Quoted 22 lines · Mike Rapoport
Quoted 21 lines · Paul Moore
Quoted 20 lines · Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

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.

---
v3:
get the args in the right order

v2:
* explicitly use kmalloc() with PATH_MAX

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
 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.

Signature · 1 line
paul-moore.com
#4 lore raw
Quoted 30 lines · Paul Moore
Quoted 29 lines · Mike Rapoport
Quoted 27 lines · Paul Moore
Quoted 17 lines · Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

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.

---
v3:
get the args in the right order

Quoted 5 lines

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 ...

Quoted 5 lines
Quoted 1 line

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 :)

Quoted 2 lines
Signature · 1 line
paul-moore.com
Signature · 2 lines
Sincerely yours,
Mike.
maintainer
#5 lore raw
In reply to Paul Moore
Quoted 30 lines · Paul Moore
Quoted 29 lines · Mike Rapoport
Quoted 27 lines · Paul Moore
Quoted 17 lines · Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

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.

---
v3:
get the args in the right order

Quoted 5 lines

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 ...

Quoted 5 lines
Quoted 1 line

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.

... and we are now there, merged into selinux/dev.

Signature · 1 line
paul-moore.com
maintainer Acked-by on v3 1/1
#6 lore raw
In reply to Mike Rapoport
Quoted 5 lines · Mike Rapoport

From: "Mike Rapoport (Microsoft)" <[email protected]>

selinux_genfs_get_sid() allocates memory for a path with __get_free_page().

Quoted 8 lines

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.