Skip to contentSkip to conversation

nvme: fix potential invalid pointer dereference

PATCH Applied Maurizio Lombardi 5 participants 6 messages Jan 27, 2023 – Feb 1, 2023 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: fix potential invalid pointer dereference

If nvme_alloc_admin_tag_set() fails, the admin_q and fabrics_q pointers are left with an invalid, non-NULL value;
Other functions may then check the pointers' value and dereference them, like it happens in
nvme_probe() -> out_disable: -> nvme_dev_remove_admin().

Fix the bug by setting admin_q and fabrics_q to NULL in case of error. Also fix a NULL pointer dereference (the ctrl->admin_tagset pointer is only initialized just before returning success; therefore, in the error code path, blk_mq_free_tag_set() must be called against the "set" variable).

---
 drivers/nvme/host/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nvme/host/core.c +3 -1
index 7be562a4e1aa..6b277b80a09c 100644
@@ -4921,7 +4921,9 @@ int nvme_alloc_admin_tag_set(struct nvme_ctrl *ctrl, struct blk_mq_tag_set *set,
 	blk_mq_destroy_queue(ctrl->admin_q);
 	blk_put_queue(ctrl->admin_q);
 out_free_tagset:
-	blk_mq_free_tag_set(ctrl->admin_tagset);
+	blk_mq_free_tag_set(set);
+	ctrl->admin_q = NULL;
+	ctrl->fabrics_q = NULL;
 	return ret;
 }
 EXPORT_SYMBOL_GPL(nvme_alloc_admin_tag_set);
Signature · 1 line
2.31.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Maurizio Lombardi

If nvme_alloc_admin_tag_set() fails, the admin_q and fabrics_q pointers are left with an invalid, non-NULL value;
Other functions may then check the pointers' value and dereference them, like it happens in
nvme_probe() -> out_disable: -> nvme_dev_remove_admin().

Fix the bug by setting admin_q and fabrics_q to NULL in case of error. Also fix a NULL pointer dereference (the ctrl->admin_tagset pointer is only initialized just before returning success; therefore, in the error code path, blk_mq_free_tag_set() must be called against the "set" variable).

Looks good.

#3 lore raw

po 30. 1. 2023 v 11:06 odesílatel Christoph Hellwig <[email protected]> napsal:

Quoted 3 lines

nvme_alloc_io_tag_set needs the same fix.

Yep, I'm going to send a patch.

Maurizio

Reviewed-by on v1 1/1
#4 lore raw
In reply to Maurizio Lombardi
Quoted 6 lines · Maurizio Lombardi

If nvme_alloc_admin_tag_set() fails, the admin_q and fabrics_q pointers are left with an invalid, non-NULL value;
Other functions may then check the pointers' value and dereference them, like it happens in
nvme_probe() -> out_disable: -> nvme_dev_remove_admin().

Quoted 8 lines

Fix the bug by setting admin_q and fabrics_q to NULL in case of error. Also fix a NULL pointer dereference (the ctrl->admin_tagset pointer is only initialized just before returning success; therefore, in the error code path, blk_mq_free_tag_set() must be called against the "set" variable).

---

Looks good.

-ck