From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3F4EC10DC1 for ; Fri, 8 Dec 2023 07:29:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573245AbjLHH3f (ORCPT ); Fri, 8 Dec 2023 02:29:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232216AbjLHH3d (ORCPT ); Fri, 8 Dec 2023 02:29:33 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7755171E for ; Thu, 7 Dec 2023 23:29:39 -0800 (PST) Received: from kwepemm000013.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SmjRq5zG7zWj96; Fri, 8 Dec 2023 15:28:39 +0800 (CST) Received: from [10.174.178.46] (10.174.178.46) by kwepemm000013.china.huawei.com (7.193.23.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Fri, 8 Dec 2023 15:29:36 +0800 Subject: Re: [PATCH] ubi: block: fix null-pointer-dereference in ubiblock_create() To: , , , CC: , , , , , , References: <20231208071317.1268465-1-linan666@huaweicloud.com> From: Zhihao Cheng Message-ID: Date: Fri, 8 Dec 2023 15:29:35 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20231208071317.1268465-1-linan666@huaweicloud.com> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.46] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm000013.china.huawei.com (7.193.23.81) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ÔÚ 2023/12/8 15:13, linan666@huaweicloud.com дµÀ: > From: Li Nan > > If idr_alloc() fails, dev->gd will be put after goto out_cleanup_disk in > ubiblock_create(), but dev->gd has not been assigned yet at this time, and > accessing it will trigger a null-pointer-dereference issue. Fix it by put > gd directly. Function 'put_disk()' checks disk whether is NULL, so I think it's a 'memleak' problem, not a null-ptr-deref problem. > > Signed-off-by: Li Nan > --- > drivers/mtd/ubi/block.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c > index 309a42aeaa4c..654bd7372cd8 100644 > --- a/drivers/mtd/ubi/block.c > +++ b/drivers/mtd/ubi/block.c > @@ -434,7 +434,7 @@ int ubiblock_create(struct ubi_volume_info *vi) > list_del(&dev->list); > idr_remove(&ubiblock_minor_idr, gd->first_minor); > out_cleanup_disk: > - put_disk(dev->gd); > + put_disk(gd); For memleak solution: Reviewed-by: Zhihao Cheng > out_free_tags: > blk_mq_free_tag_set(&dev->tag_set); > out_free_dev: