Message ID | 20221112110754.1109979-1-liushixin2@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1205223wru; Sat, 12 Nov 2022 02:24:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf67OG54idDPrNU3NAv5UDxc0mG8TqHbfBKMkZdndYhvYZRymcv7+1VQJlCtmQglGAt5O1JH X-Received: by 2002:a50:bb2c:0:b0:463:71ef:b9ce with SMTP id y41-20020a50bb2c000000b0046371efb9cemr4769958ede.75.1668248640196; Sat, 12 Nov 2022 02:24:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668248640; cv=none; d=google.com; s=arc-20160816; b=n6hlu+hFuasI+mi5NYELJN6X/b3Vbcb5i0L0M5vh9RPHxPN714BZFgCu/mIoMJY2Ms UmGaaNTokjHnwM+YXhoLU4Ua5zpTc+EAkhgvzJ2KDfxnTO+aYfdlRolYws7a0bsqEsQt 7T9tXcfihmlAgfTiMS8dAxly/5g82Sk3FjMQ+dER67W+tLX6i/d9ZZlTUd7H8Sf6QwHm TnkZCl6m6m3LtwISBW00XL7AXrXtEJ4mvy3aCMuRZ8XUmOHgiA8PjqX4vW21LVKtkGC5 BM8M8k7aGh1lKIoMugMTM/Jo/R8oNqDuARpKhwz3q+7VGy4yU58X7NcaDgCMrP5G7U+O pNvQ== 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=XFPATY0qSbr/4BxOYP6cUXPh+6zQbgmtBLgKxuFJzZA=; b=dqfotncWrekfAYBPWBeqQSZPaHa8V2WZL5sQO8xgc50tp4EM/oIzq1JBQv7lKmi+Ql GKfA5M2vc2IycV9OIlQAc5UzGvXXpIUxb/IObDYZExh4qefrI9Ivc01iwfljkbtWeT8V FncERJtoTeZTPgJ/hw2Ila3h7lZ/8peMgCQ4bCfciBydBtZFN3RG2bMEc1YqC/pt8lps 0gXS8QcubQNiqYRZVIKcIzdGQfZRtjDAViVWqgoJMbkzJzQqZ30I5tmbvuZyHOPLvzn8 S8QRMD2qg3aR5QYfICw0Y6CnMUi9O3DOjxv1W379bVAwHhvsYUMBoyAlLaB0mRBL1Jkf nOcg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y12-20020a056402440c00b00463a83ce065si5309959eda.420.2022.11.12.02.23.06; Sat, 12 Nov 2022 02:24:00 -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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232427AbiKLKUS (ORCPT <rfc822;winker.wchi@gmail.com> + 99 others); Sat, 12 Nov 2022 05:20:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230170AbiKLKUQ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 12 Nov 2022 05:20:16 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C219BC14; Sat, 12 Nov 2022 02:20:15 -0800 (PST) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4N8Whg27ryzJnWV; Sat, 12 Nov 2022 18:17:07 +0800 (CST) Received: from dggpemm100009.china.huawei.com (7.185.36.113) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 12 Nov 2022 18:20:11 +0800 Received: from huawei.com (10.175.113.32) by dggpemm100009.china.huawei.com (7.185.36.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 12 Nov 2022 18:20:11 +0800 From: Liu Shixin <liushixin2@huawei.com> To: Jens Axboe <axboe@kernel.dk> CC: <linux-block@vger.kernel.org>, <linux-kernel@vger.kernel.org>, Liu Shixin <liushixin2@huawei.com> Subject: [PATCH] blk-mq: only unregister sysfs when registration succeeded Date: Sat, 12 Nov 2022 19:07:54 +0800 Message-ID: <20221112110754.1109979-1-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749285486002776978?= X-GMAIL-MSGID: =?utf-8?q?1749285486002776978?= |
Series |
blk-mq: only unregister sysfs when registration succeeded
|
|
Commit Message
Liu Shixin
Nov. 12, 2022, 11:07 a.m. UTC
kobject_del() must not be called if kobject_add() has not been called.
Hence only unregister sysfs when registration succeeded.
Signed-off-by: Liu Shixin <liushixin2@huawei.com>
---
block/blk-mq-sysfs.c | 2 ++
1 file changed, 2 insertions(+)
Comments
Hi, 在 2022/11/12 19:07, Liu Shixin 写道: > kobject_del() must not be called if kobject_add() has not been called. > Hence only unregister sysfs when registration succeeded. > From what I see, the blk_queue_registered() from caller blk_unregister_queue() can already prevent that. QUEUE_FLAG_REGISTERED will only be set if blk_register_queue() succeed. Thanks, Kuai > Signed-off-by: Liu Shixin <liushixin2@huawei.com> > --- > block/blk-mq-sysfs.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c > index 93997d297d42..63f2df2500d9 100644 > --- a/block/blk-mq-sysfs.c > +++ b/block/blk-mq-sysfs.c > @@ -279,6 +279,8 @@ void blk_mq_sysfs_unregister(struct gendisk *disk) > unsigned long i; > > lockdep_assert_held(&q->sysfs_dir_lock); > + if (!q->mq_sysfs_init_done) > + return; > > queue_for_each_hw_ctx(q, hctx, i) > blk_mq_unregister_hctx(hctx); >
在 2022/11/12 18:44, Yu Kuai 写道: > Hi, > > 在 2022/11/12 19:07, Liu Shixin 写道: >> kobject_del() must not be called if kobject_add() has not been called. >> Hence only unregister sysfs when registration succeeded. >> > > From what I see, the blk_queue_registered() from caller > blk_unregister_queue() can already prevent that. QUEUE_FLAG_REGISTERED > will only be set if blk_register_queue() succeed. I see that the return value of blk_mq_sysfs_register() is not checked from blk_register_queue(), there will be memleak or uaf from error path. Hence I think better thing to do is to handle the case that blk_mq_sysfs_register() faild, and clean up if blk_mq_sysfs_register() succeed while follow up procedures failed from blk_register_queue().
diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c index 93997d297d42..63f2df2500d9 100644 --- a/block/blk-mq-sysfs.c +++ b/block/blk-mq-sysfs.c @@ -279,6 +279,8 @@ void blk_mq_sysfs_unregister(struct gendisk *disk) unsigned long i; lockdep_assert_held(&q->sysfs_dir_lock); + if (!q->mq_sysfs_init_done) + return; queue_for_each_hw_ctx(q, hctx, i) blk_mq_unregister_hctx(hctx);