From: Alexandru Matei <alexandru.matei@uipath.com>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
kvm@vger.kernel.org, virtualization@lists.linux-foundation.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Mihai Petrisor <mihai.petrisor@uipath.com>,
Viorel Canja <viorel.canja@uipath.com>,
Alexandru Matei <alexandru.matei@uipath.com>
Subject: Re: [PATCH v2] vsock/virtio: initialize the_virtio_vsock before using VQs
Date: Mon, 23 Oct 2023 17:52:03 +0300 [thread overview]
Message-ID: <0624137c-85cf-4086-8256-af2b8405f434@uipath.com> (raw)
In-Reply-To: <2tc56vwgs5xwqzfqbv5vud346uzagwtygdhkngdt3wjqaslbmh@zauky5czyfkg>
On 10/23/2023 5:29 PM, Stefano Garzarella wrote:
> On Mon, Oct 23, 2023 at 05:08:33PM +0300, Alexandru Matei wrote:
>> Once VQs are filled with empty buffers and we kick the host,
>> it can send connection requests. If 'the_virtio_vsock' is not
>> initialized before, replies are silently dropped and do not reach the host.
>>
>> Fixes: 0deab087b16a ("vsock/virtio: use RCU to avoid use-after-free on the_virtio_vsock")
>> Signed-off-by: Alexandru Matei <alexandru.matei@uipath.com>
>> ---
>> v2:
>> - split virtio_vsock_vqs_init in vqs_init and vqs_fill and moved
>> the_virtio_vsock initialization after vqs_init
>>
>> net/vmw_vsock/virtio_transport.c | 9 +++++++--
>> 1 file changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
>> index e95df847176b..92738d1697c1 100644
>> --- a/net/vmw_vsock/virtio_transport.c
>> +++ b/net/vmw_vsock/virtio_transport.c
>> @@ -559,6 +559,11 @@ static int virtio_vsock_vqs_init(struct virtio_vsock *vsock)
>> vsock->tx_run = true;
>> mutex_unlock(&vsock->tx_lock);
>>
>> + return 0;
>> +}
>> +
>> +static void virtio_vsock_vqs_fill(struct virtio_vsock *vsock)
>
> What about renaming this function in virtio_vsock_vqs_start() and move also the setting of `tx_run` here?
It works but in this case we also need to move rcu_assign_pointer in virtio_vsock_vqs_start(),
the assignment needs to be right after setting tx_run to true and before filling the VQs.
>
> Thanks,
> Stefano
>
>> +{
>> mutex_lock(&vsock->rx_lock);
>> virtio_vsock_rx_fill(vsock);
>> vsock->rx_run = true;
>> @@ -568,8 +573,6 @@ static int virtio_vsock_vqs_init(struct virtio_vsock *vsock)
>> virtio_vsock_event_fill(vsock);
>> vsock->event_run = true;
>> mutex_unlock(&vsock->event_lock);
>> -
>> - return 0;
>> }
>>
>> static void virtio_vsock_vqs_del(struct virtio_vsock *vsock)
>> @@ -664,6 +667,7 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
>> goto out;
>>
>> rcu_assign_pointer(the_virtio_vsock, vsock);
>> + virtio_vsock_vqs_fill(vsock);
>>
>> mutex_unlock(&the_virtio_vsock_mutex);
>>
>> @@ -736,6 +740,7 @@ static int virtio_vsock_restore(struct virtio_device *vdev)
>> goto out;
>>
>> rcu_assign_pointer(the_virtio_vsock, vsock);
>> + virtio_vsock_vqs_fill(vsock);
>>
>> out:
>> mutex_unlock(&the_virtio_vsock_mutex);
>> --
>> 2.34.1
>>
>
next prev parent reply other threads:[~2023-10-23 14:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-23 14:08 Alexandru Matei
2023-10-23 14:29 ` Stefano Garzarella
2023-10-23 14:52 ` Alexandru Matei [this message]
2023-10-23 14:59 ` Alexandru Matei
2023-10-23 15:13 ` Stefano Garzarella
2023-10-23 15:36 ` Alexandru Matei
2023-10-23 16:10 ` Stefano Garzarella
2023-10-23 16:28 ` Alexandru Matei
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0624137c-85cf-4086-8256-af2b8405f434@uipath.com \
--to=alexandru.matei@uipath.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mihai.petrisor@uipath.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sgarzare@redhat.com \
--cc=stefanha@redhat.com \
--cc=viorel.canja@uipath.com \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®