Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1537157rwi; Mon, 10 Oct 2022 18:31:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7DbsUSw3SSVfKd6ilsokg0Ozr6OW98AvPJTi13/nwOnS5YvlQm2StTQcialCmqR8UmWFQj X-Received: by 2002:aa7:93a8:0:b0:563:4dc2:9e5f with SMTP id x8-20020aa793a8000000b005634dc29e5fmr9342039pff.68.1665451899028; Mon, 10 Oct 2022 18:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665451899; cv=none; d=google.com; s=arc-20160816; b=m2DwSPKPWOHLXB82Mky/93dOqqI+cEe4yUELjVmqIJjSnAIRO/81yMc8xyhslC6y8Z Q5THNbPVZk3j6nExQsYCIzNclBLPfw9NerkFEMO/ii5t2q1edTxhswiWXthn5vicRP1B SjGbhvl1vWBwF9oJhC/wox+MD7t9U1vsl/7ijlnIdh6VHK38mL2G7gL0RGk8uw9LYt9z GjDVeOeP/qmhNRR+g2qKAksb9LV2hFbZ4+ZLsq/LnEwVyWpHWc4EPsRW8qLO15B/naxP XSUwEmGzrHaiooaXzbfrF3u4aUtPvAEMj9SZ9LUSpTIH1wRr7q1DdAzJMWQztH5iqdoA 3F6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=TBkOL4RN5rp22VJhF5+Uk+wzD8sM4Ys13kHB3JPVL2A=; b=tX6S16zlqQCrhYv87P9khuRjO9Eh2HCdpfXj1OBz3tsohZajXR8Vd4PnRl7JGQnYHB FsqFnKSgaFB7p/N5laEMI/A6yW2zBK7T1LGptNZRxMeC5QKIS0jONjINLnYwOOD99lNH Uj1iyxpKt15n6eXDL/BoGmoJA3TK2xVzLixgzEV1eCqXWmEG9IOgv65g/IJzTI+dQfDl r2RlowP9/n8kKOpHE6ctXnSQNGwjUAW4HdAbOfK27MNhzkGs0gM6uGK6LqZngtbUXLKV K9ElbAuzC3t0SNvtbuwP/0mTFj66IeYVro0PYJXw29uEiHDYSntRa+5Wb+0HXMFACpN1 7yrA== 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 b12-20020a630c0c000000b00440403ac602si6289344pgl.618.2022.10.10.18.31.27; Mon, 10 Oct 2022 18:31:39 -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 S230516AbiJKBY7 (ORCPT + 99 others); Mon, 10 Oct 2022 21:24:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229971AbiJKBY2 (ORCPT ); Mon, 10 Oct 2022 21:24:28 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 593A2855B8; Mon, 10 Oct 2022 18:23:49 -0700 (PDT) Received: from kwepemi500016.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4MmdGp3Zg9z1M8h6; Tue, 11 Oct 2022 09:19:14 +0800 (CST) Received: from [10.174.178.129] (10.174.178.129) by kwepemi500016.china.huawei.com (7.221.188.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 11 Oct 2022 09:23:46 +0800 Subject: Re: [PATCH 3/4] blk-cgroup: Add NULL check of pd_alloc_fn in blkcg_activate_policy To: Tejun Heo CC: , , , References: <20221010023859.11896-1-shikemeng@huawei.com> <20221010023859.11896-4-shikemeng@huawei.com> From: Kemeng Shi Message-ID: Date: Tue, 11 Oct 2022 09:23:45 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="gbk" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.178.129] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500016.china.huawei.com (7.221.188.220) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS 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 on 10/11/2022 4:29 AM, Tejun Heo wrote: > On Mon, Oct 10, 2022 at 10:38:58AM +0800, Kemeng Shi wrote: >> Function blkcg_policy_register only make sure pd_alloc_fn and pd_free_fn in >> pairs, so pd_alloc_fn could be NULL in registered blkcg_policy. Check NULL >> before use for pd_alloc_fn in blkcg_activate_policy to avoid protential >> NULL dereference. >> >> Signed-off-by: Kemeng Shi >> --- >> block/blk-cgroup.c | 3 +++ >> 1 file changed, 3 insertions(+) >> >> diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c >> index 463c568d3e86..fc083c35dc42 100644 >> --- a/block/blk-cgroup.c >> +++ b/block/blk-cgroup.c >> @@ -1404,6 +1404,9 @@ int blkcg_activate_policy(struct request_queue *q, >> if (blkcg_policy_enabled(q, pol)) >> return 0; >> >> + if (pol->pd_alloc_fn == NULL) >> + return -EINVAL; > > This isn't the only place this function is called, so the above won't > achieve much. Given that this is rather trivially noticeable and all the > current users do implement pd_alloc_fn, I'm not sure we need to update this > now. Thanks for review. The rest call of this function will always protect by blkcg_policy_enabled while policy only can be enabled if new added NULL check is passed. So the new added NULL check enough. By the way, the policy enable/disable work is direct call to __set_bit(pol->plid, q->blkcg_pols) in blkcg_policy_enabled and __clear_bit(pol->plid, q->blkcg_pols) in blkcg_deactivate_policy which is not intuitive. Is it a good idea to add function blkcg_policy_enable and blkcg_policy_disable to improve readability? > > Thanks. > -- Best wishes Kemeng Shi