Skip to content

Commit

Permalink
devcgroup: skip superfluous checks when found the DEV_ALL elem
Browse files Browse the repository at this point in the history
While walking through the whitelist, if the DEV_ALL item is found, no more
check is needed.

Signed-off-by: Li Zefan <[email protected]>
Acked-by: Serge Hallyn <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Li Zefan authored and torvalds committed Jun 18, 2009
1 parent f9ab5b5 commit cd50081
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions security/device_cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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;
}
Expand All @@ -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))
Expand All @@ -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;
}
Expand Down

0 comments on commit cd50081

Please sign in to comment.