* [PATCH net] virtio/vsock: Fix uninit-value in virtio_transport_recv_pkt()
@ 2023-10-26 15:01 Shigeru Yoshida
2023-10-27 8:01 ` Stefano Garzarella
2023-11-02 5:20 ` Jakub Kicinski
0 siblings, 2 replies; 6+ messages in thread
From: Shigeru Yoshida @ 2023-10-26 15:01 UTC (permalink / raw)
To: stefanha, sgarzare, davem, edumazet, kuba, pabeni
Cc: kvm, virtualization, netdev, linux-kernel, Shigeru Yoshida
KMSAN reported the following uninit-value access issue:
=====================================================
BUG: KMSAN: uninit-value in virtio_transport_recv_pkt+0x1dfb/0x26a0 net/vmw_vsock/virtio_transport_common.c:1421
virtio_transport_recv_pkt+0x1dfb/0x26a0 net/vmw_vsock/virtio_transport_common.c:1421
vsock_loopback_work+0x3bb/0x5a0 net/vmw_vsock/vsock_loopback.c:120
process_one_work kernel/workqueue.c:2630 [inline]
process_scheduled_works+0xff6/0x1e60 kernel/workqueue.c:2703
worker_thread+0xeca/0x14d0 kernel/workqueue.c:2784
kthread+0x3cc/0x520 kernel/kthread.c:388
ret_from_fork+0x66/0x80 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304
Uninit was stored to memory at:
virtio_transport_space_update net/vmw_vsock/virtio_transport_common.c:1274 [inline]
virtio_transport_recv_pkt+0x1ee8/0x26a0 net/vmw_vsock/virtio_transport_common.c:1415
vsock_loopback_work+0x3bb/0x5a0 net/vmw_vsock/vsock_loopback.c:120
process_one_work kernel/workqueue.c:2630 [inline]
process_scheduled_works+0xff6/0x1e60 kernel/workqueue.c:2703
worker_thread+0xeca/0x14d0 kernel/workqueue.c:2784
kthread+0x3cc/0x520 kernel/kthread.c:388
ret_from_fork+0x66/0x80 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304
Uninit was created at:
slab_post_alloc_hook+0x105/0xad0 mm/slab.h:767
slab_alloc_node mm/slub.c:3478 [inline]
kmem_cache_alloc_node+0x5a2/0xaf0 mm/slub.c:3523
kmalloc_reserve+0x13c/0x4a0 net/core/skbuff.c:559
__alloc_skb+0x2fd/0x770 net/core/skbuff.c:650
alloc_skb include/linux/skbuff.h:1286 [inline]
virtio_vsock_alloc_skb include/linux/virtio_vsock.h:66 [inline]
virtio_transport_alloc_skb+0x90/0x11e0 net/vmw_vsock/virtio_transport_common.c:58
virtio_transport_reset_no_sock net/vmw_vsock/virtio_transport_common.c:957 [inline]
virtio_transport_recv_pkt+0x1279/0x26a0 net/vmw_vsock/virtio_transport_common.c:1387
vsock_loopback_work+0x3bb/0x5a0 net/vmw_vsock/vsock_loopback.c:120
process_one_work kernel/workqueue.c:2630 [inline]
process_scheduled_works+0xff6/0x1e60 kernel/workqueue.c:2703
worker_thread+0xeca/0x14d0 kernel/workqueue.c:2784
kthread+0x3cc/0x520 kernel/kthread.c:388
ret_from_fork+0x66/0x80 arch/x86/kernel/process.c:147
ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304
CPU: 1 PID: 10664 Comm: kworker/1:5 Not tainted 6.6.0-rc3-00146-g9f3ebbef746f #3
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-1.fc38 04/01/2014
Workqueue: vsock-loopback vsock_loopback_work
=====================================================
The following simple reproducer can cause the issue described above:
int main(void)
{
int sock;
struct sockaddr_vm addr = {
.svm_family = AF_VSOCK,
.svm_cid = VMADDR_CID_ANY,
.svm_port = 1234,
};
sock = socket(AF_VSOCK, SOCK_STREAM, 0);
connect(sock, (struct sockaddr *)&addr, sizeof(addr));
return 0;
}
This issue occurs because the `buf_alloc` and `fwd_cnt` fields of the
`struct virtio_vsock_hdr` are not initialized when a new skb is allocated
in `virtio_transport_alloc_skb()`. This patch resolves the issue by
initializing these fields during allocation.
Fixes: 71dc9ec9ac7d ("virtio/vsock: replace virtio_vsock_pkt with sk_buff")
Signed-off-by: Shigeru Yoshida <syoshida@redhat.com>
---
net/vmw_vsock/virtio_transport_common.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index 352d042b130b..102673bef189 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -68,6 +68,8 @@ virtio_transport_alloc_skb(struct virtio_vsock_pkt_info *info,
hdr->dst_port = cpu_to_le32(dst_port);
hdr->flags = cpu_to_le32(info->flags);
hdr->len = cpu_to_le32(len);
+ hdr->buf_alloc = cpu_to_le32(0);
+ hdr->fwd_cnt = cpu_to_le32(0);
if (info->msg && len > 0) {
payload = skb_put(skb, len);
--
2.41.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH net] virtio/vsock: Fix uninit-value in virtio_transport_recv_pkt() 2023-10-26 15:01 [PATCH net] virtio/vsock: Fix uninit-value in virtio_transport_recv_pkt() Shigeru Yoshida @ 2023-10-27 8:01 ` Stefano Garzarella 2023-10-27 8:18 ` Stefano Garzarella 2023-11-02 5:20 ` Jakub Kicinski 1 sibling, 1 reply; 6+ messages in thread From: Stefano Garzarella @ 2023-10-27 8:01 UTC (permalink / raw) To: Shigeru Yoshida Cc: stefanha, davem, edumazet, kuba, pabeni, kvm, virtualization, netdev, linux-kernel, bobby.eshleman, bobbyeshleman On Fri, Oct 27, 2023 at 12:01:54AM +0900, Shigeru Yoshida wrote: >KMSAN reported the following uninit-value access issue: > >===================================================== >BUG: KMSAN: uninit-value in virtio_transport_recv_pkt+0x1dfb/0x26a0 net/vmw_vsock/virtio_transport_common.c:1421 > virtio_transport_recv_pkt+0x1dfb/0x26a0 net/vmw_vsock/virtio_transport_common.c:1421 > vsock_loopback_work+0x3bb/0x5a0 net/vmw_vsock/vsock_loopback.c:120 > process_one_work kernel/workqueue.c:2630 [inline] > process_scheduled_works+0xff6/0x1e60 kernel/workqueue.c:2703 > worker_thread+0xeca/0x14d0 kernel/workqueue.c:2784 > kthread+0x3cc/0x520 kernel/kthread.c:388 > ret_from_fork+0x66/0x80 arch/x86/kernel/process.c:147 > ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304 > >Uninit was stored to memory at: > virtio_transport_space_update net/vmw_vsock/virtio_transport_common.c:1274 [inline] > virtio_transport_recv_pkt+0x1ee8/0x26a0 net/vmw_vsock/virtio_transport_common.c:1415 > vsock_loopback_work+0x3bb/0x5a0 net/vmw_vsock/vsock_loopback.c:120 > process_one_work kernel/workqueue.c:2630 [inline] > process_scheduled_works+0xff6/0x1e60 kernel/workqueue.c:2703 > worker_thread+0xeca/0x14d0 kernel/workqueue.c:2784 > kthread+0x3cc/0x520 kernel/kthread.c:388 > ret_from_fork+0x66/0x80 arch/x86/kernel/process.c:147 > ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304 > >Uninit was created at: > slab_post_alloc_hook+0x105/0xad0 mm/slab.h:767 > slab_alloc_node mm/slub.c:3478 [inline] > kmem_cache_alloc_node+0x5a2/0xaf0 mm/slub.c:3523 > kmalloc_reserve+0x13c/0x4a0 net/core/skbuff.c:559 > __alloc_skb+0x2fd/0x770 net/core/skbuff.c:650 > alloc_skb include/linux/skbuff.h:1286 [inline] > virtio_vsock_alloc_skb include/linux/virtio_vsock.h:66 [inline] > virtio_transport_alloc_skb+0x90/0x11e0 net/vmw_vsock/virtio_transport_common.c:58 > virtio_transport_reset_no_sock net/vmw_vsock/virtio_transport_common.c:957 [inline] > virtio_transport_recv_pkt+0x1279/0x26a0 net/vmw_vsock/virtio_transport_common.c:1387 > vsock_loopback_work+0x3bb/0x5a0 net/vmw_vsock/vsock_loopback.c:120 > process_one_work kernel/workqueue.c:2630 [inline] > process_scheduled_works+0xff6/0x1e60 kernel/workqueue.c:2703 > worker_thread+0xeca/0x14d0 kernel/workqueue.c:2784 > kthread+0x3cc/0x520 kernel/kthread.c:388 > ret_from_fork+0x66/0x80 arch/x86/kernel/process.c:147 > ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304 > >CPU: 1 PID: 10664 Comm: kworker/1:5 Not tainted 6.6.0-rc3-00146-g9f3ebbef746f #3 >Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-1.fc38 04/01/2014 >Workqueue: vsock-loopback vsock_loopback_work >===================================================== > >The following simple reproducer can cause the issue described above: > >int main(void) >{ > int sock; > struct sockaddr_vm addr = { > .svm_family = AF_VSOCK, > .svm_cid = VMADDR_CID_ANY, > .svm_port = 1234, > }; > > sock = socket(AF_VSOCK, SOCK_STREAM, 0); > connect(sock, (struct sockaddr *)&addr, sizeof(addr)); > return 0; >} > >This issue occurs because the `buf_alloc` and `fwd_cnt` fields of the >`struct virtio_vsock_hdr` are not initialized when a new skb is allocated >in `virtio_transport_alloc_skb()`. This patch resolves the issue by >initializing these fields during allocation. > >Fixes: 71dc9ec9ac7d ("virtio/vsock: replace virtio_vsock_pkt with sk_buff") CCin Bobby, the original author, for any additional comments/checks. Yeah, I see, before that commit we used kzalloc() to allocate the header so we forgot to reset these 2 fields, and checking they are the only 2 missing. I was thinking of putting a memset(hdr, 0, sizeof(*hdr)) in virtio_vsock_alloc_skb() but I think it's just extra unnecessary work, since here we set all the fields (thanks to this fix), in vhost/vsock.c we copy all the header we receive from the guest and in virtio_transport.c we already set it all to 0 because we are preallocating the receive buffers. So I'm fine with this fix! >Signed-off-by: Shigeru Yoshida <syoshida@redhat.com> >--- > net/vmw_vsock/virtio_transport_common.c | 2 ++ > 1 file changed, 2 insertions(+) > >diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c >index 352d042b130b..102673bef189 100644 >--- a/net/vmw_vsock/virtio_transport_common.c >+++ b/net/vmw_vsock/virtio_transport_common.c >@@ -68,6 +68,8 @@ virtio_transport_alloc_skb(struct virtio_vsock_pkt_info *info, > hdr->dst_port = cpu_to_le32(dst_port); > hdr->flags = cpu_to_le32(info->flags); > hdr->len = cpu_to_le32(len); >+ hdr->buf_alloc = cpu_to_le32(0); >+ hdr->fwd_cnt = cpu_to_le32(0); > > if (info->msg && len > 0) { > payload = skb_put(skb, len); >-- >2.41.0 > Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Thanks, Stefano ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] virtio/vsock: Fix uninit-value in virtio_transport_recv_pkt() 2023-10-27 8:01 ` Stefano Garzarella @ 2023-10-27 8:18 ` Stefano Garzarella 2023-10-27 8:50 ` Eric Dumazet 0 siblings, 1 reply; 6+ messages in thread From: Stefano Garzarella @ 2023-10-27 8:18 UTC (permalink / raw) To: Shigeru Yoshida Cc: stefanha, davem, edumazet, kuba, pabeni, kvm, virtualization, netdev, linux-kernel, bobby.eshleman, bobbyeshleman On Fri, Oct 27, 2023 at 10:01 AM Stefano Garzarella <sgarzare@redhat.com> wrote: > > On Fri, Oct 27, 2023 at 12:01:54AM +0900, Shigeru Yoshida wrote: > >KMSAN reported the following uninit-value access issue: > > > >===================================================== > >BUG: KMSAN: uninit-value in virtio_transport_recv_pkt+0x1dfb/0x26a0 net/vmw_vsock/virtio_transport_common.c:1421 > > virtio_transport_recv_pkt+0x1dfb/0x26a0 net/vmw_vsock/virtio_transport_common.c:1421 > > vsock_loopback_work+0x3bb/0x5a0 net/vmw_vsock/vsock_loopback.c:120 > > process_one_work kernel/workqueue.c:2630 [inline] > > process_scheduled_works+0xff6/0x1e60 kernel/workqueue.c:2703 > > worker_thread+0xeca/0x14d0 kernel/workqueue.c:2784 > > kthread+0x3cc/0x520 kernel/kthread.c:388 > > ret_from_fork+0x66/0x80 arch/x86/kernel/process.c:147 > > ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304 > > > >Uninit was stored to memory at: > > virtio_transport_space_update net/vmw_vsock/virtio_transport_common.c:1274 [inline] > > virtio_transport_recv_pkt+0x1ee8/0x26a0 net/vmw_vsock/virtio_transport_common.c:1415 > > vsock_loopback_work+0x3bb/0x5a0 net/vmw_vsock/vsock_loopback.c:120 > > process_one_work kernel/workqueue.c:2630 [inline] > > process_scheduled_works+0xff6/0x1e60 kernel/workqueue.c:2703 > > worker_thread+0xeca/0x14d0 kernel/workqueue.c:2784 > > kthread+0x3cc/0x520 kernel/kthread.c:388 > > ret_from_fork+0x66/0x80 arch/x86/kernel/process.c:147 > > ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304 > > > >Uninit was created at: > > slab_post_alloc_hook+0x105/0xad0 mm/slab.h:767 > > slab_alloc_node mm/slub.c:3478 [inline] > > kmem_cache_alloc_node+0x5a2/0xaf0 mm/slub.c:3523 > > kmalloc_reserve+0x13c/0x4a0 net/core/skbuff.c:559 > > __alloc_skb+0x2fd/0x770 net/core/skbuff.c:650 > > alloc_skb include/linux/skbuff.h:1286 [inline] > > virtio_vsock_alloc_skb include/linux/virtio_vsock.h:66 [inline] > > virtio_transport_alloc_skb+0x90/0x11e0 net/vmw_vsock/virtio_transport_common.c:58 > > virtio_transport_reset_no_sock net/vmw_vsock/virtio_transport_common.c:957 [inline] > > virtio_transport_recv_pkt+0x1279/0x26a0 net/vmw_vsock/virtio_transport_common.c:1387 > > vsock_loopback_work+0x3bb/0x5a0 net/vmw_vsock/vsock_loopback.c:120 > > process_one_work kernel/workqueue.c:2630 [inline] > > process_scheduled_works+0xff6/0x1e60 kernel/workqueue.c:2703 > > worker_thread+0xeca/0x14d0 kernel/workqueue.c:2784 > > kthread+0x3cc/0x520 kernel/kthread.c:388 > > ret_from_fork+0x66/0x80 arch/x86/kernel/process.c:147 > > ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304 > > > >CPU: 1 PID: 10664 Comm: kworker/1:5 Not tainted 6.6.0-rc3-00146-g9f3ebbef746f #3 > >Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-1.fc38 04/01/2014 > >Workqueue: vsock-loopback vsock_loopback_work > >===================================================== > > > >The following simple reproducer can cause the issue described above: > > > >int main(void) > >{ > > int sock; > > struct sockaddr_vm addr = { > > .svm_family = AF_VSOCK, > > .svm_cid = VMADDR_CID_ANY, > > .svm_port = 1234, > > }; > > > > sock = socket(AF_VSOCK, SOCK_STREAM, 0); > > connect(sock, (struct sockaddr *)&addr, sizeof(addr)); > > return 0; > >} > > > >This issue occurs because the `buf_alloc` and `fwd_cnt` fields of the > >`struct virtio_vsock_hdr` are not initialized when a new skb is allocated > >in `virtio_transport_alloc_skb()`. This patch resolves the issue by > >initializing these fields during allocation. > > > >Fixes: 71dc9ec9ac7d ("virtio/vsock: replace virtio_vsock_pkt with sk_buff") > > CCin Bobby, the original author, for any additional comments/checks. > > Yeah, I see, before that commit we used kzalloc() to allocate the > header so we forgot to reset these 2 fields, and checking they are > the only 2 missing. > > I was thinking of putting a memset(hdr, 0, sizeof(*hdr)) in > virtio_vsock_alloc_skb() but I think it's just extra unnecessary work, > since here we set all the fields (thanks to this fix), in vhost/vsock.c > we copy all the header we receive from the guest and in > virtio_transport.c we already set it all to 0 because we are > preallocating the receive buffers. > > So I'm fine with this fix! > > >Signed-off-by: Shigeru Yoshida <syoshida@redhat.com> > >--- > > net/vmw_vsock/virtio_transport_common.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > >diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c > >index 352d042b130b..102673bef189 100644 > >--- a/net/vmw_vsock/virtio_transport_common.c > >+++ b/net/vmw_vsock/virtio_transport_common.c > >@@ -68,6 +68,8 @@ virtio_transport_alloc_skb(struct virtio_vsock_pkt_info *info, > > hdr->dst_port = cpu_to_le32(dst_port); > > hdr->flags = cpu_to_le32(info->flags); > > hdr->len = cpu_to_le32(len); > >+ hdr->buf_alloc = cpu_to_le32(0); > >+ hdr->fwd_cnt = cpu_to_le32(0); > > > > if (info->msg && len > 0) { > > payload = skb_put(skb, len); > >-- > >2.41.0 > > > > Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> syzbot just reported the same [1], should we add the following tag? Reported-by: syzbot+0c8ce1da0ac31abbadcd@syzkaller.appspotmail.com [1] https://lore.kernel.org/netdev/00000000000008b2940608ae3ce9@google.com/ Thanks, Stefano ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] virtio/vsock: Fix uninit-value in virtio_transport_recv_pkt() 2023-10-27 8:18 ` Stefano Garzarella @ 2023-10-27 8:50 ` Eric Dumazet 0 siblings, 0 replies; 6+ messages in thread From: Eric Dumazet @ 2023-10-27 8:50 UTC (permalink / raw) To: Stefano Garzarella Cc: Shigeru Yoshida, stefanha, davem, kuba, pabeni, kvm, virtualization, netdev, linux-kernel, bobby.eshleman, bobbyeshleman On Fri, Oct 27, 2023 at 10:18 AM Stefano Garzarella <sgarzare@redhat.com> wrote: > > On Fri, Oct 27, 2023 at 10:01 AM Stefano Garzarella <sgarzare@redhat.com> wrote: > > > > On Fri, Oct 27, 2023 at 12:01:54AM +0900, Shigeru Yoshida wrote: > > >KMSAN reported the following uninit-value access issue: > > > > > >===================================================== > > >BUG: KMSAN: uninit-value in virtio_transport_recv_pkt+0x1dfb/0x26a0 net/vmw_vsock/virtio_transport_common.c:1421 > > > virtio_transport_recv_pkt+0x1dfb/0x26a0 net/vmw_vsock/virtio_transport_common.c:1421 > > > vsock_loopback_work+0x3bb/0x5a0 net/vmw_vsock/vsock_loopback.c:120 > > > process_one_work kernel/workqueue.c:2630 [inline] > > > process_scheduled_works+0xff6/0x1e60 kernel/workqueue.c:2703 > > > worker_thread+0xeca/0x14d0 kernel/workqueue.c:2784 > > > kthread+0x3cc/0x520 kernel/kthread.c:388 > > > ret_from_fork+0x66/0x80 arch/x86/kernel/process.c:147 > > > ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304 > > > > > >Uninit was stored to memory at: > > > virtio_transport_space_update net/vmw_vsock/virtio_transport_common.c:1274 [inline] > > > virtio_transport_recv_pkt+0x1ee8/0x26a0 net/vmw_vsock/virtio_transport_common.c:1415 > > > vsock_loopback_work+0x3bb/0x5a0 net/vmw_vsock/vsock_loopback.c:120 > > > process_one_work kernel/workqueue.c:2630 [inline] > > > process_scheduled_works+0xff6/0x1e60 kernel/workqueue.c:2703 > > > worker_thread+0xeca/0x14d0 kernel/workqueue.c:2784 > > > kthread+0x3cc/0x520 kernel/kthread.c:388 > > > ret_from_fork+0x66/0x80 arch/x86/kernel/process.c:147 > > > ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304 > > > > > >Uninit was created at: > > > slab_post_alloc_hook+0x105/0xad0 mm/slab.h:767 > > > slab_alloc_node mm/slub.c:3478 [inline] > > > kmem_cache_alloc_node+0x5a2/0xaf0 mm/slub.c:3523 > > > kmalloc_reserve+0x13c/0x4a0 net/core/skbuff.c:559 > > > __alloc_skb+0x2fd/0x770 net/core/skbuff.c:650 > > > alloc_skb include/linux/skbuff.h:1286 [inline] > > > virtio_vsock_alloc_skb include/linux/virtio_vsock.h:66 [inline] > > > virtio_transport_alloc_skb+0x90/0x11e0 net/vmw_vsock/virtio_transport_common.c:58 > > > virtio_transport_reset_no_sock net/vmw_vsock/virtio_transport_common.c:957 [inline] > > > virtio_transport_recv_pkt+0x1279/0x26a0 net/vmw_vsock/virtio_transport_common.c:1387 > > > vsock_loopback_work+0x3bb/0x5a0 net/vmw_vsock/vsock_loopback.c:120 > > > process_one_work kernel/workqueue.c:2630 [inline] > > > process_scheduled_works+0xff6/0x1e60 kernel/workqueue.c:2703 > > > worker_thread+0xeca/0x14d0 kernel/workqueue.c:2784 > > > kthread+0x3cc/0x520 kernel/kthread.c:388 > > > ret_from_fork+0x66/0x80 arch/x86/kernel/process.c:147 > > > ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304 > > > > > >CPU: 1 PID: 10664 Comm: kworker/1:5 Not tainted 6.6.0-rc3-00146-g9f3ebbef746f #3 > > >Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-1.fc38 04/01/2014 > > >Workqueue: vsock-loopback vsock_loopback_work > > >===================================================== > > > > > >The following simple reproducer can cause the issue described above: > > > > > >int main(void) > > >{ > > > int sock; > > > struct sockaddr_vm addr = { > > > .svm_family = AF_VSOCK, > > > .svm_cid = VMADDR_CID_ANY, > > > .svm_port = 1234, > > > }; > > > > > > sock = socket(AF_VSOCK, SOCK_STREAM, 0); > > > connect(sock, (struct sockaddr *)&addr, sizeof(addr)); > > > return 0; > > >} > > > > > >This issue occurs because the `buf_alloc` and `fwd_cnt` fields of the > > >`struct virtio_vsock_hdr` are not initialized when a new skb is allocated > > >in `virtio_transport_alloc_skb()`. This patch resolves the issue by > > >initializing these fields during allocation. > > > > > >Fixes: 71dc9ec9ac7d ("virtio/vsock: replace virtio_vsock_pkt with sk_buff") > > > > CCin Bobby, the original author, for any additional comments/checks. > > > > Yeah, I see, before that commit we used kzalloc() to allocate the > > header so we forgot to reset these 2 fields, and checking they are > > the only 2 missing. > > > > I was thinking of putting a memset(hdr, 0, sizeof(*hdr)) in > > virtio_vsock_alloc_skb() but I think it's just extra unnecessary work, > > since here we set all the fields (thanks to this fix), in vhost/vsock.c > > we copy all the header we receive from the guest and in > > virtio_transport.c we already set it all to 0 because we are > > preallocating the receive buffers. > > > > So I'm fine with this fix! > > > > >Signed-off-by: Shigeru Yoshida <syoshida@redhat.com> > > >--- > > > net/vmw_vsock/virtio_transport_common.c | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > >diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c > > >index 352d042b130b..102673bef189 100644 > > >--- a/net/vmw_vsock/virtio_transport_common.c > > >+++ b/net/vmw_vsock/virtio_transport_common.c > > >@@ -68,6 +68,8 @@ virtio_transport_alloc_skb(struct virtio_vsock_pkt_info *info, > > > hdr->dst_port = cpu_to_le32(dst_port); > > > hdr->flags = cpu_to_le32(info->flags); > > > hdr->len = cpu_to_le32(len); > > >+ hdr->buf_alloc = cpu_to_le32(0); > > >+ hdr->fwd_cnt = cpu_to_le32(0); > > > > > > if (info->msg && len > 0) { > > > payload = skb_put(skb, len); > > >-- > > >2.41.0 > > > > > > > Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> > > syzbot just reported the same [1], should we add the following tag? > > Reported-by: syzbot+0c8ce1da0ac31abbadcd@syzkaller.appspotmail.com > > [1] https://lore.kernel.org/netdev/00000000000008b2940608ae3ce9@google.com/ Yes, I was about to add this tag as well, but you were fast ;) Reviewed-by: Eric Dumazet <edumazet@google.com> ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] virtio/vsock: Fix uninit-value in virtio_transport_recv_pkt() 2023-10-26 15:01 [PATCH net] virtio/vsock: Fix uninit-value in virtio_transport_recv_pkt() Shigeru Yoshida 2023-10-27 8:01 ` Stefano Garzarella @ 2023-11-02 5:20 ` Jakub Kicinski 2023-11-02 13:30 ` Shigeru Yoshida 1 sibling, 1 reply; 6+ messages in thread From: Jakub Kicinski @ 2023-11-02 5:20 UTC (permalink / raw) To: Shigeru Yoshida Cc: stefanha, sgarzare, davem, edumazet, pabeni, kvm, virtualization, netdev, linux-kernel On Fri, 27 Oct 2023 00:01:54 +0900 Shigeru Yoshida wrote: > This issue occurs because the `buf_alloc` and `fwd_cnt` fields of the > `struct virtio_vsock_hdr` are not initialized when a new skb is allocated > in `virtio_transport_alloc_skb()`. This patch resolves the issue by > initializing these fields during allocation. We didn't manage to apply this before the merge window, and now the trees have converged. Patch no longer applies cleanly to net. Please rebase & repost. -- pw-bot: cr ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net] virtio/vsock: Fix uninit-value in virtio_transport_recv_pkt() 2023-11-02 5:20 ` Jakub Kicinski @ 2023-11-02 13:30 ` Shigeru Yoshida 0 siblings, 0 replies; 6+ messages in thread From: Shigeru Yoshida @ 2023-11-02 13:30 UTC (permalink / raw) To: kuba Cc: stefanha, sgarzare, davem, edumazet, pabeni, kvm, virtualization, netdev, linux-kernel On Wed, 1 Nov 2023 22:20:45 -0700, Jakub Kicinski wrote: > On Fri, 27 Oct 2023 00:01:54 +0900 Shigeru Yoshida wrote: >> This issue occurs because the `buf_alloc` and `fwd_cnt` fields of the >> `struct virtio_vsock_hdr` are not initialized when a new skb is allocated >> in `virtio_transport_alloc_skb()`. This patch resolves the issue by >> initializing these fields during allocation. > > We didn't manage to apply this before the merge window, and now the > trees have converged. Patch no longer applies cleanly to net. > Please rebase & repost. I got it. I'll rebase the patch to the latest net tree and resend it. Thanks, Shigeru ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-11-02 13:30 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-10-26 15:01 [PATCH net] virtio/vsock: Fix uninit-value in virtio_transport_recv_pkt() Shigeru Yoshida 2023-10-27 8:01 ` Stefano Garzarella 2023-10-27 8:18 ` Stefano Garzarella 2023-10-27 8:50 ` Eric Dumazet 2023-11-02 5:20 ` Jakub Kicinski 2023-11-02 13:30 ` Shigeru Yoshida
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).