diff mbox series

selinux: remove unnecessary selinux cred request

Message ID 1576116144-55503-1-git-send-email-zhangshaokun@hisilicon.com (mailing list archive)
State Accepted
Headers show
Series selinux: remove unnecessary selinux cred request | expand

Commit Message

Shaokun Zhang Dec. 12, 2019, 2:02 a.m. UTC
From: Yang Guo <guoyang2@huawei.com>

task_security_struct was obtained at the beginning of may_create
and selinux_inode_init_security, no need to obtain again.
may_create will be called very frequently when create dir and file.

Cc: Paul Moore <paul@paul-moore.com>
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Cc: Eric Paris <eparis@parisplace.org>
Signed-off-by: Yang Guo <guoyang2@huawei.com>
Signed-off-by: Shaokun Zhang <zhangshaokun@hisilicon.com>
---
 security/selinux/hooks.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Paul Moore Dec. 12, 2019, 1:53 p.m. UTC | #1
On Wed, Dec 11, 2019 at 9:02 PM Shaokun Zhang
<zhangshaokun@hisilicon.com> wrote:
> From: Yang Guo <guoyang2@huawei.com>
>
> task_security_struct was obtained at the beginning of may_create
> and selinux_inode_init_security, no need to obtain again.
> may_create will be called very frequently when create dir and file.
>
> Cc: Paul Moore <paul@paul-moore.com>
> Cc: Stephen Smalley <sds@tycho.nsa.gov>
> Cc: Eric Paris <eparis@parisplace.org>
> Signed-off-by: Yang Guo <guoyang2@huawei.com>
> Signed-off-by: Shaokun Zhang <zhangshaokun@hisilicon.com>
> ---
>  security/selinux/hooks.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)

Merged into selinux/next, thanks.
Stephen Smalley Dec. 12, 2019, 1:53 p.m. UTC | #2
On 12/11/19 9:02 PM, Shaokun Zhang wrote:
> From: Yang Guo <guoyang2@huawei.com>
> 
> task_security_struct was obtained at the beginning of may_create
> and selinux_inode_init_security, no need to obtain again.
> may_create will be called very frequently when create dir and file.
> 
> Cc: Paul Moore <paul@paul-moore.com>
> Cc: Stephen Smalley <sds@tycho.nsa.gov>
> Cc: Eric Paris <eparis@parisplace.org>
> Signed-off-by: Yang Guo <guoyang2@huawei.com>
> Signed-off-by: Shaokun Zhang <zhangshaokun@hisilicon.com>

Reviewed-by: Stephen Smalley <sds@tycho.nsa.gov>

> ---
>   security/selinux/hooks.c | 7 +++----
>   1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index 116b4d644f68..64bc69426369 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -1833,8 +1833,8 @@ static int may_create(struct inode *dir,
>   	if (rc)
>   		return rc;
>   
> -	rc = selinux_determine_inode_label(selinux_cred(current_cred()), dir,
> -					   &dentry->d_name, tclass, &newsid);
> +	rc = selinux_determine_inode_label(tsec, dir, &dentry->d_name, tclass,
> +					   &newsid);
>   	if (rc)
>   		return rc;
>   
> @@ -2906,8 +2906,7 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir,
>   
>   	newsid = tsec->create_sid;
>   
> -	rc = selinux_determine_inode_label(selinux_cred(current_cred()),
> -		dir, qstr,
> +	rc = selinux_determine_inode_label(tsec, dir, qstr,
>   		inode_mode_to_security_class(inode->i_mode),
>   		&newsid);
>   	if (rc)
>
diff mbox series

Patch

diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 116b4d644f68..64bc69426369 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -1833,8 +1833,8 @@  static int may_create(struct inode *dir,
 	if (rc)
 		return rc;
 
-	rc = selinux_determine_inode_label(selinux_cred(current_cred()), dir,
-					   &dentry->d_name, tclass, &newsid);
+	rc = selinux_determine_inode_label(tsec, dir, &dentry->d_name, tclass,
+					   &newsid);
 	if (rc)
 		return rc;
 
@@ -2906,8 +2906,7 @@  static int selinux_inode_init_security(struct inode *inode, struct inode *dir,
 
 	newsid = tsec->create_sid;
 
-	rc = selinux_determine_inode_label(selinux_cred(current_cred()),
-		dir, qstr,
+	rc = selinux_determine_inode_label(tsec, dir, qstr,
 		inode_mode_to_security_class(inode->i_mode),
 		&newsid);
 	if (rc)