Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp877120rwb; Thu, 19 Jan 2023 04:00:10 -0800 (PST) X-Google-Smtp-Source: AMrXdXvU6Bf6SDspnW0eytrdPGKsmx8HETNauOpNU0ypQw5LXo1WR3ekzyRk/hURfpLbqPXRI+Xv X-Received: by 2002:a05:6402:10c6:b0:497:d4ca:457d with SMTP id p6-20020a05640210c600b00497d4ca457dmr10359292edu.34.1674129610208; Thu, 19 Jan 2023 04:00:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674129610; cv=none; d=google.com; s=arc-20160816; b=b3fxAa/1oyjwZMaeXJhSNQE2lOrAZ/BU2uOa98fMQ6PodEgol5PEA1ual8S/a7TDpf QAa8ypudP4+pA6JcNZXBdm+YL5lhIiFiAY1HojbrWRX0NE6iAFW/BchsfdUxFJCRjrv7 DFTupDGsjrhviAjZEaqMsL/cLiZBmPD1PyyzucgjwLnyyR+cjaYLseXS2MkVQ92l2ABn d5wOqzfRslJxaidhyT/oXo3IOiUT1h47tf8vQZ4L/Tbclxdr4nG/+G8pmKrK+YKnYV+o ijl1jGBwdWZYSbahPFMPb/8X+k/Ae2cort2gUU8TZG8j+Kww8Jbip8toTb3BA2tqOpJ+ a05A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=JYULC5/53QdQisqNd02+cD42FE55GvrkpT5vXCX7kdY=; b=p7B9c1xDTa5U9ixh3Z1yc3HnBUSMEIibQnpC9it+RNoW7IX/cfV0Jlh3hj9bAWn7jc XqOtW4DHqt83j98f6n0bVpWh9zpm6K7G7ECXITI5z1JJnhpNFBFkkQ4zAFbq3UxaxL+2 9d0Qhs40kLTuJYnBrhCU5T9toe/CTBJFBENywTHN+rcTJiKPYCkeheGSg3DtvT2n6yA4 zuNAjwiwq8MOvcMaZ5TSj2yzcGLO2IC78nKnyRVrgXQch92CMa2sSfWWin5uWkLMNLml 1fv2EJGzNmQXi+EjyxcbvKSqam0vQVTL07MNbw/TFiISKuqQKN1350yOpbHN24qyPFmM k6qw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l16-20020a056402255000b0046197a8b7a1si34566506edb.485.2023.01.19.03.59.58; Thu, 19 Jan 2023 04:00:10 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230208AbjASKj6 (ORCPT + 44 others); Thu, 19 Jan 2023 05:39:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229630AbjASKjo (ORCPT ); Thu, 19 Jan 2023 05:39:44 -0500 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 880014941E; Thu, 19 Jan 2023 02:39:42 -0800 (PST) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4NyJzC659pz4f3qQw; Thu, 19 Jan 2023 18:39:35 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP3 (Coremail) with SMTP id _Ch0CgCnUyHmHclj45hSBw--.55879S5; Thu, 19 Jan 2023 18:39:38 +0800 (CST) From: Yu Kuai To: tj@kernel.org, hch@lst.de, josef@toxicpanda.com, axboe@kernel.dk Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH -next v3 1/3] blk-cgroup: dropping parent refcount after pd_free_fn() is done Date: Thu, 19 Jan 2023 19:03:48 +0800 Message-Id: <20230119110350.2287325-2-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230119110350.2287325-1-yukuai1@huaweicloud.com> References: <20230119110350.2287325-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _Ch0CgCnUyHmHclj45hSBw--.55879S5 X-Coremail-Antispam: 1UD129KBjvJXoW7AF1kGF4DuFW5Ar4xCr4rZrb_yoW8WF15pa n3Kr45KrWFgF1qva17t3ZrX34rCF4rG348GrWrGa1Fkry3CryvvFn5Zrs5ZrWFvF97JFW5 Zr4vqa4UJa1jkaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBK14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UM2 8EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AI xVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20x vE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xv r2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2IY04 v7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_ Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x 0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8 JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIx AIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUjeWlDUUUUU= = X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, MAY_BE_FORGED,SPF_HELO_NONE,SPF_NONE 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 From: Yu Kuai Some cgroup policies will access parent pd through child pd even after pd_offline_fn() is done. If pd_free_fn() for parent is called before child, then UAF can be triggered. Hence it's better to guarantee the order of pd_free_fn(). Currently refcount of parent blkg is dropped in __blkg_release(), which is before pd_free_fn() is called in blkg_free_work_fn() while blkg_free_work_fn() is called asynchronously. This patch make sure pd_free_fn() called from removing cgroup is ordered by delaying dropping parent refcount after calling pd_free_fn() for child. BTW, pd_free_fn() will also be called from blkcg_deactivate_policy() from deleting device, and following patches will guarantee the order. Signed-off-by: Yu Kuai Acked-by: Tejun Heo --- block/blk-cgroup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index 4c94a6560f62..c6d7d1fce65a 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -124,6 +124,8 @@ static void blkg_free_workfn(struct work_struct *work) if (blkg->pd[i]) blkcg_policy[i]->pd_free_fn(blkg->pd[i]); + if (blkg->parent) + blkg_put(blkg->parent); if (blkg->q) blk_put_queue(blkg->q); free_percpu(blkg->iostat_cpu); @@ -158,8 +160,6 @@ static void __blkg_release(struct rcu_head *rcu) /* release the blkcg and parent blkg refs this blkg has been holding */ css_put(&blkg->blkcg->css); - if (blkg->parent) - blkg_put(blkg->parent); blkg_free(blkg); } -- 2.31.1