From: Benjamin Coddington <bcodding@redhat.com>
To: Trond Myklebust <trondmy@kernel.org>,
Anna Schumaker <anna@kernel.org>,
Chuck Lever <chuck.lever@oracle.com>
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] nfs/blocklayout: Don't attempt unregister for invalid block device
Date: Mon, 18 Nov 2024 17:40:40 -0500 [thread overview]
Message-ID: <eeb62d9260f2e9b61ff5e186eec0048e51bc8758.1731969260.git.bcodding@redhat.com> (raw)
In-Reply-To: <cover.1731969260.git.bcodding@redhat.com>
Since commit d869da91cccb, an unmount of a pNFS SCSI layout-enabled NFS
will dereference a NULL block_device in:
bl_unregister_scsi+0x16/0xe0 [blocklayoutdriver]
bl_free_device+0x70/0x80 [blocklayoutdriver]
bl_free_deviceid_node+0x12/0x30 [blocklayoutdriver]
nfs4_put_deviceid_node+0x60/0xc0 [nfsv4]
nfs4_deviceid_purge_client+0x132/0x190 [nfsv4]
unset_pnfs_layoutdriver+0x59/0x60 [nfsv4]
nfs4_destroy_server+0x36/0x70 [nfsv4]
nfs_free_server+0x23/0xe0 [nfs]
deactivate_locked_super+0x30/0xb0
cleanup_mnt+0xba/0x150
task_work_run+0x59/0x90
syscall_exit_to_user_mode+0x217/0x220
do_syscall_64+0x8e/0x160
This happens because even though we were able to create the
nfs4_deviceid_node, the lookup for the device was unable to attach the
block device to the pnfs_block_dev.
If we never found a block device to register, we can avoid this case with
the PNFS_BDEV_REGISTERED flag. Move the deref behind the test for the
flag.
Fixes: d869da91cccb ("nfs/blocklayout: Fix premature PR key unregistration")
Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
---
fs/nfs/blocklayout/dev.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/fs/nfs/blocklayout/dev.c b/fs/nfs/blocklayout/dev.c
index 6252f4447945..7ae79814f4ff 100644
--- a/fs/nfs/blocklayout/dev.c
+++ b/fs/nfs/blocklayout/dev.c
@@ -16,13 +16,16 @@
static void bl_unregister_scsi(struct pnfs_block_dev *dev)
{
- struct block_device *bdev = file_bdev(dev->bdev_file);
- const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
+ struct block_device *bdev;
+ const struct pr_ops *ops;
int status;
if (!test_and_clear_bit(PNFS_BDEV_REGISTERED, &dev->flags))
return;
+ bdev = file_bdev(dev->bdev_file);
+ ops = bdev->bd_disk->fops->pr_ops;
+
status = ops->pr_register(bdev, dev->pr_key, 0, false);
if (status)
trace_bl_pr_key_unreg_err(bdev, dev->pr_key, status);
--
2.47.0
next prev parent reply other threads:[~2024-11-18 22:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-18 22:40 [PATCH 0/2] two fixes for pNFS SCSI device handling Benjamin Coddington
2024-11-18 22:40 ` Benjamin Coddington [this message]
2024-11-19 12:42 ` [PATCH 1/2] nfs/blocklayout: Don't attempt unregister for invalid block device Christoph Hellwig
2024-11-19 13:46 ` Benjamin Coddington
2024-11-18 22:40 ` [PATCH 2/2] nfs/blocklayout: Limit repeat device registration on failure Benjamin Coddington
2024-11-19 12:42 ` Christoph Hellwig
2024-11-20 14:09 [PATCH v2 0/2] two fixes for pNFS SCSI device handling Benjamin Coddington
2024-11-20 14:09 ` [PATCH 1/2] nfs/blocklayout: Don't attempt unregister for invalid block device Benjamin Coddington
2024-11-20 15:07 ` Chuck Lever
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=eeb62d9260f2e9b61ff5e186eec0048e51bc8758.1731969260.git.bcodding@redhat.com \
--to=bcodding@redhat.com \
--cc=anna@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=trondmy@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
Powered by JetHome