Skip to contentSkip to conversation

nvme-tcp: check for allocated queue in nvme_tcp_get_address()

PATCH In review Hannes Reinecke 3 participants 3 messages Feb 7, 2023 – Feb 13, 2023 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme-tcp: check for allocated queue in nvme_tcp_get_address()

We need to check if the queue is allocated, otherwise we get a kernel crash as 'queue->sock' is not allocated.

---
 drivers/nvme/host/tcp.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/nvme/host/tcp.c +3 -0
index 4ddf3e7b252a..487ea3e8b6c4 100644
@@ -2859,6 +2859,9 @@ static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size)
 	struct sockaddr_storage src_addr;
 	int ret, len;
 
+	if (!test_bit(NVME_TCP_Q_ALLOCATED, &queue->flags))
+		return -EINVAL;
+
 	len = nvmf_get_address(ctrl, buf, size);
 
 	ret = kernel_getsockname(queue->sock, (struct sockaddr *)&src_addr);
Signature · 1 line
2.35.3
#1 lore raw
Quoted 13 lines · Hannes Reinecke

We need to check if the queue is allocated, otherwise we get a kernel crash as 'queue->sock' is not allocated.

---
 drivers/nvme/host/tcp.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/nvme/host/tcp.c +0 -0
index 4ddf3e7b252a..487ea3e8b6c4 100644

drivers/nvme/host/tcp.c static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size) · line 2863

Quoted 5 lines
drivers/nvme/host/tcp.c +2 -0
@@ -2859,6 +2859,9 @@ static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size)
 	struct sockaddr_storage src_addr;
 	int ret, len;
 
+	if (!test_bit(NVME_TCP_Q_ALLOCATED, &queue->flags))
+		return -EINVAL;

I'm not sure this is enough. The queue could be freed right after this check. I think we have to cache the address information somewhere instead and ensure that it is always valid.

maintainer
#2 lore raw
Quoted 17 lines
Quoted 17 lines

We need to check if the queue is allocated, otherwise we get a kernel crash as 'queue->sock' is not allocated.

---
  drivers/nvme/host/tcp.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/nvme/host/tcp.c +0 -0
index 4ddf3e7b252a..487ea3e8b6c4 100644
@@ -2859,6 +2859,9 @@ static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size)
  	struct sockaddr_storage src_addr;
  	int ret, len;
 
Quoted 6 lines

drivers/nvme/host/tcp.c static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size) · line 2863

Quoted 2 lines
drivers/nvme/host/tcp.c +2 -0
+	if (!test_bit(NVME_TCP_Q_ALLOCATED, &queue->flags))
+		return -EINVAL;

I'm not sure this is enough. The queue could be freed right after this check. I think we have to cache the address information somewhere instead and ensure that it is always valid.

The destination address is cached in ctrl->opts (passed to the host).

What is referenced afterwards is the socket src_addr of the admin queue (was added for debug information afaict). So it has the same lifetime of the queue.

The patch should return call nvmf_get_address and if the queue is LIVE, append the src_addr info under the queue_lock.