Received: by 10.223.185.116 with SMTP id b49csp1084989wrg; Wed, 21 Feb 2018 11:51:09 -0800 (PST) X-Google-Smtp-Source: AH8x2243hAI3SYUqps8z8Qw3ly8nLzNhU+8B1YQUptwEIULn+SZa7c4OqIJsI05ELjiVes2vpHlj X-Received: by 2002:a17:902:8b87:: with SMTP id ay7-v6mr4210065plb.139.1519242669077; Wed, 21 Feb 2018 11:51:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519242669; cv=none; d=google.com; s=arc-20160816; b=zG3Jr4mNilwkK5YZTLl6Z1hmgTh2Tna51mFNrTDR0UcuxJM4F4Qqy/em/NJgITX1Lw aV/HyXrdHQhVT5x1Z2A9aL7kv8Ch08nG8i6OwGmyZQwZa/oWK31huARphwarjuJmdoN7 mN/AdugdBSlIiTb2NjKgwFiVreSS5uw9r9ACe+fWV9pYUBFhNnYqgazaOtGEx85sZJn8 1Uqnjw+3QOHZLFQoVB8ni/n/MLvgwH4j1PvcqXz/bIpOpzDE3egL3dHMO6xMgYpVnuQP RBHqPle2+x/Jdg1YNc/nqL+uY7fv+zYl3jH6bdauzJxsosUMGl+emlbTxRGVoqAJoS5d SVNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=dFVzJF6T+bHakiy0WlZy8nBIbPfHL63GBnWCuR+XSgs=; b=hCKNBH6Ng/bprF4V8XMGtrGp1+9qfR5kiwh7R0ph9xIy4It5yeeBQj44wNSKzLKlv6 cgX8wZoFRoK7N0wnseZ3nZWTJ4mOeGmjnK+RstV3vRj8qlCWRYrH9G4nTFHvWi9xOQKu aGxEOF5l1L4I1JOo+OjX87jFgC53lyhUSt9zKOeKGSVa27nN3A/ouqaUz3GRfURrEPVH 0SxBfY3Qpj1ToQKgKm1GeoMM5cUuTG39tYiF0E0vfN/R8FwBmAqZ+p2YZCqIXJrjAj6k v5opx9DwI/CTkHTct+/BLz3xKsT94sNN20k/VZY7vOxBqMNJSbYaNKebjC1Nb86g1oKJ xtOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=TxPgK38f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x21-v6si2573349pln.416.2018.02.21.11.50.54; Wed, 21 Feb 2018 11:51:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=TxPgK38f; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751339AbeBUTr2 (ORCPT + 99 others); Wed, 21 Feb 2018 14:47:28 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:41028 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751053AbeBUTr0 (ORCPT ); Wed, 21 Feb 2018 14:47:26 -0500 Received: by mail-qt0-f195.google.com with SMTP id a9so3429105qtj.8; Wed, 21 Feb 2018 11:47:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=dFVzJF6T+bHakiy0WlZy8nBIbPfHL63GBnWCuR+XSgs=; b=TxPgK38f1sgMSz3bOzl6SMv83IU7sXStCwotd4k/5YYyBjZlcRKpGWJozaBFnxF3Ov sS3PQY8UM8H2JaQQB6Z7nMbdLxhhWqb8F0qr2ygySMZcb3FEK1qC+u6AY3YnqYpu22cI 2lq4QbfPBvontOb+YiSuUkt69o+1OrkYlC05I8Q9Y9VUdYIJGJXGNZaVeYEVVTjeBYyj k7JgwGXXz1tvO+JVjWVDkGVkXgfrnmGGJQqPcShyZsFiJj6SyePYOgwY3Skiqmnl+7d0 wTYyOPmS2RwMUzKcqT3ddzNpA/H/2M+lWpZTyz5QcdNKWKUSKVkHtDI12yDuF77lhdE3 6sJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=dFVzJF6T+bHakiy0WlZy8nBIbPfHL63GBnWCuR+XSgs=; b=HGdj8gqRCLnlurOkz7PA9wain3rGy9LWQoZvZMh4VigWFdRypJa6EZSPTspqm/oD9Q CnWbObUmg3revGQH+ZK4mxz/ChmRQELvhPKgDofgGSAFvEDjo4gO08RgNsc7tky5sv/K k2SMrzuLEwJj8ymDXgu5ylDR4E8Bo8SBcY4bF3qq/uvgYi/w4joRoYmY13bK6ig9gtis ZBjSI5QVGMrmlL/QklrfDaOHkhtBPc0dyi96xf6p6EWXGbgXlbUzyxqgWKQGpiQgPlkm qImjb+V25bf4r0ApsLr+l7kjphlRDEIhx/gs8KuLYNA/nQq2l3IN6aJseKW34wVRpQVP 2+lA== X-Gm-Message-State: APf1xPCl7i/bB8n4OKq+EBhyVykmiktmWZFqIZkLIIsrKvCi6T6E13of rTP+BzOxRUzIZeA+n4rQM2A= X-Received: by 10.200.61.90 with SMTP id u26mr6908184qtf.168.1519242445493; Wed, 21 Feb 2018 11:47:25 -0800 (PST) Received: from localhost (dhcp-ec-8-6b-ed-7a-cf.cpe.echoes.net. [72.28.5.223]) by smtp.gmail.com with ESMTPSA id p35sm19406150qkh.74.2018.02.21.11.47.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 11:47:24 -0800 (PST) Date: Wed, 21 Feb 2018 11:47:22 -0800 From: Tejun Heo To: "Michael Kerrisk (man-pages)" Cc: "Serge E. Hallyn" , lkml , "open list:CONTROL GROUP (CGROUP)" , kernel-team@fb.com Subject: [PATCH cgroup/for-4.16-fixes] cgroup: fix rule checking for threaded mode switching Message-ID: <20180221194722.GF170644@devbig577.frc2.facebook.com> References: <20180220193547.GB170644@devbig577.frc2.facebook.com> <20180220230136.GD170644@devbig577.frc2.facebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From d1897c9538edafd4ae6bbd03cc075962ddde2c21 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Wed, 21 Feb 2018 11:39:22 -0800 A domain cgroup isn't allowed to be turned threaded if its subtree is populated or domain controllers are enabled. cgroup_enable_threaded() depended on cgroup_can_be_thread_root() test to enforce this rule. A parent which has populated domain descendants or have domain controllers enabled can't become a thread root, so the above rules are enforced automatically. However, for the root cgroup which can host mixed domain and threaded children, cgroup_can_be_thread_root() doesn't check any of those conditions and thus first level cgroups ends up escaping those rules. This patch fixes the bug by adding explicit checks for those rules in cgroup_enable_threaded(). Reported-by: Michael Kerrisk (man-pages) Signed-off-by: Tejun Heo Fixes: 8cfd8147df67 ("cgroup: implement cgroup v2 thread support") Cc: stable@vger.kernel.org # v4.14+ --- kernel/cgroup/cgroup.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 8cda3bc..4bfb290 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -3183,6 +3183,16 @@ static int cgroup_enable_threaded(struct cgroup *cgrp) if (cgroup_is_threaded(cgrp)) return 0; + /* + * If @cgroup is populated or has domain controllers enabled, it + * can't be switched. While the below cgroup_can_be_thread_root() + * test can catch the same conditions, that's only when @parent is + * not mixable, so let's check it explicitly. + */ + if (cgroup_is_populated(cgrp) || + cgrp->subtree_control & ~cgrp_dfl_threaded_ss_mask) + return -EOPNOTSUPP; + /* we're joining the parent's domain, ensure its validity */ if (!cgroup_is_valid_domain(dom_cgrp) || !cgroup_can_be_thread_root(dom_cgrp)) -- 2.9.5