diff options
author | Varun Prakash <varun@chelsio.com> | 2022-09-21 00:06:49 +0530 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2022-10-26 13:25:54 +0200 |
commit | d5bb45f47b37d10f010355686b28c9ebacb361d4 (patch) | |
tree | 02e526118dc000a505b91d143c77bc8e2c15774e | |
parent | b79da0080d81063868d1cf4715d67ed5075dd9cc (diff) | |
download | linux-stable-d5bb45f47b37d10f010355686b28c9ebacb361d4.tar.gz linux-stable-d5bb45f47b37d10f010355686b28c9ebacb361d4.tar.bz2 linux-stable-d5bb45f47b37d10f010355686b28c9ebacb361d4.zip |
nvmet-tcp: add bounds check on Transfer Tag
[ Upstream commit b6a545ffa2c192b1e6da4a7924edac5ba9f4ea2b ]
ttag is used as an index to get cmd in nvmet_tcp_handle_h2c_data_pdu(),
add a bounds check to avoid out-of-bounds access.
Signed-off-by: Varun Prakash <varun@chelsio.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r-- | drivers/nvme/target/tcp.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index e3e35b9bd684..2ddbd4f4f628 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -922,10 +922,17 @@ static int nvmet_tcp_handle_h2c_data_pdu(struct nvmet_tcp_queue *queue) struct nvme_tcp_data_pdu *data = &queue->pdu.data; struct nvmet_tcp_cmd *cmd; - if (likely(queue->nr_cmds)) + if (likely(queue->nr_cmds)) { + if (unlikely(data->ttag >= queue->nr_cmds)) { + pr_err("queue %d: received out of bound ttag %u, nr_cmds %u\n", + queue->idx, data->ttag, queue->nr_cmds); + nvmet_tcp_fatal_error(queue); + return -EPROTO; + } cmd = &queue->cmds[data->ttag]; - else + } else { cmd = &queue->connect; + } if (le32_to_cpu(data->data_offset) != cmd->rbytes_done) { pr_err("ttag %u unexpected data offset %u (expected %u)\n", |