mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Wei <dw@davidwei.uk>
To: Shigeru Yoshida <syoshida@redhat.com>,
	stefanha@redhat.com, sgarzare@redhat.com, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com
Cc: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+0c8ce1da0ac31abbadcd@syzkaller.appspotmail.com
Subject: Re: [PATCH net v2] virtio/vsock: Fix uninit-value in virtio_transport_recv_pkt()
Date: Sat, 4 Nov 2023 11:28:28 -0700	[thread overview]
Message-ID: <67c45ff3-4f98-4ca5-bd68-2d90cc52a775@davidwei.uk> (raw)
In-Reply-To: <20231104150531.257952-1-syoshida@redhat.com>

On 2023-11-04 08:05, 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_init_hdr()`. This patch resolves the issue by
> initializing these fields during allocation.
> 
> Fixes: 71dc9ec9ac7d ("virtio/vsock: replace virtio_vsock_pkt with sk_buff")
> Reported-and-tested-by: syzbot+0c8ce1da0ac31abbadcd@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=0c8ce1da0ac31abbadcd
> Signed-off-by: Shigeru Yoshida <syoshida@redhat.com>
> ---
> v1->v2:
> - Rebase on the latest net tree
> https://lore.kernel.org/all/20231026150154.3536433-1-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 e22c81435ef7..dc65dd4d26df 100644
> --- a/net/vmw_vsock/virtio_transport_common.c
> +++ b/net/vmw_vsock/virtio_transport_common.c
> @@ -130,6 +130,8 @@ static void virtio_transport_init_hdr(struct sk_buff *skb,
>  	hdr->dst_port	= cpu_to_le32(dst_port);
>  	hdr->flags	= cpu_to_le32(info->flags);
>  	hdr->len	= cpu_to_le32(payload_len);
> +	hdr->buf_alloc	= cpu_to_le32(0);
> +	hdr->fwd_cnt	= cpu_to_le32(0);

This change looks good to me.

I did notice that payload_len in virtio_transport_init_hdr is size_t but
len in struct virtio_vsock_hdr is __le32. But I don't think this is an
issue other than wasting some stack space, though.

>  }
>  
>  static void virtio_transport_copy_nonlinear_skb(const struct sk_buff *skb,

  reply	other threads:[~2023-11-04 18:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-04 15:05 Shigeru Yoshida
2023-11-04 18:28 ` David Wei [this message]
2023-11-06  8:42 ` Stefano Garzarella
2023-11-08  3:10 ` patchwork-bot+netdevbpf

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=67c45ff3-4f98-4ca5-bd68-2d90cc52a775@davidwei.uk \
    --to=dw@davidwei.uk \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=syoshida@redhat.com \
    --cc=syzbot+0c8ce1da0ac31abbadcd@syzkaller.appspotmail.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®