From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.201 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796409666; b=aV+t3QBvc6bGr+hX74BKARlKR779C41iL0FGvoLpwM+qQnUY5075LVtWrFWnGv8diqBL EYhE9XHlAOAhtgBpr5lyhfJ+Ed9LmQ028se+rcrtMu45uIJSuoImO6RfvZNACGCdHSeTm dQ6vTmNg5F81sR6Lp+pDvS6PFRgcHNnkxCPpk9iOImGGMilIhlS7J2vkznpnjxeO6/tJv gMDTM9ir4p33+bil7iwTf05YrFu/WcH+2wRE9mtwuoUWlq4sTrHv/7t2upjx8uiWmvUNC /STVlrw7KOih5mmjOe4AkGUrv4emjnH70WTzlsjoQlJ7SJaK9dTOrfbk9RhkGdSwRjA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796409666; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=Pa6Ohlnp/j5Gesj0L5RmjWBSkwnLYI9te2ILRQZOceQ=; b=kx/Linp7L+PfrI37gKmZiSHBdH02u8c5sTmAND4fwBioCGwl1pTUqLigePm5eo4h4gRH VTp9GXmnGNrlXqwrcapARYJ7knHfEsbpa5nbxEhWlwcc2rn4Sg7bw/ZmtkLsALIX1w8tw EGoj2vdR/6fSsOsBCy87BoBJSWmYTxzK5Ad0zvvChBPC/Zie/9DUYQ1aBMbpGP2Ks7VFs xLV1mDpIZFtN2FYDLtMjoiRgdBleGM5qzsXoA4xxulMj9+5hVbL0yalyWQ8BnFLQ8SDwm OuyehuOafIVHcEC4WwTNNpjpQ29LRoZd3i39OJG/lTmFi7cGZrt2e4oQZQDzdAF8mVg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=FaV9PKZu; arc=none smtp.remote-ip=95.215.58.201 Received: from mta1.migadu.com (out-201.mta1.migadu.com [95.215.58.201]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FBD860A260C for ; Fri, 4 Dec 2026 18:41:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9FBD860A260C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=FaV9PKZu X-Envelope-To: cgroups@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=RVV0+CcHZGtvsXnBtCqEo7PUOINhasWcS7LG/YoD2bU=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796409663; v=1; x=1797014463; b=FaV9PKZuhWvqc9UACnhUqfBYgY3XeDhlPEBQvHHxYl1doGwBdcPKC/ewXXg5gQT2/RGh4GlH GLsxnq2cxkFOZkpJQ4+Nw7r6jPuPdeKf/OFBKWXxGDn2kY19yNje+sAnfRGzOdwCJKaf8x3FjeO hrCSspIxq9eIlLmU3C8ni/3c= X-Envelope-To: cgroups@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 4ee773bd2950fb97; Fri, 04 Dec 2026 18:41:03 +0000 X-Mizu-Trace-ID: 4ee773bd2950fb97 X-Migadu-Flow: FLOW_OUT From: Shakeel Butt To: Tejun Heo Cc: Andrew Morton , Johannes Weiner , Michal Koutny , Michal Hocko , Roman Gushchin , Christian Brauner , Oleg Nesterov , Sebastian Andrzej Siewior , Suren Baghdasaryan , "T . J . Mercier" , Usama Arif , Meta kernel team , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sashiko , stable@vger.kernel.org Subject: [PATCH v3 03/12] cgroup: refuse cgroup.kill below a threaded cgroup Date: Fri, 4 Dec 2026 10:40:32 -0800 Message-ID: <20261204184041.1489976-4-shakeel.butt@linux.dev> X-Mailer: git-send-email 2.53.1 In-Reply-To: <20261204184041.1489976-1-shakeel.butt@linux.dev> References: <20261204184041.1489976-1-shakeel.butt@linux.dev> X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit cgroup.kill refuses threaded cgroups, because killing is a process directed operation: killing one thread takes down its whole process. But it accepts a cgroup below a threaded cgroup, which can hold threads of processes that live outside of it: mkdir -p A/B/C echo threaded > A/B/C/cgroup.type B becomes a thread root echo threaded > A/cgroup.type C joins the root's domain, and B becomes "domain invalid" echo > A/B/C/cgroup.threads a thread of a process in the root echo 1 > A/B/cgroup.kill succeeds and kills that process When a cgroup turns threaded, the threaded cgroups below it join its new domain, also those below a thread root such as B. Every cgroup below a threaded cgroup is threaded or an invalid domain, so refuse cgroup.kill for all of them, as it is refused for threaded cgroups. Reproduced in a VM. A selftest follows later in this series. Fixes: 661ee6280931 ("cgroup: introduce cgroup.kill") Reported-by: Sashiko Closes: https://lore.kernel.org/r/sashiko-outbox-241838@kernel.org Cc: stable@vger.kernel.org # v5.14+ Signed-off-by: Shakeel Butt --- Documentation/admin-guide/cgroup-v2.rst | 6 +++--- kernel/cgroup/cgroup.c | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 2f792ff29425..9539f3a99a2f 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1059,9 +1059,9 @@ All cgroup core files are prefixed with "cgroup." Killing a cgroup tree will deal with concurrent forks appropriately and is protected against migrations. - In a threaded cgroup, writing this file fails with EOPNOTSUPP as - killing cgroups is a process directed operation, i.e. it affects - the whole thread-group. + In a threaded cgroup, or a cgroup below one, writing this file fails + with EOPNOTSUPP as killing cgroups is a process directed operation, + i.e. it affects the whole thread-group. cgroup.pressure A read-write single value file that allowed values are "0" and "1". diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 0fcd2c1b0da9..f38da8b810f1 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -4322,6 +4322,20 @@ static ssize_t cgroup_freeze_write(struct kernfs_open_file *of, return nbytes; } +/* + * Is @cgrp threaded, or below a threaded cgroup? When a cgroup turns threaded, + * the threaded cgroups below it join its new domain, also those below a thread + * root. So a cgroup below a threaded cgroup can hold threads of processes that + * live outside of it. + */ +static bool cgroup_in_threaded_subtree(struct cgroup *cgrp) +{ + for (; cgrp; cgrp = cgroup_parent(cgrp)) + if (cgroup_is_threaded(cgrp)) + return true; + return false; +} + static void __cgroup_kill(struct cgroup *cgrp) { struct css_task_iter it; @@ -4392,9 +4406,10 @@ static ssize_t cgroup_kill_write(struct kernfs_open_file *of, char *buf, /* * Killing is a process directed operation, i.e. the whole thread-group * is taken down so act like we do for cgroup.procs and only make this - * writable in non-threaded cgroups. + * writable in non-threaded cgroups. The cgroups below a threaded cgroup + * can hold threads of processes outside of them, so refuse those too. */ - if (cgroup_is_threaded(cgrp)) + if (cgroup_in_threaded_subtree(cgrp)) ret = -EOPNOTSUPP; else cgroup_kill(cgrp); -- 2.53.1-Meta