vsock/virtio: Fix unsigned integer wrap around in virtio_transport_has_space()
authorNikolay Kuratov <kniv@yandex-team.ru>
Mon, 11 Dec 2023 16:23:17 +0000 (19:23 +0300)
committerJakub Kicinski <kuba@kernel.org>
Thu, 14 Dec 2023 01:59:08 +0000 (17:59 -0800)
We need to do signed arithmetic if we expect condition
`if (bytes < 0)` to be possible

Found by Linux Verification Center (linuxtesting.org) with SVACE

Fixes: 06a8fc78367d ("VSOCK: Introduce virtio_vsock_common.ko")
Signed-off-by: Nikolay Kuratov <kniv@yandex-team.ru>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Link: https://lore.kernel.org/r/20231211162317.4116625-1-kniv@yandex-team.ru
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/vmw_vsock/virtio_transport_common.c

index c8e162c9d1df9265bd6e93586fca9e721fae979e..6df246b532606312f2cbf547c7332fa3463a7e3e 100644 (file)
@@ -843,7 +843,7 @@ static s64 virtio_transport_has_space(struct vsock_sock *vsk)
        struct virtio_vsock_sock *vvs = vsk->trans;
        s64 bytes;
 
-       bytes = vvs->peer_buf_alloc - (vvs->tx_cnt - vvs->peer_fwd_cnt);
+       bytes = (s64)vvs->peer_buf_alloc - (vvs->tx_cnt - vvs->peer_fwd_cnt);
        if (bytes < 0)
                bytes = 0;