Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp23373175rwd; Sat, 1 Jul 2023 00:16:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlFJSQWnB25aqWmTIiDEdl+iKZEfE/asaoUsKzxcIw4tf9M2lU/CDjqs1epafFvrPJijTBk7 X-Received: by 2002:a17:90b:4f81:b0:262:ec13:d3a with SMTP id qe1-20020a17090b4f8100b00262ec130d3amr4826831pjb.28.1688195804459; Sat, 01 Jul 2023 00:16:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688195804; cv=none; d=google.com; s=arc-20160816; b=KPvBd5u6D641sso18NeUuL7JC5IxUyW3J10l7oqLgJJhitiHI9wrScvyJPPcUPBagU Sq4TT9t+idDRV7TtPZAhdOyZ3ISPcr0cVfOOKY1Wt0Z9dhx/v2UWKZKEegnKUqbRTA3h yq117wNYJaDq7zoucpnR7IIXm6YEGQPxxH2COC5eBUIcfEPKoPhSGmQF9czcZf+DGkpk 1+tiJFIKlPwmAfAp8MZ0ItmSR8/wfsOZAmzVK0sx9LaqMLy1O196eorMFjFu4syBleo8 x0B7bP+bCxoVIfZfc1gkzxTyibnM0muj6tnLy0/GUCyGKsPPiLB3honAl82pum97I11c jWkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=AYnFhvIMZyh/5xzJjTtA6c4mbUbz4Pn+uQs+8vDT4qg=; fh=xm61FqaKFbVtJj3DZjMBwIjT3viqbFfn4Ws5hFHxOsg=; b=xtanLqhIt0bY9QR8PPuKLTjGxDzyG3fjvP9cRGp21cd9SnbDkg+ypfXnmJJeOt6EuC AzTX1nRMdtYKgVjH7eAsOIKSbwJzMhi2pzhMolkpzp6SKX4YSTSvybH+RHL6Kk+FhzZ5 QDouHx76rjxL2CwZEnPp/0xtLgvmHDQZdR5L93qSL04RlPANFzPr1HGKryd39oNpVKN+ f0AJcRX11jvIQQ2XMetJrwT8Wl8VjOMc+7F9yXB5ZRvhTlM7e9Axr7+opxXXHceeHNUH wFPGYP6a3Bxoqjm7BX+WS+GFm7cmBzBRat6HbA2ylQEWXoik5AeVPeIF86s88OaUQnBg RNSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 201-20020a6301d2000000b0055381e05244si14412601pgb.777.2023.07.01.00.16.29; Sat, 01 Jul 2023 00:16:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231828AbjGAG4T (ORCPT + 99 others); Sat, 1 Jul 2023 02:56:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229695AbjGAGza (ORCPT ); Sat, 1 Jul 2023 02:55:30 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11539423B; Fri, 30 Jun 2023 23:50:27 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QtN966WN7zqSKb; Sat, 1 Jul 2023 14:50:02 +0800 (CST) Received: from huawei.com (10.174.151.185) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Sat, 1 Jul 2023 14:50:23 +0800 From: Miaohe Lin To: , , , CC: , , Subject: [PATCH] cgroup/cpuset: update parent subparts cpumask while holding css refcnt Date: Sat, 1 Jul 2023 14:50:49 +0800 Message-ID: <20230701065049.1758266-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org update_parent_subparts_cpumask() is called outside RCU read-side critical section without holding extra css refcnt of cp. In theroy, cp could be freed at any time. Holding extra css refcnt to ensure cp is valid while updating parent subparts cpumask. Fixes: d7c8142d5a55 ("cgroup/cpuset: Make partition invalid if cpumask change violates exclusivity rule") Signed-off-by: Miaohe Lin --- kernel/cgroup/cpuset.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index 58e6f18f01c1..632a9986d5de 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -1806,9 +1806,12 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs, cpuset_for_each_child(cp, css, parent) if (is_partition_valid(cp) && cpumask_intersects(trialcs->cpus_allowed, cp->cpus_allowed)) { + if (!css_tryget_online(&cp->css)) + continue; rcu_read_unlock(); update_parent_subparts_cpumask(cp, partcmd_invalidate, NULL, &tmp); rcu_read_lock(); + css_put(&cp->css); } rcu_read_unlock(); retval = 0; -- 2.33.0