nvme: fix potential invalid pointer dereference
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 innvme_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
@@ -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
Quoted 11 lines · Maurizio Lombardi
If
nvme_alloc_admin_tag_set()fails, theadmin_qandfabrics_qpointers are left with an invalid, non-NULL value;
Other functions may then check the pointers' value and dereference them, like it happens innvme_probe()->out_disable: ->nvme_dev_remove_admin().Fix the bug by setting
admin_qandfabrics_qto NULL in case of error. Also fix a NULL pointer dereference (thectrl->admin_tagsetpointer 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.
nvme_alloc_io_tag_set needs the same fix.
po 30. 1. 2023 v 11:06 odesílatel Christoph Hellwig <[email protected]> napsal:
Quoted 3 lines
nvme_alloc_io_tag_setneeds the same fix.
Yep, I'm going to send a patch.
Maurizio
Quoted 6 lines · Maurizio Lombardi
If
nvme_alloc_admin_tag_set()fails, theadmin_qandfabrics_qpointers are left with an invalid, non-NULL value;
Other functions may then check the pointers' value and dereference them, like it happens innvme_probe()->out_disable: ->nvme_dev_remove_admin().
Quoted 8 lines
Fix the bug by setting
admin_qandfabrics_qto NULL in case of error. Also fix a NULL pointer dereference (thectrl->admin_tagsetpointer 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).Signed-off-by Maurizio Lombardi <[email protected]>---
Looks good.
-ck
Thanks,
applied to nvme-6.2.