mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Wagner <dwagner@suse.de>
To: Christoph Hellwig <hch@lst.de>
Cc: James Smart <james.smart@broadcom.com>,
	 Sagi Grimberg <sagi@grimberg.me>,
	Chaitanya Kulkarni <kch@nvidia.com>,
	 Hannes Reinecke <hare@suse.de>, Keith Busch <kbusch@kernel.org>,
	linux-nvme@lists.infradead.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH 02/11] nvmet-fcloop: add ref counting to lport
Date: Thu, 6 Mar 2025 10:26:36 +0100	[thread overview]
Message-ID: <0efdf3e7-e49e-4e2f-846b-b072169de318@flourine.local> (raw)
In-Reply-To: <20250305141740.GC18065@lst.de>

On Wed, Mar 05, 2025 at 03:17:40PM +0100, Christoph Hellwig wrote:
> On Wed, Feb 26, 2025 at 07:45:54PM +0100, Daniel Wagner wrote:
> > +static void
> > +fcloop_lport_free(struct kref *ref)
> > +{
> > +	struct fcloop_lport *lport =
> > +		container_of(ref, struct fcloop_lport, ref);
> > +	unsigned long flags;
> > +
> > +	spin_lock_irqsave(&fcloop_lock, flags);
> > +	list_del(&lport->lport_list);
> > +	spin_unlock_irqrestore(&fcloop_lock, flags);
> > +
> > +	kfree(lport);
> 
> Maybe it's just me, but I find the kref a really horrible pattern over
> usig a simple refcount_t.

There was already some kref usage in the fc code, that's why I started
to use it. But I agree there is not much to be gained from the kref
wrappers. I'll replace them.

> Otherwise adding proper refcounting looks fine.

BTW, I found a bunch more places which need to do proper ref counting. I
have now a version which works pretty good. Though there is one
case which gives me an UAF:

  setup target
  setup host
  connect
  loop
    remove target
    wait for host connecting state
    add target
    wait for host live state

When fcloop has no in flight commands and the target is removed, fcloop
will unregister the localport now. But the nvme-fc driver just assumes
that the port is always there and just sends down new commands
independend of the port status:

nvme_fc_start_fcp_op()
{
[...]

	ret = ctrl->lport->ops->fcp_io(&ctrl->lport->localport,
					&ctrl->rport->remoteport,
					queue->lldd_handle, &op->fcp_req);
[...]
}

There is nothing which updates the ctrl in nvme_fc_unregister_localport.
Not really sure what to do here. fcloop obviously is now behaving
differently to the hw drivers. But still, this looks very fragile that
there is no sort of synchronization between port unregistration and ctrl
state.

  reply	other threads:[~2025-03-06  9:26 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-26 18:45 [PATCH 00/11] nvmet-fcloop: track resources via reference counting Daniel Wagner
2025-02-26 18:45 ` [PATCH 01/11] nvmet-fcloop: remove nport from list on last user Daniel Wagner
2025-02-28  7:04   ` Hannes Reinecke
2025-03-05 14:16   ` Christoph Hellwig
2025-02-26 18:45 ` [PATCH 02/11] nvmet-fcloop: add ref counting to lport Daniel Wagner
2025-02-28  7:05   ` Hannes Reinecke
2025-03-05 14:17   ` Christoph Hellwig
2025-03-06  9:26     ` Daniel Wagner [this message]
2025-03-06 10:06       ` Daniel Wagner
2025-02-26 18:45 ` [PATCH 03/11] nvmet-fcloop: refactor fcloop_nport_alloc Daniel Wagner
2025-02-28  7:11   ` Hannes Reinecke
2025-02-28  7:56     ` Daniel Wagner
2025-03-05 14:18   ` Christoph Hellwig
2025-02-26 18:45 ` [PATCH 04/11] nvmet-fcloop: track ref counts for nports Daniel Wagner
2025-02-28  7:19   ` Hannes Reinecke
2025-02-28  8:09     ` Daniel Wagner
2025-02-28  8:18     ` Daniel Wagner
2025-02-26 18:45 ` [PATCH 05/11] nvmet-fcloop: track tport with ref counting Daniel Wagner
2025-02-28  7:27   ` Hannes Reinecke
2025-02-28  8:30     ` Daniel Wagner
2025-02-28 14:31       ` Daniel Wagner
2025-02-26 18:45 ` [PATCH 06/11] nvmet-fcloop: track rport " Daniel Wagner
2025-02-28  7:29   ` Hannes Reinecke
2025-02-26 18:45 ` [PATCH 07/11] nvmet-fc: update tgtport ref per assoc Daniel Wagner
2025-02-28  7:30   ` Hannes Reinecke
2025-02-26 18:46 ` [PATCH 08/11] nvmet-fc: take tgtport reference only once Daniel Wagner
2025-02-28  7:34   ` Hannes Reinecke
2025-02-28  8:45     ` Daniel Wagner
2025-02-26 18:46 ` [PATCH 09/11] nvmet-fc: free pending reqs on tgtport unregister Daniel Wagner
2025-02-28  7:35   ` Hannes Reinecke
2025-02-26 18:46 ` [PATCH 10/11] nvmet-fc: inline nvmet_fc_delete_assoc Daniel Wagner
2025-02-28  7:36   ` Hannes Reinecke
2025-02-26 18:46 ` [PATCH 11/11] nvmet-fc: inline nvmet_fc_free_hostport Daniel Wagner
2025-02-28  7:37   ` Hannes Reinecke
2025-02-27 16:30 ` [PATCH 00/11] nvmet-fcloop: track resources via reference counting Daniel Wagner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0efdf3e7-e49e-4e2f-846b-b072169de318@flourine.local \
    --to=dwagner@suse.de \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=james.smart@broadcom.com \
    --cc=kbusch@kernel.org \
    --cc=kch@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®