* [PATCH] nvme-tcp: check for allocated queue in nvme_tcp_get_address()
@ 2023-02-07 14:55 Hannes Reinecke
2023-02-08 6:27 ` Christoph Hellwig
0 siblings, 1 reply; 3+ messages in thread
From: Hannes Reinecke @ 2023-02-07 14:55 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Sagi Grimberg, Keith Busch, linux-nvme, Hannes Reinecke
We need to check if the queue is allocated, otherwise we get
a kernel crash as 'queue->sock' is not allocated.
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
drivers/nvme/host/tcp.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 4ddf3e7b252a..487ea3e8b6c4 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -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);
--
2.35.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] nvme-tcp: check for allocated queue in nvme_tcp_get_address()
2023-02-07 14:55 [PATCH] nvme-tcp: check for allocated queue in nvme_tcp_get_address() Hannes Reinecke
@ 2023-02-08 6:27 ` Christoph Hellwig
2023-02-13 10:50 ` Sagi Grimberg
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2023-02-08 6:27 UTC (permalink / raw)
To: Hannes Reinecke; +Cc: Christoph Hellwig, Sagi Grimberg, Keith Busch, linux-nvme
On Tue, Feb 07, 2023 at 03:55:48PM +0100, Hannes Reinecke wrote:
> We need to check if the queue is allocated, otherwise we get
> a kernel crash as 'queue->sock' is not allocated.
>
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
> drivers/nvme/host/tcp.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
> index 4ddf3e7b252a..487ea3e8b6c4 100644
> --- a/drivers/nvme/host/tcp.c
> +++ b/drivers/nvme/host/tcp.c
> @@ -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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] nvme-tcp: check for allocated queue in nvme_tcp_get_address()
2023-02-08 6:27 ` Christoph Hellwig
@ 2023-02-13 10:50 ` Sagi Grimberg
0 siblings, 0 replies; 3+ messages in thread
From: Sagi Grimberg @ 2023-02-13 10:50 UTC (permalink / raw)
To: Christoph Hellwig, Hannes Reinecke; +Cc: Keith Busch, linux-nvme
>> We need to check if the queue is allocated, otherwise we get
>> a kernel crash as 'queue->sock' is not allocated.
>>
>> Signed-off-by: Hannes Reinecke <hare@suse.de>
>> ---
>> drivers/nvme/host/tcp.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
>> index 4ddf3e7b252a..487ea3e8b6c4 100644
>> --- a/drivers/nvme/host/tcp.c
>> +++ b/drivers/nvme/host/tcp.c
>> @@ -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.
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-02-13 10:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-07 14:55 [PATCH] nvme-tcp: check for allocated queue in nvme_tcp_get_address() Hannes Reinecke
2023-02-08 6:27 ` Christoph Hellwig
2023-02-13 10:50 ` Sagi Grimberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox