* [PATCH] vsock/virtio: Fix unsigned integer wrap around in virtio_transport_has_space()
@ 2023-12-11 14:25 Nikolay Kuratov
2023-12-11 15:45 ` Stefano Garzarella
0 siblings, 1 reply; 5+ messages in thread
From: Nikolay Kuratov @ 2023-12-11 14:25 UTC (permalink / raw)
To: linux-kernel; +Cc: sgarzare, netdev, virtualization, kvm, Nikolay Kuratov
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
Signed-off-by: Nikolay Kuratov <kniv@yandex-team.ru>
---
net/vmw_vsock/virtio_transport_common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index c8e162c9d1df..6df246b53260 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -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;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] vsock/virtio: Fix unsigned integer wrap around in virtio_transport_has_space()
2023-12-11 14:25 [PATCH] vsock/virtio: Fix unsigned integer wrap around in virtio_transport_has_space() Nikolay Kuratov
@ 2023-12-11 15:45 ` Stefano Garzarella
2023-12-11 16:23 ` [PATCH v2] " Nikolay Kuratov
0 siblings, 1 reply; 5+ messages in thread
From: Stefano Garzarella @ 2023-12-11 15:45 UTC (permalink / raw)
To: Nikolay Kuratov; +Cc: linux-kernel, netdev, virtualization, kvm
On Mon, Dec 11, 2023 at 05:25:05PM +0300, Nikolay Kuratov wrote:
>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
>
We should add:
Fixes: 06a8fc78367d ("VSOCK: Introduce virtio_vsock_common.ko")
>Signed-off-by: Nikolay Kuratov <kniv@yandex-team.ru>
>---
> net/vmw_vsock/virtio_transport_common.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
>index c8e162c9d1df..6df246b53260 100644
>--- a/net/vmw_vsock/virtio_transport_common.c
>+++ b/net/vmw_vsock/virtio_transport_common.c
>@@ -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 we respect the credit, this should not happen. It can happen, though,
that the receiver changes its buffer size while we're communicating,
and if it reduces it, this could happen. So yes, we need to fix it!
Thanks!
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
> if (bytes < 0)
> bytes = 0;
>
>--
>2.34.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2] vsock/virtio: Fix unsigned integer wrap around in virtio_transport_has_space()
2023-12-11 15:45 ` Stefano Garzarella
@ 2023-12-11 16:23 ` Nikolay Kuratov
2023-12-11 16:33 ` Stefano Garzarella
2023-12-14 2:30 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 5+ messages in thread
From: Nikolay Kuratov @ 2023-12-11 16:23 UTC (permalink / raw)
To: linux-kernel; +Cc: sgarzare, netdev, virtualization, kvm, Nikolay Kuratov
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>
---
V1 -> V2: Added Fixes section
net/vmw_vsock/virtio_transport_common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index c8e162c9d1df..6df246b53260 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -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;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2] vsock/virtio: Fix unsigned integer wrap around in virtio_transport_has_space()
2023-12-11 16:23 ` [PATCH v2] " Nikolay Kuratov
@ 2023-12-11 16:33 ` Stefano Garzarella
2023-12-14 2:30 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 5+ messages in thread
From: Stefano Garzarella @ 2023-12-11 16:33 UTC (permalink / raw)
To: Nikolay Kuratov; +Cc: linux-kernel, netdev, virtualization, kvm
On Mon, Dec 11, 2023 at 07:23:17PM +0300, Nikolay Kuratov wrote:
>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>
>---
>
>V1 -> V2: Added Fixes section
Please, next time carry also R-b tags.
>
> net/vmw_vsock/virtio_transport_common.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Thanks,
Stefano
>
>diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
>index c8e162c9d1df..6df246b53260 100644
>--- a/net/vmw_vsock/virtio_transport_common.c
>+++ b/net/vmw_vsock/virtio_transport_common.c
>@@ -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;
>
>--
>2.34.1
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2] vsock/virtio: Fix unsigned integer wrap around in virtio_transport_has_space()
2023-12-11 16:23 ` [PATCH v2] " Nikolay Kuratov
2023-12-11 16:33 ` Stefano Garzarella
@ 2023-12-14 2:30 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-12-14 2:30 UTC (permalink / raw)
To: Nikolay Kuratov; +Cc: linux-kernel, sgarzare, netdev, virtualization, kvm
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Mon, 11 Dec 2023 19:23:17 +0300 you wrote:
> 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>
>
> [...]
Here is the summary with links:
- [v2] vsock/virtio: Fix unsigned integer wrap around in virtio_transport_has_space()
https://git.kernel.org/netdev/net/c/60316d7f10b1
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-12-14 2:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-11 14:25 [PATCH] vsock/virtio: Fix unsigned integer wrap around in virtio_transport_has_space() Nikolay Kuratov
2023-12-11 15:45 ` Stefano Garzarella
2023-12-11 16:23 ` [PATCH v2] " Nikolay Kuratov
2023-12-11 16:33 ` Stefano Garzarella
2023-12-14 2:30 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox