diff options
author | Aristeu Rozanski <aris@redhat.com> | 2012-11-06 10:25:04 -0500 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2012-11-06 10:25:20 -0500 |
commit | 64e104771351d365e51e588a0e9a656ae6ed2f50 (patch) | |
tree | e5078e0ba32729735846aa465c1f53f5d98c11ac /security | |
parent | 3d70f8c617a436c7146ecb81df2265b4626dfe89 (diff) |
device_cgroup: fix unchecked cgroup parent usage
In 4cef7299b478687 ("device_cgroup: add proper checking when changing
default behavior") the cgroup parent usage is unchecked. root will not
have a parent and trying to use device.{allow,deny} will cause problems.
For some reason my stressing scripts didn't test the root directory so I
didn't catch it on my regular tests.
Signed-off-by: Aristeu Rozanski <aris@redhat.com>
Cc: Li Zefan <lizefan@huawei.com>
Cc: James Morris <jmorris@namei.org>
Cc: Pavel Emelyanov <xemul@openvz.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Cc: Jiri Slaby <jslaby@suse.cz>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'security')
-rw-r--r-- | security/device_cgroup.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/security/device_cgroup.c b/security/device_cgroup.c index 842c254396db..96d87eab1660 100644 --- a/security/device_cgroup.c +++ b/security/device_cgroup.c | |||
@@ -352,6 +352,8 @@ static int parent_has_perm(struct dev_cgroup *childcg, | |||
352 | */ | 352 | */ |
353 | static inline int may_allow_all(struct dev_cgroup *parent) | 353 | static inline int may_allow_all(struct dev_cgroup *parent) |
354 | { | 354 | { |
355 | if (!parent) | ||
356 | return 1; | ||
355 | return parent->behavior == DEVCG_DEFAULT_ALLOW; | 357 | return parent->behavior == DEVCG_DEFAULT_ALLOW; |
356 | } | 358 | } |
357 | 359 | ||
@@ -376,11 +378,14 @@ static int devcgroup_update_access(struct dev_cgroup *devcgroup, | |||
376 | int count, rc; | 378 | int count, rc; |
377 | struct dev_exception_item ex; | 379 | struct dev_exception_item ex; |
378 | struct cgroup *p = devcgroup->css.cgroup; | 380 | struct cgroup *p = devcgroup->css.cgroup; |
379 | struct dev_cgroup *parent = cgroup_to_devcgroup(p->parent); | 381 | struct dev_cgroup *parent = NULL; |
380 | 382 | ||
381 | if (!capable(CAP_SYS_ADMIN)) | 383 | if (!capable(CAP_SYS_ADMIN)) |
382 | return -EPERM; | 384 | return -EPERM; |
383 | 385 | ||
386 | if (p->parent) | ||
387 | parent = cgroup_to_devcgroup(p->parent); | ||
388 | |||
384 | memset(&ex, 0, sizeof(ex)); | 389 | memset(&ex, 0, sizeof(ex)); |
385 | b = buffer; | 390 | b = buffer; |
386 | 391 | ||
@@ -391,11 +396,14 @@ static int devcgroup_update_access(struct dev_cgroup *devcgroup, | |||
391 | if (!may_allow_all(parent)) | 396 | if (!may_allow_all(parent)) |
392 | return -EPERM; | 397 | return -EPERM; |
393 | dev_exception_clean(devcgroup); | 398 | dev_exception_clean(devcgroup); |
399 | devcgroup->behavior = DEVCG_DEFAULT_ALLOW; | ||
400 | if (!parent) | ||
401 | break; | ||
402 | |||
394 | rc = dev_exceptions_copy(&devcgroup->exceptions, | 403 | rc = dev_exceptions_copy(&devcgroup->exceptions, |
395 | &parent->exceptions); | 404 | &parent->exceptions); |
396 | if (rc) | 405 | if (rc) |
397 | return rc; | 406 | return rc; |
398 | devcgroup->behavior = DEVCG_DEFAULT_ALLOW; | ||
399 | break; | 407 | break; |
400 | case DEVCG_DENY: | 408 | case DEVCG_DENY: |
401 | dev_exception_clean(devcgroup); | 409 | dev_exception_clean(devcgroup); |