From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423179Ab2JaQEs (ORCPT ); Wed, 31 Oct 2012 12:04:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:17538 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422946Ab2JaQEq (ORCPT ); Wed, 31 Oct 2012 12:04:46 -0400 Date: Wed, 31 Oct 2012 12:04:30 -0400 From: Aristeu Rozanski To: linux-kernel@vger.kernel.org Cc: Andrew Morton , Tejun Heo , Li Zefan , James Morris , Pavel Emelyanov , Serge Hallyn , Jiri Slaby , cgroups@vger.kernel.org Subject: [PATCH] device_cgroup: fix unchecked cgroup parent usage Message-ID: <20121031160430.GD14789@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In 4cef7299b4786879a3e113e84084a72b24590c5b 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. Andrew, Tejun, this patch needs to make Linus tree ASAP or a revert for 4cef7299b4786879a3e113e84084a72b24590c5b. Cc: Andrew Morton Cc: Tejun Heo Cc: Li Zefan Cc: James Morris Cc: Pavel Emelyanov Cc: Serge Hallyn Cc: Jiri Slaby Signed-off-by: Aristeu Rozanski --- github.orig/security/device_cgroup.c 2012-10-26 17:18:01.739366780 -0400 +++ github/security/device_cgroup.c 2012-10-29 10:03:33.221918003 -0400 @@ -352,6 +352,8 @@ */ static inline int may_allow_all(struct dev_cgroup *parent) { + if (!parent) + return 1; return parent->behavior == DEVCG_DEFAULT_ALLOW; } @@ -376,11 +378,14 @@ int count, rc; struct dev_exception_item ex; struct cgroup *p = devcgroup->css.cgroup; - struct dev_cgroup *parent = cgroup_to_devcgroup(p->parent); + struct dev_cgroup *parent = NULL; if (!capable(CAP_SYS_ADMIN)) return -EPERM; + if (p->parent) + parent = cgroup_to_devcgroup(p->parent); + memset(&ex, 0, sizeof(ex)); b = buffer; @@ -391,11 +396,14 @@ if (!may_allow_all(parent)) return -EPERM; dev_exception_clean(devcgroup); + devcgroup->behavior = DEVCG_DEFAULT_ALLOW; + if (!parent) + break; + rc = dev_exceptions_copy(&devcgroup->exceptions, &parent->exceptions); if (rc) return rc; - devcgroup->behavior = DEVCG_DEFAULT_ALLOW; break; case DEVCG_DENY: dev_exception_clean(devcgroup);