From: Chuck Lever <chuck.lever@oracle.com>
To: Benjamin Coddington <bcodding@redhat.com>
Cc: Trond Myklebust <trondmy@kernel.org>,
Anna Schumaker <anna@kernel.org>,
linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH 1/2] nfs/blocklayout: Don't attempt unregister for invalid block device
Date: Wed, 20 Nov 2024 10:07:06 -0500 [thread overview]
Message-ID: <Zz37GmKULmPYUlee@tissot.1015granger.net> (raw)
In-Reply-To: <4e9690bed3d95d1c4cf2a7b1cc76f7cd1b333847.1732111502.git.bcodding@redhat.com>
On Wed, Nov 20, 2024 at 09:09:34AM -0500, Benjamin Coddington wrote:
> Since commit d869da91cccb ("nfs/blocklayout: Fix premature PR key
> unregistration") an unmount of a pNFS SCSI layout-enabled NFS may
> 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>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> ---
> fs/nfs/blocklayout/dev.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/fs/nfs/blocklayout/dev.c b/fs/nfs/blocklayout/dev.c
> index 6252f4447945..cab8809f0e0f 100644
> --- a/fs/nfs/blocklayout/dev.c
> +++ b/fs/nfs/blocklayout/dev.c
> @@ -20,9 +20,6 @@ static void bl_unregister_scsi(struct pnfs_block_dev *dev)
> const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
> int status;
>
> - if (!test_and_clear_bit(PNFS_BDEV_REGISTERED, &dev->flags))
> - return;
> -
> status = ops->pr_register(bdev, dev->pr_key, 0, false);
> if (status)
> trace_bl_pr_key_unreg_err(bdev, dev->pr_key, status);
> @@ -58,7 +55,8 @@ static void bl_unregister_dev(struct pnfs_block_dev *dev)
> return;
> }
>
> - if (dev->type == PNFS_BLOCK_VOLUME_SCSI)
> + if (dev->type == PNFS_BLOCK_VOLUME_SCSI &&
> + test_and_clear_bit(PNFS_BDEV_REGISTERED, &dev->flags))
> bl_unregister_scsi(dev);
> }
>
> --
> 2.47.0
>
Reviewed-by: Chuck Lever <chuck.lever@oracle.com>
--
Chuck Lever
next prev parent reply other threads:[~2024-11-20 15:07 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2024-11-20 14:09 ` [PATCH 2/2] nfs/blocklayout: Limit repeat device registration on failure Benjamin Coddington
2024-11-20 15:22 ` Chuck Lever
2024-11-21 15:11 ` Benjamin Coddington
2024-11-21 15:32 ` Chuck Lever
-- strict thread matches above, loose matches on Subject: below --
2024-11-18 22:40 [PATCH 0/2] two fixes for pNFS SCSI device handling Benjamin Coddington
2024-11-18 22:40 ` [PATCH 1/2] nfs/blocklayout: Don't attempt unregister for invalid block device Benjamin Coddington
2024-11-19 12:42 ` Christoph Hellwig
2024-11-19 13:46 ` Benjamin Coddington
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=Zz37GmKULmPYUlee@tissot.1015granger.net \
--to=chuck.lever@oracle.com \
--cc=anna@kernel.org \
--cc=bcodding@redhat.com \
--cc=hch@lst.de \
--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
all inboxes | Powered by JetHome®