nvmet-rdma: Fix a possible uninitialized variable dereference
Subsystems (3)
Sagi Grimberg
maintainerPATCH v2 1/1 nvmet-rdma: Fix a possible uninitialized variable dereference
When handling a new recv command, we grab a new rsp resource and check for the queue state being live. In case the queue is not in live state, we simply restore the rsp back to the free list. However in this flow we didn't set rsp->queue yet, so we cannot dereference it.
Instead, make sure to initialize rsp->queue (and other rsp members) as soon as possible so we won't reference uninitialized variables.
---
- v1 broke srq, this one doesn't
drivers/nvme/target/rdma.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/nvme/target/rdma.c +3 -5
@@ -703,11 +703,6 @@ static void nvmet_rdma_handle_command(struct nvmet_rdma_queue *queue, {u16 status; - cmd->queue = queue; - cmd->n_rdma =0 ; - cmd->req.port = queue->port; - -ib_dma_sync_single_for_cpu (queue->dev->device, cmd->cmd->sge[0 ].addr, cmd->cmd->sge[0 ].length,DMA_FROM_DEVICE );
@@ -760,9 +755,12 @@ static void nvmet_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc) cmd->queue = queue; rsp =nvmet_rdma_get_rsp (queue); + rsp->queue = queue; rsp->cmd = cmd; rsp->flags =0 ; rsp->req.cmd = cmd->nvme_cmd; + rsp->req.port = queue->port; + rsp->n_rdma =0 ;if (unlikely (queue->state !=NVMET_RDMA_Q_LIVE )) {unsigned long flags;
Signature · 1 line
2.7.4
Christoph Hellwig
maintainerPATCH v2 1/1 nvmet-rdma: Fix a possible uninitialized variable dereference
Quoted 7 lines · Sagi Grimberg
When handling a new recv command, we grab a new rsp resource and check for the queue state being live. In case the queue is not in live state, we simply restore the rsp back to the free list. However in this flow we didn't set
rsp->queueyet, so we cannot dereference it.Instead, make sure to initialize
rsp->queue(and other rsp members) as soon as possible so we won't reference uninitialized variables.
Looks good,
PATCH v2 1/1 nvmet-rdma: Fix a possible uninitialized variable dereference
In reply to Sagi GrimbergPatch looks good.
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Sagi Grimberg
Sent: 13 March 2017 19:10
To: linux-nvme at lists.infradead.org; linux-rdma at vger.kernel.org
Cc: Christoph Hellwig <hch at lst.de>
Subject: [PATCH v2] nvmet-rdma: Fix a possible uninitialized variable dereference
When handling a new recv command, we grab a new rsp resource and check for the queue state being live. In case the queue is not in live state, we simply restore the rsp back to the free list. However in this flow we didn't set rsp->queue yet, so we cannot dereference it.
Instead, make sure to initialize rsp->queue (and other rsp members) as soon as possible so we won't reference uninitialized variables.
---
- v1 broke srq, this one doesn't
drivers/nvme/target/rdma.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/nvme/target/rdma.c +3 -5
@@ -703,11 +703,6 @@ static void nvmet_rdma_handle_command(struct nvmet_rdma_queue *queue, {u16 status; - cmd->queue = queue; - cmd->n_rdma =0 ; - cmd->req.port = queue->port; - -ib_dma_sync_single_for_cpu (queue->dev->device, cmd->cmd->sge[0 ].addr, cmd->cmd->sge[0 ].length,DMA_FROM_DEVICE );
@@ -760,9 +755,12 @@ static void nvmet_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc) cmd->queue = queue; rsp =nvmet_rdma_get_rsp (queue); + rsp->queue = queue; rsp->cmd = cmd; rsp->flags =0 ; rsp->req.cmd = cmd->nvme_cmd; + rsp->req.port = queue->port; + rsp->n_rdma =0 ;if (unlikely (queue->state !=NVMET_RDMA_Q_LIVE )) {unsigned long flags;
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 1/1 nvmet-rdma: Fix a possible uninitialized variable dereference
In reply to Sagi GrimbergThanks Sagi
Best Regards,
Yi Zhang
----- Original Message -----
From: "Sagi Grimberg" <[email protected]>
To: linux-nvme at lists.infradead.org, linux-rdma at vger.kernel.org
Cc: "Christoph Hellwig" <hch at lst.de>
Sent: Monday, March 13, 2017 9:39:41 PM
Subject: [PATCH v2] nvmet-rdma: Fix a possible uninitialized variable dereference
When handling a new recv command, we grab a new rsp resource and check for the queue state being live. In case the queue is not in live state, we simply restore the rsp back to the free list. However in this flow we didn't set rsp->queue yet, so we cannot dereference it.
Instead, make sure to initialize rsp->queue (and other rsp members) as soon as possible so we won't reference uninitialized variables.
---
- v1 broke srq, this one doesn't
drivers/nvme/target/rdma.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/nvme/target/rdma.c +3 -5
@@ -703,11 +703,6 @@ static void nvmet_rdma_handle_command(struct nvmet_rdma_queue *queue, {u16 status; - cmd->queue = queue; - cmd->n_rdma =0 ; - cmd->req.port = queue->port; - -ib_dma_sync_single_for_cpu (queue->dev->device, cmd->cmd->sge[0 ].addr, cmd->cmd->sge[0 ].length,DMA_FROM_DEVICE );
@@ -760,9 +755,12 @@ static void nvmet_rdma_recv_done(struct ib_cq *cq, struct ib_wc *wc) cmd->queue = queue; rsp =nvmet_rdma_get_rsp (queue); + rsp->queue = queue; rsp->cmd = cmd; rsp->flags =0 ; rsp->req.cmd = cmd->nvme_cmd; + rsp->req.port = queue->port; + rsp->n_rdma =0 ;if (unlikely (queue->state !=NVMET_RDMA_Q_LIVE )) {unsigned long flags;
Signature · 7 lines
2.7.4 _______________________________________________ Linux-nvme mailing list Linux-nvme at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-nvme