From patchwork Mon Feb 3 16:19:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 232179 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 076E2C35247 for ; Mon, 3 Feb 2020 16:36:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CF5E521744 for ; Mon, 3 Feb 2020 16:36:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580747773; bh=JnRYNnGNOF9cZ3qsuZzHZ8R6s46Ky+gu6E3H11b26uw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=HcXwb5a7kLlYRNBNIDtMgU3YDJH2QSWyzSrHOlP8GKJVs2JQ6dQeXjhw6LdSr686H bQzEU2wobyeb5M+WC1t4U1dQqdV/9Tzwy9JmnqYXipc1tuFNnMdXAh8jj7HP/Vy7+I qrYCDjywJt+DfzwdKtsc+U48mk4I06Lwasm70lw4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730804AbgBCQgM (ORCPT ); Mon, 3 Feb 2020 11:36:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:51364 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731144AbgBCQgM (ORCPT ); Mon, 3 Feb 2020 11:36:12 -0500 Received: from localhost (unknown [104.132.45.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CF6112051A; Mon, 3 Feb 2020 16:36:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580747771; bh=JnRYNnGNOF9cZ3qsuZzHZ8R6s46Ky+gu6E3H11b26uw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hv+Tuj21u3jnd1tmdk4AykhN6xWHLX4JI9fv40iAy2IpPPGhcEt/2M/6UVdxCbvpD xeTReFNy4INxdU01NFPftpC4ZgMJbcsv6z9esQKra1vWd4s6+rYoRSh2GznUru4I2t gVzd4rd+gmWVSQZUm3M/AjdIQZiw/kiiZaeeuil8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+5493b2a54d31d6aea629@syzkaller.appspotmail.com, Christian Brauner , =?utf-8?q?Michal_Koutn=C3=BD?= , Tejun Heo Subject: [PATCH 5.4 23/90] cgroup: Prevent double killing of css when enabling threaded cgroup Date: Mon, 3 Feb 2020 16:19:26 +0000 Message-Id: <20200203161920.701201485@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200203161917.612554987@linuxfoundation.org> References: <20200203161917.612554987@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Michal Koutný commit 3bc0bb36fa30e95ca829e9cf480e1ef7f7638333 upstream. The test_cgcore_no_internal_process_constraint_on_threads selftest when running with subsystem controlling noise triggers two warnings: > [ 597.443115] WARNING: CPU: 1 PID: 28167 at kernel/cgroup/cgroup.c:3131 cgroup_apply_control_enable+0xe0/0x3f0 > [ 597.443413] WARNING: CPU: 1 PID: 28167 at kernel/cgroup/cgroup.c:3177 cgroup_apply_control_disable+0xa6/0x160 Both stem from a call to cgroup_type_write. The first warning was also triggered by syzkaller. When we're switching cgroup to threaded mode shortly after a subsystem was disabled on it, we can see the respective subsystem css dying there. The warning in cgroup_apply_control_enable is harmless in this case since we're not adding new subsys anyway. The warning in cgroup_apply_control_disable indicates an attempt to kill css of recently disabled subsystem repeatedly. The commit prevents these situations by making cgroup_type_write wait for all dying csses to go away before re-applying subtree controls. When at it, the locations of WARN_ON_ONCE calls are moved so that warning is triggered only when we are about to misuse the dying css. Reported-by: syzbot+5493b2a54d31d6aea629@syzkaller.appspotmail.com Reported-by: Christian Brauner Signed-off-by: Michal Koutný Signed-off-by: Tejun Heo Signed-off-by: Greg Kroah-Hartman --- kernel/cgroup/cgroup.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -3111,8 +3111,6 @@ static int cgroup_apply_control_enable(s for_each_subsys(ss, ssid) { struct cgroup_subsys_state *css = cgroup_css(dsct, ss); - WARN_ON_ONCE(css && percpu_ref_is_dying(&css->refcnt)); - if (!(cgroup_ss_mask(dsct) & (1 << ss->id))) continue; @@ -3122,6 +3120,8 @@ static int cgroup_apply_control_enable(s return PTR_ERR(css); } + WARN_ON_ONCE(percpu_ref_is_dying(&css->refcnt)); + if (css_visible(css)) { ret = css_populate_dir(css); if (ret) @@ -3157,11 +3157,11 @@ static void cgroup_apply_control_disable for_each_subsys(ss, ssid) { struct cgroup_subsys_state *css = cgroup_css(dsct, ss); - WARN_ON_ONCE(css && percpu_ref_is_dying(&css->refcnt)); - if (!css) continue; + WARN_ON_ONCE(percpu_ref_is_dying(&css->refcnt)); + if (css->parent && !(cgroup_ss_mask(dsct) & (1 << ss->id))) { kill_css(css); @@ -3448,7 +3448,8 @@ static ssize_t cgroup_type_write(struct if (strcmp(strstrip(buf), "threaded")) return -EINVAL; - cgrp = cgroup_kn_lock_live(of->kn, false); + /* drain dying csses before we re-apply (threaded) subtree control */ + cgrp = cgroup_kn_lock_live(of->kn, true); if (!cgrp) return -ENOENT;