Skip to content

Commit 85eeda3

Browse files
committed
ioctl: fix nvme_directive_recv_stream_status
Take the nr_entries parameter for the returned data structure length into account. Signed-off-by: Dennis Maisenbacher <[email protected]>
1 parent 4cef519 commit 85eeda3

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/nvme/ioctl.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#ifndef _LIBNVME_IOCTL_H
1111
#define _LIBNVME_IOCTL_H
1212

13+
#include <errno.h>
1314
#include <stddef.h>
1415
#include <sys/ioctl.h>
1516

@@ -4041,6 +4042,11 @@ static inline int nvme_directive_recv_stream_status(int fd, __u32 nsid,
40414042
unsigned int nr_entries,
40424043
struct nvme_streams_directive_status *id)
40434044
{
4045+
if (nr_entries > NVME_STREAM_ID_MAX) {
4046+
errno = EINVAL;
4047+
return -1;
4048+
}
4049+
40444050
struct nvme_directive_recv_args args = {
40454051
.result = NULL,
40464052
.data = id,
@@ -4051,7 +4057,7 @@ static inline int nvme_directive_recv_stream_status(int fd, __u32 nsid,
40514057
.doper = NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_STATUS,
40524058
.dtype = NVME_DIRECTIVE_DTYPE_STREAMS,
40534059
.cdw12 = 0,
4054-
.data_len = sizeof(*id),
4060+
.data_len = (__u32)(sizeof(*id) + nr_entries * sizeof(__le16)),
40554061
.dspec = 0,
40564062
};
40574063

src/nvme/types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
* @NVMF_TSAS_SIZE: Max Transport Specific Address Subtype size
117117
* @NVME_ZNS_CHANGED_ZONES_MAX: Max number of zones in the changed zones log
118118
* page
119+
* @NVME_STREAM_ID_MAX: Max number of stream IDs
119120
*/
120121
enum nvme_constants {
121122
NVME_NSID_ALL = 0xffffffff,
@@ -147,6 +148,7 @@ enum nvme_constants {
147148
NVMF_TRADDR_SIZE = 256,
148149
NVMF_TSAS_SIZE = 256,
149150
NVME_ZNS_CHANGED_ZONES_MAX = 511,
151+
NVME_STREAM_ID_MAX = 0xffff,
150152
};
151153

152154
/**

0 commit comments

Comments
 (0)