* [PATCH] devcgroup: skip superfluous checks when found the DEV_ALL elem
@ 2009-04-07 5:47 Li Zefan
2009-04-08 2:55 ` Serge E. Hallyn
2009-04-10 0:06 ` Andrew Morton
0 siblings, 2 replies; 4+ messages in thread
From: Li Zefan @ 2009-04-07 5:47 UTC (permalink / raw)
To: Andrew Morton; +Cc: Serge E. Hallyn, LKML, Linux Containers
While walking through the whitelist, if the DEV_ALL item is found,
no more check is needed.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
security/device_cgroup.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/security/device_cgroup.c b/security/device_cgroup.c
index 5fda7df..b8186ba 100644
--- a/security/device_cgroup.c
+++ b/security/device_cgroup.c
@@ -490,7 +490,7 @@ int devcgroup_inode_permission(struct inode *inode, int mask)
list_for_each_entry_rcu(wh, &dev_cgroup->whitelist, list) {
if (wh->type & DEV_ALL)
- goto acc_check;
+ goto found;
if ((wh->type & DEV_BLOCK) && !S_ISBLK(inode->i_mode))
continue;
if ((wh->type & DEV_CHAR) && !S_ISCHR(inode->i_mode))
@@ -499,11 +499,12 @@ int devcgroup_inode_permission(struct inode *inode, int mask)
continue;
if (wh->minor != ~0 && wh->minor != iminor(inode))
continue;
-acc_check:
+
if ((mask & MAY_WRITE) && !(wh->access & ACC_WRITE))
continue;
if ((mask & MAY_READ) && !(wh->access & ACC_READ))
continue;
+found:
rcu_read_unlock();
return 0;
}
@@ -527,7 +528,7 @@ int devcgroup_inode_mknod(int mode, dev_t dev)
list_for_each_entry_rcu(wh, &dev_cgroup->whitelist, list) {
if (wh->type & DEV_ALL)
- goto acc_check;
+ goto found;
if ((wh->type & DEV_BLOCK) && !S_ISBLK(mode))
continue;
if ((wh->type & DEV_CHAR) && !S_ISCHR(mode))
@@ -536,9 +537,10 @@ int devcgroup_inode_mknod(int mode, dev_t dev)
continue;
if (wh->minor != ~0 && wh->minor != MINOR(dev))
continue;
-acc_check:
+
if (!(wh->access & ACC_MKNOD))
continue;
+found:
rcu_read_unlock();
return 0;
}
--
1.5.4.rc3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] devcgroup: skip superfluous checks when found the DEV_ALL elem
2009-04-07 5:47 [PATCH] devcgroup: skip superfluous checks when found the DEV_ALL elem Li Zefan
@ 2009-04-08 2:55 ` Serge E. Hallyn
2009-04-10 0:06 ` Andrew Morton
1 sibling, 0 replies; 4+ messages in thread
From: Serge E. Hallyn @ 2009-04-08 2:55 UTC (permalink / raw)
To: Li Zefan; +Cc: Andrew Morton, LKML, Linux Containers
Quoting Li Zefan (lizf@cn.fujitsu.com):
> While walking through the whitelist, if the DEV_ALL item is found,
> no more check is needed.
Right, because the DEV_ALL item always has all permissions.
> Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Serge Hallyn <serue@us.ibm.com>
thanks,
-serge
> ---
> security/device_cgroup.c | 10 ++++++----
> 1 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/security/device_cgroup.c b/security/device_cgroup.c
> index 5fda7df..b8186ba 100644
> --- a/security/device_cgroup.c
> +++ b/security/device_cgroup.c
> @@ -490,7 +490,7 @@ int devcgroup_inode_permission(struct inode *inode, int mask)
>
> list_for_each_entry_rcu(wh, &dev_cgroup->whitelist, list) {
> if (wh->type & DEV_ALL)
> - goto acc_check;
> + goto found;
> if ((wh->type & DEV_BLOCK) && !S_ISBLK(inode->i_mode))
> continue;
> if ((wh->type & DEV_CHAR) && !S_ISCHR(inode->i_mode))
> @@ -499,11 +499,12 @@ int devcgroup_inode_permission(struct inode *inode, int mask)
> continue;
> if (wh->minor != ~0 && wh->minor != iminor(inode))
> continue;
> -acc_check:
> +
> if ((mask & MAY_WRITE) && !(wh->access & ACC_WRITE))
> continue;
> if ((mask & MAY_READ) && !(wh->access & ACC_READ))
> continue;
> +found:
> rcu_read_unlock();
> return 0;
> }
> @@ -527,7 +528,7 @@ int devcgroup_inode_mknod(int mode, dev_t dev)
>
> list_for_each_entry_rcu(wh, &dev_cgroup->whitelist, list) {
> if (wh->type & DEV_ALL)
> - goto acc_check;
> + goto found;
> if ((wh->type & DEV_BLOCK) && !S_ISBLK(mode))
> continue;
> if ((wh->type & DEV_CHAR) && !S_ISCHR(mode))
> @@ -536,9 +537,10 @@ int devcgroup_inode_mknod(int mode, dev_t dev)
> continue;
> if (wh->minor != ~0 && wh->minor != MINOR(dev))
> continue;
> -acc_check:
> +
> if (!(wh->access & ACC_MKNOD))
> continue;
> +found:
> rcu_read_unlock();
> return 0;
> }
> --
> 1.5.4.rc3
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] devcgroup: skip superfluous checks when found the DEV_ALL elem
2009-04-07 5:47 [PATCH] devcgroup: skip superfluous checks when found the DEV_ALL elem Li Zefan
2009-04-08 2:55 ` Serge E. Hallyn
@ 2009-04-10 0:06 ` Andrew Morton
2009-04-10 0:20 ` Li Zefan
1 sibling, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2009-04-10 0:06 UTC (permalink / raw)
To: Li Zefan; +Cc: serue, linux-kernel, containers
On Tue, 07 Apr 2009 13:47:16 +0800
Li Zefan <lizf@cn.fujitsu.com> wrote:
> While walking through the whitelist, if the DEV_ALL item is found,
> no more check is needed.
>
It's unobvious whether this is a behavioural change, a bugfix or just a
speedup?
>
> diff --git a/security/device_cgroup.c b/security/device_cgroup.c
> index 5fda7df..b8186ba 100644
> --- a/security/device_cgroup.c
> +++ b/security/device_cgroup.c
> @@ -490,7 +490,7 @@ int devcgroup_inode_permission(struct inode *inode, int mask)
>
> list_for_each_entry_rcu(wh, &dev_cgroup->whitelist, list) {
> if (wh->type & DEV_ALL)
> - goto acc_check;
> + goto found;
> if ((wh->type & DEV_BLOCK) && !S_ISBLK(inode->i_mode))
> continue;
> if ((wh->type & DEV_CHAR) && !S_ISCHR(inode->i_mode))
> @@ -499,11 +499,12 @@ int devcgroup_inode_permission(struct inode *inode, int mask)
> continue;
> if (wh->minor != ~0 && wh->minor != iminor(inode))
> continue;
> -acc_check:
> +
> if ((mask & MAY_WRITE) && !(wh->access & ACC_WRITE))
> continue;
> if ((mask & MAY_READ) && !(wh->access & ACC_READ))
> continue;
> +found:
> rcu_read_unlock();
> return 0;
> }
> @@ -527,7 +528,7 @@ int devcgroup_inode_mknod(int mode, dev_t dev)
>
> list_for_each_entry_rcu(wh, &dev_cgroup->whitelist, list) {
> if (wh->type & DEV_ALL)
> - goto acc_check;
> + goto found;
> if ((wh->type & DEV_BLOCK) && !S_ISBLK(mode))
> continue;
> if ((wh->type & DEV_CHAR) && !S_ISCHR(mode))
> @@ -536,9 +537,10 @@ int devcgroup_inode_mknod(int mode, dev_t dev)
> continue;
> if (wh->minor != ~0 && wh->minor != MINOR(dev))
> continue;
> -acc_check:
> +
> if (!(wh->access & ACC_MKNOD))
> continue;
> +found:
> rcu_read_unlock();
> return 0;
> }
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] devcgroup: skip superfluous checks when found the DEV_ALL elem
2009-04-10 0:06 ` Andrew Morton
@ 2009-04-10 0:20 ` Li Zefan
0 siblings, 0 replies; 4+ messages in thread
From: Li Zefan @ 2009-04-10 0:20 UTC (permalink / raw)
To: Andrew Morton; +Cc: serue, linux-kernel, containers
Andrew Morton wrote:
> On Tue, 07 Apr 2009 13:47:16 +0800
> Li Zefan <lizf@cn.fujitsu.com> wrote:
>
>> While walking through the whitelist, if the DEV_ALL item is found,
>> no more check is needed.
>>
>
> It's unobvious whether this is a behavioural change, a bugfix or just a
> speedup?
>
It's a speedup. I thought it's obvious by saying "skip superfluous checks"..
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-04-10 0:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-07 5:47 [PATCH] devcgroup: skip superfluous checks when found the DEV_ALL elem Li Zefan
2009-04-08 2:55 ` Serge E. Hallyn
2009-04-10 0:06 ` Andrew Morton
2009-04-10 0:20 ` Li Zefan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).