selinux: hooks: use kmalloc() to allocate path buffer
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
@@ -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
Paul Moore
maintainerQuoted 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_MAXwhich may be less thanPAGE_SIZEon some architectures.Replace
__get_free_page()for allocation of a path buffer withkmalloc()and make it explicit that the buffer size isPATH_MAX.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>---
v3:
get the args in the right order
Quoted 5 lines
v2:
* explicitly usekmalloc()withPATH_MAXsecurity/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
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_MAXwhich may be less thanPAGE_SIZEon some architectures.Replace
__get_free_page()for allocation of a path buffer withkmalloc()and make it explicit that the buffer size isPATH_MAX.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>---
v3:
get the args in the right orderv2:
* explicitly usekmalloc()withPATH_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.
Paul Moore
maintainerQuoted 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_MAXwhich may be less thanPAGE_SIZEon some architectures.Replace
__get_free_page()for allocation of a path buffer withkmalloc()and make it explicit that the buffer size isPATH_MAX.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>---
v3:
get the args in the right orderv2:
* explicitly usekmalloc()withPATH_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
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_MAXwhich may be less thanPAGE_SIZEon some architectures.Replace
__get_free_page()for allocation of a path buffer withkmalloc()and make it explicit that the buffer size isPATH_MAX.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>---
v3:
get the args in the right orderQuoted 5 lines
v2:
* explicitly usekmalloc()withPATH_MAXsecurity/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.
Paul Moore
maintainerQuoted 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_MAXwhich may be less thanPAGE_SIZEon some architectures.Replace
__get_free_page()for allocation of a path buffer withkmalloc()and make it explicit that the buffer size isPATH_MAX.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>---
v3:
get the args in the right orderQuoted 5 lines
v2:
* explicitly usekmalloc()withPATH_MAXsecurity/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
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_MAXwhich may be less thanPAGE_SIZEon some architectures.Replace
__get_free_page()for allocation of a path buffer withkmalloc()and make it explicit that the buffer size isPATH_MAX.Signed-off-by Mike Rapoport (Microsoft) <[email protected]>