From patchwork Fri Oct 21 01:24:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 78580 Delivered-To: patches@linaro.org Received: by 10.140.97.247 with SMTP id m110csp1063666qge; Thu, 20 Oct 2016 18:24:43 -0700 (PDT) X-Received: by 10.99.131.66 with SMTP id h63mr5398754pge.103.1477013083394; Thu, 20 Oct 2016 18:24:43 -0700 (PDT) Return-Path: Received: from mail-pf0-x22f.google.com (mail-pf0-x22f.google.com. [2607:f8b0:400e:c00::22f]) by mx.google.com with ESMTPS id t5si128594paz.64.2016.10.20.18.24.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Oct 2016 18:24:43 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::22f as permitted sender) client-ip=2607:f8b0:400e:c00::22f; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::22f as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by mail-pf0-x22f.google.com with SMTP id r16so46511597pfg.1 for ; Thu, 20 Oct 2016 18:24:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=qkpb20ACL6pgRHsJJmZObIcYJ8Fftiujv32jUVl7Y3M=; b=gfNELPyPiq5nVsNaLhw4BI4baQYAf0ttbghg/S7jEQLdc7VNEgyCAMwDnII+XX5TPg SOXN/eCGrxFSZATSAQYUGA5d3wC979AvCSyzdsfHjc4l9UAZMbEYAQhaerUgy4JvUcV3 gbXYy7Ome5edlDG2ItglUQ0JHIfg7dtEjozsA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=qkpb20ACL6pgRHsJJmZObIcYJ8Fftiujv32jUVl7Y3M=; b=OvlWiirCLQ42qnaGgXkR18tLjjkrsCxTg5zna0WiF+XD3X/jc6tbJqNBY0KdjSBZSS BYaInfnS6qBPowmpo4f7nw+LnvYfHzqP9WD7EB3gz5l/okGo5ifLTZTX1FLO2mUqMRsm dk9E+SoKf04Bek109zd2yH9DHLqJtluehxRsVKkABT8xc5RHJCrQsXd6XkOq8HkD5qoV UW0RDO1Lp3V46B6e9VIso2I1SuAWKQI6TT+n9MHi8ejd+xmoJwYHpykOUhHkW9vl1SIT 1VVubkU+6MBI9lVFKi7jYMLaracOMqFStM3UR67M+c2rGxSqTHOmm8Dnz8zUe4F+3BJR cM1Q== X-Gm-Message-State: AA6/9RkrgooULrwkMJh37FwhJIlr9Gf9UpOnInNZ5KAmDg0fN1DEjbgGd9z8u0s2qUqFRMILs1I= X-Received: by 10.99.150.10 with SMTP id c10mr5330373pge.94.1477013083016; Thu, 20 Oct 2016 18:24:43 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id g196sm105859pfb.43.2016.10.20.18.24.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Oct 2016 18:24:42 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Tejun Heo , Li Zefan , Jonathan Corbet , cgroups@vger.kernel.org, Android Kernel Team , Rom Lemarchand , Colin Cross , Dmitry Shmidt , Todd Kjos , Christian Poetzsch , Amit Pundir , Dmitry Torokhov , Kees Cook , "Serge E . Hallyn" , linux-api@vger.kernel.org Subject: [RFC][PATCH v3] cgroup: Use CAP_SYS_RESOURCE to allow a process to migrate other tasks between cgroups Date: Thu, 20 Oct 2016 18:24:39 -0700 Message-Id: <1477013079-23692-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 This patch adds logic to allows a process to migrate other tasks between cgroups if they have CAP_SYS_RESOURCE. In Android (where this feature originated), the ActivityManager tracks various application states (TOP_APP, FOREGROUND, BACKGROUND, SYSTEM, etc), and then as applications change states, the SchedPolicy logic will migrate the application tasks between different cgroups used to control the different application states (for example, there is a background cpuset cgroup which can limit background tasks to stay on one low-power cpu, and the bg_non_interactive cpuctrl cgroup can then further limit those background tasks to a small percentage of that one cpu's cpu time). However, for security reasons, Android doesn't want to make the system_server (the process that runs the ActivityManager and SchedPolicy logic), run as root. So in the Android common.git kernel, they have some logic to allow cgroups to loosen their permissions so CAP_SYS_NICE tasks can migrate other tasks between cgroups. I feel the approach taken there overloads CAP_SYS_NICE a bit much, and is maybe more complicated then needed. So this patch, as suggested by Michael Kerrisk, simply adds a check for CAP_SYS_RESOURCE. I've tested this with AOSP master, and this seems to work well as Zygote and system_server already use CAP_SYS_RESOURCE. I've also submitted patches against the android-4.4 kernel to change it to use CAP_SYS_RESOURCE, and the Android developers have seemed ok with this change. Thouhts and feedback would be appreciated! Cc: Tejun Heo Cc: Li Zefan Cc: Jonathan Corbet Cc: cgroups@vger.kernel.org Cc: Android Kernel Team Cc: Rom Lemarchand Cc: Colin Cross Cc: Dmitry Shmidt Cc: Todd Kjos Cc: Christian Poetzsch Cc: Amit Pundir Cc: Dmitry Torokhov Cc: Kees Cook Cc: Serge E. Hallyn Cc: linux-api@vger.kernel.org Signed-off-by: John Stultz --- v2: Renamed to just CAP_CGROUP_MIGRATE as reccomended by Tejun v3: Switched to just using CAP_SYS_RESOURCE as suggested by Michael --- kernel/cgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.7.4 Acked-by: Serge Hallyn diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 09f84d2..866059a 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -2857,7 +2857,7 @@ static int cgroup_procs_write_permission(struct task_struct *task, if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) && !uid_eq(cred->euid, tcred->uid) && !uid_eq(cred->euid, tcred->suid) && - !ns_capable(tcred->user_ns, CAP_CGROUP_MIGRATE)) + !ns_capable(tcred->user_ns, CAP_SYS_RESOURCE)) ret = -EACCES; if (!ret && cgroup_on_dfl(dst_cgrp)) {