From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 E907728686 for ; Tue, 11 Aug 2026 13:10:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786453817; cv=none; b=gojeywP2tFkzearDjCSqC8rsLUSLyCyu3Rp/mPgi8D61X1RGK1XoX5IXceNcukWQVoIO6X+I2QZdHJ9SLKmuV2MUC5mfRYvWxiUsAP/8gSVFEhzyZ+3wclLoTgQ7gtiTNm4LxrbesBEPbLx/oe/DglhhbONn/9V6s7EL9Kh9U8Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786453817; c=relaxed/simple; bh=j7WnydQxYbvbPUlODJfyip7zbY7BcraVR6pkaWh/fuU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GeuhHrTZLfTLB3TRz5a/saip/9HlGi70qkcE6lVX8EGhDsUfOAtLQzkr2vYl866nD4/+yv+U3t7izcYiGMJr32ndpW4C5D3a1G/SMWeCKocdA44IWcygxbFPTGPYVv4z6dDDbDxnW4PIob2QixlNmgB5pvjZYDo6+nPcufLOBR4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nbw1e4+U; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nbw1e4+U" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 333681F000E9; Tue, 11 Aug 2026 13:10:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786453815; bh=kUTc7Zcj155tJxd99raX4BSfyhzHFcuoERsqLcAp6s8=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=nbw1e4+U+WLxrNhN/6gi1lFWtY8ljZm7Vv2PhKDqTJBEX4Xny0SAB2PJOP28w+f8n 4X2yx7IQQJD6lAGeCrJvMR0xLzEHOoGydCaeiHxBJFVRfEvgm1a1w5nbq1HKU4x3V6 OvuXm2AHo7R9714oYew8uxNPGx287nfpEak+x+f+bMPQ4rS1kUo2mri97/B9UWTpYE 9g7/JRXY8uZY2dGgAuAlgWKWuhElALL00iz01qLlbRYVHhVdbhJxG6xlRGqmX7eaJR NDVOyn3dFYkLNSuNQEd4DOWfdGHnwaNDzZCIhIHFXX+ehReZQnOlbtrUkSY3EWeIuO fkfEiOWi0xLOQ== Date: Tue, 11 Aug 2026 15:10:10 +0200 From: Niklas Cassel To: Rihyeon Kim Cc: kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, axboe@kernel.dk, justin.tee@broadcom.com, nareshgottumukkala83@gmail.com, paul.ely@broadcom.com, kch@nvidia.com, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] nvme-fc: fix double free of fabrics options when nvme_add_ctrl() fails Message-ID: References: <6a7a83ac.01d0871a.3a0d52.00bb.GAE@google.com> <20260811125310.165487-1-rihyeon8648@gmail.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: <20260811125310.165487-1-rihyeon8648@gmail.com> On Tue, Aug 11, 2026 at 09:53:10PM +0900, Rihyeon Kim wrote: (snip) > diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c > index 04363b9c4489..e4d0eeccd846 100644 > --- a/drivers/nvme/host/fc.c > +++ b/drivers/nvme/host/fc.c > @@ -3601,6 +3601,9 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts, > nvme_uninit_ctrl(&ctrl->ctrl); > > out_put_ctrl: > + /* nvme_add_ctrl() failures skip the clear in fail_ctrl: above */ > + ctrl->ctrl.opts = NULL; > + > /* Remove core ctrl ref. */ > nvme_put_ctrl(&ctrl->ctrl); > > > base-commit: 0ce37745d4bfbc493f718169c3974898ffec8ee7 > -- > 2.43.0 > > Wouldn't a nicer fix be to change nvme_fc_ctrl_free() to look more like nvme_tcp_ctrl_free(), i.e. something like: diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c index 04363b9c4489..2b4c222995ea 100644 --- a/drivers/nvme/host/fc.c +++ b/drivers/nvme/host/fc.c @@ -2359,19 +2359,22 @@ nvme_fc_ctrl_free(struct kref *ref) container_of(ref, struct nvme_fc_ctrl, ref); unsigned long flags; + if (list_empty(&ctrl->ctrl_list)) + goto free_ctrl; + /* remove from rport list */ spin_lock_irqsave(&ctrl->rport->lock, flags); list_del(&ctrl->ctrl_list); spin_unlock_irqrestore(&ctrl->rport->lock, flags); - kfree(ctrl->queues); - put_device(ctrl->dev); nvme_fc_rport_put(ctrl->rport); ida_free(&nvme_fc_ctrl_cnt, ctrl->cnum); - if (ctrl->ctrl.opts) - nvmf_free_options(ctrl->ctrl.opts); + + nvmf_free_options(ctrl->ctrl.opts); +free_ctrl: + kfree(ctrl->queues); kfree(ctrl); } @@ -3593,8 +3596,6 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts, cancel_work_sync(&ctrl->ctrl.reset_work); cancel_delayed_work_sync(&ctrl->connect_work); - ctrl->ctrl.opts = NULL; - if (ctrl->ctrl.admin_tagset) nvme_remove_admin_tag_set(&ctrl->ctrl); /* initiate nvme ctrl ref counting teardown */ However, I'm not familar with the fc driver, so this suggestion is untested. Kind regards, Niklas