From cc1efaaebb409426bb725c015b534a1959f94e29 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Thu, 4 Oct 2018 22:08:01 -0600 Subject: [PATCH] nvme-cli: fix ioctl argument The command argument for ioctl is unsigned long, not int. Fix all the places that we pass cmd through to the ioctl call to handle it as an unsigned long. This prevents a sign extension bug when IOCTL commands encode with the top bit set. --- nvme-ioctl.c | 6 ++++-- nvme-ioctl.h | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/nvme-ioctl.c b/nvme-ioctl.c index 1866f438..be0823df 100644 --- a/nvme-ioctl.c +++ b/nvme-ioctl.c @@ -81,7 +81,8 @@ int nvme_get_nsid(int fd) return ioctl(fd, NVME_IOCTL_ID); } -int nvme_submit_passthru(int fd, int ioctl_cmd, struct nvme_passthru_cmd *cmd) +int nvme_submit_passthru(int fd, unsigned long ioctl_cmd, + struct nvme_passthru_cmd *cmd) { return ioctl(fd, ioctl_cmd, cmd); } @@ -96,7 +97,8 @@ static int nvme_submit_io_passthru(int fd, struct nvme_passthru_cmd *cmd) return ioctl(fd, NVME_IOCTL_IO_CMD, cmd); } -int nvme_passthru(int fd, int ioctl_cmd, __u8 opcode, __u8 flags, __u16 rsvd, +int nvme_passthru(int fd, unsigned long ioctl_cmd, __u8 opcode, + __u8 flags, __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11, __u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15, __u32 data_len, void *data, __u32 metadata_len, diff --git a/nvme-ioctl.h b/nvme-ioctl.h index bb06f825..3fb740c3 100644 --- a/nvme-ioctl.h +++ b/nvme-ioctl.h @@ -9,9 +9,10 @@ int nvme_get_nsid(int fd); /* Generic passthrough */ -int nvme_submit_passthru(int fd, int ioctl_cmd, struct nvme_passthru_cmd *cmd); +int nvme_submit_passthru(int fd, unsigned long ioctl_cmd, + struct nvme_passthru_cmd *cmd); -int nvme_passthru(int fd, int ioctl_cmd, __u8 opcode, __u8 flags, +int nvme_passthru(int fd, unsigned long ioctl_cmd, __u8 opcode, __u8 flags, __u16 rsvd, __u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11, __u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15, -- 2.50.1