mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Keith Busch <kbusch@kernel.org>
To: Yuqiang Sun <izaiahsun@gmail.com>
Cc: hch@lst.de, sagi@grimberg.me, axboe@kernel.dk,
	john.garry@linux.dev, nilay@linux.ibm.com,
	linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v2] nvme: Do not drop the cdev reference twice when cdev_device_add() fails
Date: Mon, 2 Nov 2026 10:29:04 -0700	[thread overview]
Message-ID: <aujIYJZvZzJrTrne@kbusch-mbp> (raw)
In-Reply-To: <20261102095015.36448-1-izaiahsun@gmail.com>

On Mon, Nov 02, 2026 at 05:50:15PM +0800, Yuqiang Sun wrote:
> Since commit 9952f3882ecb ("nvme: fix cdev lifetime"),
> nvme_add_ns_cdev() and nvme_add_ns_head_cdev() take a reference to the
> namespace (or namespace head) before calling nvme_cdev_add(), to be
> dropped by the char device's release, nvme_cdev_rel(), and drop it
> themselves when nvme_cdev_add() fails. But when cdev_device_add()
> fails, nvme_cdev_add() has already put the device, and nvme_cdev_rel()
> has already dropped that reference: the caller drops it a second time.
> 
> With one allocation failure injected into cdev_device_add() for a
> namespace on an NVMe over loop controller, deleting the controller
> gives, with native multipath:
> 
>   BUG: KASAN: slab-use-after-free in nvme_put_ns_head+0x21/0x140
>   Write of size 4 at addr ff1100000a4ea078 by task init/1
>    nvme_put_ns_head
>    nvme_put_ns
>    nvme_remove_namespaces
>    nvme_do_delete_ctrl
>    nvme_delete_ctrl_sync
>    nvme_sysfs_delete
>   Freed by task 1:
>    kfree
>    nvme_ns_remove
>    nvme_remove_namespaces
>   refcount_t: underflow; use-after-free.
> 
> Take the reference in nvme_cdev_add() instead, right before
> cdev_device_add(), and let the callers neither take nor drop it. Add
> nvme_is_ns_cdev() for the check that nvme_cdev_rel() and nvme_cdev_add()
> now share.

Thanks, applied to nvme-7.4.

      parent reply	other threads:[~2026-11-02 17:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02  9:50 Yuqiang Sun
2026-11-02  9:52 ` Yuqiang Sun
2026-11-02 17:29 ` Keith Busch [this message]

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=aujIYJZvZzJrTrne@kbusch-mbp \
    --to=kbusch@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=izaiahsun@gmail.com \
    --cc=john.garry@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=nilay@linux.ibm.com \
    --cc=sagi@grimberg.me \
    --cc=stable@vger.kernel.org \
    /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®