linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Sagi Grimberg <sagi@grimberg.me>
To: Anton Eidelman <anton@lightbitslabs.com>,
	linux-nvme@lists.infradead.org,  hch@lst.de,
	keith.busch@intel.com, hare@suse.de
Subject: Re: [PATCH] nvme-multipath: fix crash in nvme_mpath_clear_ctrl_paths
Date: Sun, 3 Nov 2019 06:31:15 -0800	[thread overview]
Message-ID: <c857ecec-7009-174f-ecb7-c43fd77212b9@grimberg.me> (raw)
In-Reply-To: <20191102002755.25165-1-anton@lightbitslabs.com>


> nvme_mpath_clear_ctrl_paths() iterates through
> the ctrl->namespaces list while holding ctrl->scan_lock.
> This does not seem to be the correct way of protecting
> from concurrent list modification.
> 
> Specifically, nvme_scan_work() sorts ctrl->namespaces
> AFTER unlocking scan_lock.
> 
> This may result in the following (rare) crash in ctrl disconnect
> during scan_work:
> 
>      BUG: kernel NULL pointer dereference, address: 0000000000000050
>      Oops: 0000 [#1] SMP PTI
>      CPU: 0 PID: 3995 Comm: nvme 5.3.5-050305-generic
>      RIP: 0010:nvme_mpath_clear_current_path+0xe/0x90 [nvme_core]
>      ...
>      Call Trace:
>       nvme_mpath_clear_ctrl_paths+0x3c/0x70 [nvme_core]
>       nvme_remove_namespaces+0x35/0xe0 [nvme_core]
>       nvme_do_delete_ctrl+0x47/0x90 [nvme_core]
>       nvme_sysfs_delete+0x49/0x60 [nvme_core]
>       dev_attr_store+0x17/0x30
>       sysfs_kf_write+0x3e/0x50
>       kernfs_fop_write+0x11e/0x1a0
>       __vfs_write+0x1b/0x40
>       vfs_write+0xb9/0x1a0
>       ksys_write+0x67/0xe0
>       __x64_sys_write+0x1a/0x20
>       do_syscall_64+0x5a/0x130
>       entry_SYSCALL_64_after_hwframe+0x44/0xa9
>      RIP: 0033:0x7f8d02bfb154
> 
> Fix:
> After taking scan_lock in nvme_mpath_clear_ctrl_paths()
> down_read(&ctrl->namespaces_rwsem) as well to make list traversal safe.
> This will not cause deadlocks because taking scan_lock never happens
> while holding the namespaces_rwsem.
> Moreover, scan work downs namespaces_rwsem in the same order.

Thanks Anton, this looks good to me,

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

  reply	other threads:[~2019-11-03 14:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-02  0:27 [PATCH] nvme-multipath: fix crash in nvme_mpath_clear_ctrl_paths Anton Eidelman
2019-11-03 14:31 ` Sagi Grimberg [this message]
2019-11-04 23:55 ` Christoph Hellwig

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=c857ecec-7009-174f-ecb7-c43fd77212b9@grimberg.me \
    --to=sagi@grimberg.me \
    --cc=anton@lightbitslabs.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=keith.busch@intel.com \
    --cc=linux-nvme@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).