Skip to content

Commit 84909f7

Browse files
shroffnikeithbusch
authored andcommitted
nvmet: use kzalloc instead of ZERO_PAGE in nvme_execute_identify_ns_nvm()
The nvme_execute_identify_ns_nvm function uses ZERO_PAGE for copying SG list with all zeros. As ZERO_PAGE would not necessarily return the virtual-address of the zero page, we need to first convert the page address to kernel virtual-address and then use it as source address for copying the data to SG list with all zeros. Using return address of ZERO_PAGE(0) as source address for copying data to SG list would fill the target buffer with random/garbage value and causes the undesired side effect. As other identify implemenations uses kzalloc for allocating a zero filled buffer, we decided use kzalloc for allocating a zero filled buffer in nvme_execute_identify_ns_nvm function and then use this buffer for copying all zeros to SG list buffers. So esentially, we now avoid using ZERO_PAGE. Reported-by: Yi Zhang <[email protected]> Fixes: 64a5108 ("nvmet: implement id ns for nvm command set") Link: https://lore.kernel.org/all/CAHj4cs8OVyxmn4XTvA=y4uQ3qWpdw-x3M3FSUYr-KpE-nhaFEA@mail.gmail.com/ Signed-off-by: Nilay Shroff <[email protected]> Tested-by: Yi Zhang <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent ec9b3ac commit 84909f7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/nvme/target/admin-cmd.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,13 +902,18 @@ static void nvmet_execute_identify_ctrl_nvm(struct nvmet_req *req)
902902
static void nvme_execute_identify_ns_nvm(struct nvmet_req *req)
903903
{
904904
u16 status;
905+
struct nvme_id_ns_nvm *id;
905906

906907
status = nvmet_req_find_ns(req);
907908
if (status)
908909
goto out;
909910

910-
status = nvmet_copy_to_sgl(req, 0, ZERO_PAGE(0),
911-
NVME_IDENTIFY_DATA_SIZE);
911+
id = kzalloc(sizeof(*id), GFP_KERNEL);
912+
if (!id) {
913+
status = NVME_SC_INTERNAL;
914+
goto out;
915+
}
916+
status = nvmet_copy_to_sgl(req, 0, id, sizeof(*id));
912917
out:
913918
nvmet_req_complete(req, status);
914919
}

0 commit comments

Comments
 (0)