Skip to content

Commit

Permalink
devscgroup: make white list more compact in some cases
Browse files Browse the repository at this point in the history
Consider you added a 'c foo:bar r' permission to some cgroup and then (a
bit later) 'c'foo:bar w' for it.  After this you'll see the

c foo:bar r
c foo:bar w

lines in a devices.list file.

Another example - consider you added 10 'c foo:bar r' permissions to some
cgroup (e.g.  by mistake).  After this you'll see 10 c foo:bar r lines in
a list file.

This is weird.  This situation also has one more annoying consequence.
Having many items in a white list makes permissions checking slower, sine
it has to walk a longer list.

The proposal is to merge permissions for items, that correspond to the
same device.

Signed-off-by: Pavel Emelyanov <[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
xemul authored and torvalds committed Jun 6, 2008
1 parent 7db9cfd commit d1ee297
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions security/device_cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,29 @@ static int dev_whitelist_copy(struct list_head *dest, struct list_head *orig)
static int dev_whitelist_add(struct dev_cgroup *dev_cgroup,
struct dev_whitelist_item *wh)
{
struct dev_whitelist_item *whcopy;
struct dev_whitelist_item *whcopy, *walk;

whcopy = kmalloc(sizeof(*whcopy), GFP_KERNEL);
if (!whcopy)
return -ENOMEM;

memcpy(whcopy, wh, sizeof(*whcopy));
spin_lock(&dev_cgroup->lock);
list_add_tail(&whcopy->list, &dev_cgroup->whitelist);
list_for_each_entry(walk, &dev_cgroup->whitelist, list) {
if (walk->type != wh->type)
continue;
if (walk->major != wh->major)
continue;
if (walk->minor != wh->minor)
continue;

walk->access |= wh->access;
kfree(whcopy);
whcopy = NULL;
}

if (whcopy != NULL)
list_add_tail(&whcopy->list, &dev_cgroup->whitelist);
spin_unlock(&dev_cgroup->lock);
return 0;
}
Expand Down

0 comments on commit d1ee297

Please sign in to comment.