Skip to content

Commit 551b6bc

Browse files
committed
cmds: avoid possible infinite loop
nvme_fw_download_seq() updates data, size, and offset by xfer even though the actual submitted chunk length is min(xfer, size). If xfer > size, size -= xfer underflows (since size is __u32), potentially causing an infinite loop and out-of-bounds reads. Track the chunk size in a variable and advance/decrement by that value instead. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 82967b9 commit 551b6bc

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

libnvme/src/nvme/cmds.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@ int nvme_fw_download_seq(struct nvme_transport_handle *hdl, bool ish,
2626
nvme_init_mi_cmd_flags(&cmd, ish);
2727

2828
while (size > 0) {
29-
err = nvme_init_fw_download(&cmd, data,
30-
min(xfer, size), offset);
29+
__u32 chunk = min(xfer, size);
30+
31+
err = nvme_init_fw_download(&cmd, data, chunk, offset);
3132
if (err)
3233
break;
3334
err = nvme_submit_admin_passthru(hdl, &cmd);
3435
if (err)
3536
break;
3637

37-
data += xfer;
38-
size -= xfer;
39-
offset += xfer;
38+
data += chunk;
39+
size -= chunk;
40+
offset += chunk;
4041
}
4142

4243
return err;

0 commit comments

Comments
 (0)