Received: by 10.213.65.68 with SMTP id h4csp885248imn; Tue, 27 Mar 2018 10:34:11 -0700 (PDT) X-Google-Smtp-Source: AIpwx49A7/hRFFlaL20oX/PgUxm6VU0ZQkYmW3UOFnnJCjSoi0T/5jn8+oHK+oj8rT5HQXTFq5ia X-Received: by 2002:a17:902:2b84:: with SMTP id l4-v6mr225665plb.65.1522172051114; Tue, 27 Mar 2018 10:34:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522172051; cv=none; d=google.com; s=arc-20160816; b=GguGVL/08TPU4FAtTTXk71CcOTHMTYuRhu6FbzXMsrPVnfxrG6DISdEtTTIDwyxHM1 l0xoZvba9f/xOJYzACLzwMOxsdXxIHA4mpOm2i3Nbrq3gcN3Ih2JA1FLc5qcXagEb3ac SmhWOp6QamKX8fTps9bHvBpvegwqWsXtZ9cC3wZIqFLRC0reyHy7kzi3rninyfaHJ9va cE5YLKQZzi8iKfnvZop841oRzr8scE879fvoNYsKe1EkkIQVp1pEp4BNiktbAH89GsfI dUHSYusfuTIJuIWM/+RKLUGllh3Xgj+Td6RjjPNfF0Rg2WHyxVptW6xH7gW+JSRnqmE8 L4aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=bQqdmmekBAUXBqDKOKRFzs9Xqx+C0hhFZ+wt1JEsrig=; b=oG+cgg6aG3H4qSX7h4/wUAGvb+J7xsSSJZYVZZuSF8pbQaxKlxiLPQTcR8MrzPhCbO me30qfm59+T7akPiMChTqDwsnALKqDIeEj5iGit1gXB+ui1fsf8R6VLqYVZ0asZwoBwa n3/23epUasQYKFOCe2iFyadCcI+VtufEd3pqQnayvxl83kQIVqM8QZT/vkcqWqCr1LZA efgtvL8l8Ro7gJ26+76gyM+YI/nZSu8WUHtMxrtBuPatpy15ZAO6EpNtdxReTIWzlZwn zrh2CWZ2hZ28ZR/2H1w4Cas1Oh5b5BgekNEw0QC9TzVSDtwSaRK+GQeMGtrkurK22AxT 2u4A== ARC-Authentication-Results: i=1; mx.google.com; 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 l69si1232558pfk.180.2018.03.27.10.33.56; Tue, 27 Mar 2018 10:34:11 -0700 (PDT) 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; 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 S1754522AbeC0Qfe (ORCPT + 99 others); Tue, 27 Mar 2018 12:35:34 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44860 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754426AbeC0Qfb (ORCPT ); Tue, 27 Mar 2018 12:35:31 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C3AB71225; Tue, 27 Mar 2018 16:35:30 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Michael Kerrisk (man-pages)" , Tejun Heo Subject: [PATCH 4.14 043/101] cgroup: fix rule checking for threaded mode switching Date: Tue, 27 Mar 2018 18:27:15 +0200 Message-Id: <20180327162752.666971002@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162749.993880276@linuxfoundation.org> References: <20180327162749.993880276@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tejun Heo commit d1897c9538edafd4ae6bbd03cc075962ddde2c21 upstream. 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+ Signed-off-by: Greg Kroah-Hartman --- kernel/cgroup/cgroup.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -3148,6 +3148,16 @@ static int cgroup_enable_threaded(struct 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))