virtio/vsock: WARN_ONCE() for invalid state of socket
authorArseniy Krasnov <avkrasnov@sberdevices.ru>
Tue, 28 Mar 2023 11:32:12 +0000 (14:32 +0300)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 30 Mar 2023 08:47:48 +0000 (10:47 +0200)
This adds WARN_ONCE() and return from stream dequeue callback when
socket's queue is empty, but 'rx_bytes' still non-zero. This allows
the detection of potential bugs due to packet merging (see previous
patch).

Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
net/vmw_vsock/virtio_transport_common.c

index 11ca9b3..37934df 100644 (file)
@@ -363,6 +363,13 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk,
        u32 free_space;
 
        spin_lock_bh(&vvs->rx_lock);
        u32 free_space;
 
        spin_lock_bh(&vvs->rx_lock);
+
+       if (WARN_ONCE(skb_queue_empty(&vvs->rx_queue) && vvs->rx_bytes,
+                     "rx_queue is empty, but rx_bytes is non-zero\n")) {
+               spin_unlock_bh(&vvs->rx_lock);
+               return err;
+       }
+
        while (total < len && !skb_queue_empty(&vvs->rx_queue)) {
                skb = skb_peek(&vvs->rx_queue);
 
        while (total < len && !skb_queue_empty(&vvs->rx_queue)) {
                skb = skb_peek(&vvs->rx_queue);