]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
nvmet: fix refcount leak in nvmet_sq_create()
authorWentao Liang <vulab@iscas.ac.cn>
Tue, 9 Jun 2026 09:55:05 +0000 (09:55 +0000)
committerKeith Busch <kbusch@kernel.org>
Tue, 9 Jun 2026 16:42:23 +0000 (09:42 -0700)
In nvmet_sq_create(), a reference on the ctrl is taken
via kref_get_unless_zero() before calling nvmet_check_sqid().
If nvmet_check_sqid() fails, the function returns the error
directly without releasing the reference, leading to a leak.

Fix this by jumping to the "ctrl_put" label, which already
performs the necessary nvmet_ctrl_put(ctrl). This ensures the
reference is properly released on this error path.

Cc: stable@vger.kernel.org
Fixes: 1eb380caf527 ("nvmet: Introduce nvmet_sq_create() and nvmet_cq_create()")
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
Signed-off-by: Keith Busch <kbusch@kernel.org>
drivers/nvme/target/core.c

index 62dd59b9aa4f1c9bfd32361e3f06ab1520424ce8..4477c4d6b1eed50a9f5cd233ac6bfcee25972d09 100644 (file)
@@ -944,7 +944,7 @@ u16 nvmet_sq_create(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq,
 
        status = nvmet_check_sqid(ctrl, sqid, true);
        if (status != NVME_SC_SUCCESS)
-               return status;
+               goto ctrl_put;
 
        ret = nvmet_sq_init(sq, cq);
        if (ret) {