Skip to content

Commit

Permalink
nvme: catch errors from nvme_configure_metadata()
Browse files Browse the repository at this point in the history
[ Upstream commit cd9aed6 ]

nvme_configure_metadata() is issuing I/O, so we might incur an I/O
error which will cause the connection to be reset.
But in that case any further probing will race with reset and
cause UAF errors.
So return a status from nvme_configure_metadata() and abort
probing if there was an I/O error.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
hreinecke authored and gregkh committed Dec 20, 2023
1 parent 89fc902 commit 9514925
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions drivers/nvme/host/core.c
Expand Up @@ -1813,16 +1813,18 @@ static int nvme_init_ms(struct nvme_ns *ns, struct nvme_id_ns *id)
return ret;
}

static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)
static int nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)
{
struct nvme_ctrl *ctrl = ns->ctrl;
int ret;

if (nvme_init_ms(ns, id))
return;
ret = nvme_init_ms(ns, id);
if (ret)
return ret;

ns->features &= ~(NVME_NS_METADATA_SUPPORTED | NVME_NS_EXT_LBAS);
if (!ns->ms || !(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED))
return;
return 0;

if (ctrl->ops->flags & NVME_F_FABRICS) {
/*
Expand All @@ -1831,7 +1833,7 @@ static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)
* remap the separate metadata buffer from the block layer.
*/
if (WARN_ON_ONCE(!(id->flbas & NVME_NS_FLBAS_META_EXT)))
return;
return 0;

ns->features |= NVME_NS_EXT_LBAS;

Expand All @@ -1858,6 +1860,7 @@ static void nvme_configure_metadata(struct nvme_ns *ns, struct nvme_id_ns *id)
else
ns->features |= NVME_NS_METADATA_SUPPORTED;
}
return 0;
}

static void nvme_set_queue_limits(struct nvme_ctrl *ctrl,
Expand Down Expand Up @@ -2038,7 +2041,11 @@ static int nvme_update_ns_info_block(struct nvme_ns *ns,
ns->lba_shift = id->lbaf[lbaf].ds;
nvme_set_queue_limits(ns->ctrl, ns->queue);

nvme_configure_metadata(ns, id);
ret = nvme_configure_metadata(ns, id);
if (ret < 0) {
blk_mq_unfreeze_queue(ns->disk->queue);
goto out;
}
nvme_set_chunk_sectors(ns, id);
nvme_update_disk_info(ns->disk, ns, id);

Expand Down

0 comments on commit 9514925

Please sign in to comment.