Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp340251lqr; Wed, 5 Jun 2024 07:39:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXmQ0g3XfpPWhgKWBdjSlpp3p0S/uxcOpt/0L5NUxfvDFg64Brv99XZOLuMv8jvgo0BoTb5VGF1tiSYjBJtmelnfJegDAnaPgdEnUsvfg== X-Google-Smtp-Source: AGHT+IFCCrgZG2Tfr328JlAzoEQpjofM1xfh+khibwQ4Q7kpETTecnSuO1iiYQ3GTzNmOI9rNp8l X-Received: by 2002:a92:cd82:0:b0:374:90b0:9c0c with SMTP id e9e14a558f8ab-374b1ef2ca6mr28780195ab.10.1717598360122; Wed, 05 Jun 2024 07:39:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717598360; cv=pass; d=google.com; s=arc-20160816; b=vvJoHX6igjl7khf3ArCVNrwX0evjT6gacBHC0UVxtUQatjayk9lUpDU2a4YeKa7ecV pop/guxL49LH/hpV3B+3BxKlPVukdofIRN48tQ1oa0yN9OaoDgmBFOiBQupmR6gd8akH W0aJG3HS5hCRBMDvETDsfU2/unn+PwRkaPVbhtUpVl6CMUIEQ0G1K6mDx6+dn7DA//az RJzIf1Q0U+ChJLrpGBrMdE60jzIVl7HwHna2FcV/sMoclDIDuBCmwssZqV6k3JhMCYiK Ggl0Y7q8QXS0Y3JeRKa1Ja1o8kbrDc6DwSdq7M/Gj1xSXOX5kBB06LiE6Eiz4Qn04pfM WmwQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=VVQki7dljRdd595Iuazk93awZb7cREaJ1gMKT62U1tU=; fh=Cl/u9DV+aQwDU2Kk4xoiYdKI1zg11qPwCSdVohI20ZI=; b=Myd8sW2zUeSShANDAXNR2J7RhslSjmkH8UUrgVllx9VyVoz0UogvLgk1ejweNIOJVz GcaM14c6eYW0nT3L4q6MGqKTbX2pamGj/JrL0gn5/NdloXpa26xagS4T7zdIBSYqFEY6 NpHNfOw4fx2Tg8j/KCN0YYb4R880U6jEsmvwVvzb1KKZ4Rd3g69ZWYzzsUKEd046IVH2 pdEghhH3QnCIRnEtzQPtXkoIg9zfnciQidrOBeiICxmHlIEVebcgZnqpgpc6Z6SsTb8G bC7wyr0pL2xtAY81lV/SX2XClGNO1ZGOpQwoDu2KqnnrnBHW41sB3dVMrHv7W1cPjkB+ a7BA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=makrotopia.org); spf=pass (google.com: domain of linux-kernel+bounces-202603-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202603-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c35c73b8b4si2867634a12.716.2024.06.05.07.39.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 07:39:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202603-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=makrotopia.org); spf=pass (google.com: domain of linux-kernel+bounces-202603-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202603-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 842FA28C049 for ; Wed, 5 Jun 2024 13:11:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9248819B59B; Wed, 5 Jun 2024 12:27:16 +0000 (UTC) Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1155614D447 for ; Wed, 5 Jun 2024 12:27:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.142.180.65 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717590436; cv=none; b=fcPCS47vYXAzA6nORHVfhUGipTFDeuT9C0BSWxzKojriVQdx4mp4vnR/Fo9LwRJKMsJLtEOWD1CB6T+jPuNcmlhLjoV0Zw0yW6EwWF9auvt3zJnXE+s5LJKSvjG6q7vngEH/euHXfafk4p57Jwh1ge3Z3BySpLvmKlKAKKw8QwI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717590436; c=relaxed/simple; bh=UH+a2KNv7+kayHPhr6nzPqbtcC4qYCR4EJS1G8kFWxc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FHhs4kgToqxN6VJues1VZc2yw2irhRqCrPy5zlN8cAdpZ/ycoAH72xJco0u1kYVDS9siZkDssLovTWhsxUQ1PYFAH8MnLp1AXrY6h/hgoDvrA9vnQiTX8EuwkDrncVlzoNryGZYt2pHluiAnFmAYxQ04j6PdSSY22VVX7AbjRPE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.client-ip=185.142.180.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.97.1) (envelope-from ) id 1sEpjH-000000005ku-0xUu; Wed, 05 Jun 2024 12:26:59 +0000 Date: Wed, 5 Jun 2024 13:26:55 +0100 From: Daniel Golle To: linan666@huaweicloud.com Cc: richard@nod.at, miquel.raynal@bootlin.com, vigneshr@ti.com, chaitanya.kulkarni@wdc.com, axboe@kernel.dk, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, chengzhihao1@huawei.com, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: Re: [PATCH v3] ubi: block: fix null-pointer-dereference in ubiblock_create() Message-ID: References: <20240522171035.3776026-1-linan666@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240522171035.3776026-1-linan666@huaweicloud.com> On Thu, May 23, 2024 at 01:10:35AM +0800, linan666@huaweicloud.com wrote: > From: Li Nan > > Similar to commit adbf4c4954e3 ("ubi: block: fix memleak in > ubiblock_create()"), 'dev->gd' is not assigned but dereferenced if > blk_mq_alloc_tag_set() fails, and leading to a null-pointer-dereference. > Fix it by using pr_err() and variable 'dev' to print error log. > > Additionally, the log in the error handle path of idr_alloc() has > been improved by using pr_err(), too. Before initializing device > name, using dev_err() will print error log with 'null' instead of > the actual device name, like this: > block (null): ... > ~~~~~~ > It is unclear. Using pr_err() can print more details of the device. > The improved log is: > ubiblock0_0: ... > > Fixes: 77567b25ab9f ("ubi: use blk_mq_alloc_disk and blk_cleanup_disk") > Reported-by: Dan Carpenter > Signed-off-by: Li Nan Reviewed-by: Daniel Golle > --- > v3: spliting this patch into two in v2 is not a good idea. This version > is consistent with v1, but only optimizes the commit message. > > drivers/mtd/ubi/block.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c > index f82e3423acb9..bf7308e8ec2f 100644 > --- a/drivers/mtd/ubi/block.c > +++ b/drivers/mtd/ubi/block.c > @@ -390,7 +390,8 @@ int ubiblock_create(struct ubi_volume_info *vi) > > ret = blk_mq_alloc_tag_set(&dev->tag_set); > if (ret) { > - dev_err(disk_to_dev(dev->gd), "blk_mq_alloc_tag_set failed"); > + pr_err("ubiblock%d_%d: blk_mq_alloc_tag_set failed\n", > + dev->ubi_num, dev->vol_id); > goto out_free_dev; > } > > @@ -407,8 +408,8 @@ int ubiblock_create(struct ubi_volume_info *vi) > gd->minors = 1; > gd->first_minor = idr_alloc(&ubiblock_minor_idr, dev, 0, 0, GFP_KERNEL); > if (gd->first_minor < 0) { > - dev_err(disk_to_dev(gd), > - "block: dynamic minor allocation failed"); > + pr_err("ubiblock%d_%d: block: dynamic minor allocation failed\n", > + dev->ubi_num, dev->vol_id); > ret = -ENODEV; > goto out_cleanup_disk; > } > -- > 2.39.2 > > > ______________________________________________________ > Linux MTD discussion mailing list > http://lists.infradead.org/mailman/listinfo/linux-mtd/