Message ID | 20231026150154.3536433-1-syoshida@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp742474vqb; Thu, 26 Oct 2023 08:04:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHXejWrTbs7fSGdb7h2q/nljYynzLhbUsHzhQKdACrUgypXBgfQ160uMflNt21HOxu/0ms3 X-Received: by 2002:a05:6830:2b2a:b0:6c4:9fda:a1e2 with SMTP id l42-20020a0568302b2a00b006c49fdaa1e2mr18776275otv.4.1698332690767; Thu, 26 Oct 2023 08:04:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698332690; cv=none; d=google.com; s=arc-20160816; b=TafHIZwc5Vr/wLMA1TD8eIi0Phh3u4DnBkEJMG1iQyOFt8TKijqqa9XfMmXwZuMzhQ Hsz8ipSRbru372cJXG5svhpirfZa5zmdXc5FciyVQSlBBlHQMQOYLXuGXofwzwkVCmAB Uxj2gbRg+Ik5NX1JuxgcSlD0Vj6SKLd8dl7v+YDRg02uvPdtSCr23/5CVLmUggEx1DWg CPf8j8C+UHnZOnHNW8YYlHoiHZrO1OO2MsPxeK/qgCzCWe/qjupyIqla9G/lF6N99GVt UghNPIMSpKQYB8GCq4DKQWOjcnq4srn7cGHZNjcK/+zOgC5dSc2OIDH77XREmgKhazfd 3QaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Le7r1qZdjn6tilkqUR5AFBSjzkY/HKzRQy2FXtGZ7Zs=; fh=GOidVxu21BzRNzRs0dBZExJj+efjgFFiKJC2JDUndzI=; b=NZ9WCzEh0Tync0fr4gtesTriJnxA6GInEmJOK4J91EOR2KRuDTcBBoxn9c1neZZsdS l0r7sGM18fOQY9ZRvGmd1jzGT5HI4trlgb4P0MSZvEJrEMPfqcGP/D5Vk3xNl4QW0da2 jc1IGd/CBPLQhUp9HI4SnjRQrGBpKS3fAejXVdwxOPxKqS4+wQsVe16X08DxX5FCuRll 92d+cF0Pon5IEaAbUPGJwaZlXQRxeaQ+5l8YV0joufiYMWwXW2VJcbjzQUlaBYTELYSl Q3mkIxoKWffoxIIO9w1wodPIM4XxFIs+Lhuq6DG33IOuFria5vrm5hAszSVl5IK4CRTI dzNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="W/tQ7Oss"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id c3-20020a67f9c3000000b004577aed33ebsi1564123vsq.812.2023.10.26.08.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 08:04:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="W/tQ7Oss"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id D1885825B536; Thu, 26 Oct 2023 08:04:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231587AbjJZPEC (ORCPT <rfc822;aposhian.dev@gmail.com> + 26 others); Thu, 26 Oct 2023 11:04:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231423AbjJZPDx (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 26 Oct 2023 11:03:53 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A81D18F for <linux-kernel@vger.kernel.org>; Thu, 26 Oct 2023 08:03:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698332583; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Le7r1qZdjn6tilkqUR5AFBSjzkY/HKzRQy2FXtGZ7Zs=; b=W/tQ7OssfYXpdu8enA/aMercHDT0FCXVSiEphS+4aDiOOww45qCG5hE6MllCQc1AyGv6vr bNXiqMFpwCarLQD6HaqkinAWcuD4xMo/8ncuJslcrw6X+CUhXa6rySe1Xkj7V1BNxmjcQc BHOVqvGkqBHhI6mkixi/2Ixc70urLsE= Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-657-nQM2Hu4UMX6Yqa0dw87GYA-1; Thu, 26 Oct 2023 11:02:09 -0400 X-MC-Unique: nQM2Hu4UMX6Yqa0dw87GYA-1 Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-1c9fc94b182so9509375ad.1 for <linux-kernel@vger.kernel.org>; Thu, 26 Oct 2023 08:02:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698332522; x=1698937322; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Le7r1qZdjn6tilkqUR5AFBSjzkY/HKzRQy2FXtGZ7Zs=; b=W0734whwmMKCcia4piRwZ8/RQsslpEIw8KR7Mgu9+LDs11I/AMWFhFKWtjL2bNZfGN 4tU3r8yopgreQlarxTJKaZQemyk+hPeqHs3yLsIhkLInllm0e6rHFjSpgchdpJoUDjd0 v2PZDr432VLu9ELzX/GFueFBKicfvE59GgcbE46zrg3Ca522qFi67nlMLcngOfjyxe6i l+m4u8Om36jKwJyRfbNxtljNtoz2nz2p/Cm/VeS+w4vK+kjIdEKqUaujGgH1ISDRc8Lw ITDLzHglJNZhjZ5KIl5gix43zycysIunTl8UspgjtvUOAxaXijPYlUoo6lI5K3j629eD p5Fg== X-Gm-Message-State: AOJu0Yz4wTLIpHh8cq4Ze/bFQxirDhYcPBxVnWfQOqzS+INCf/66W4Zb 2P5KVyuaPBsPkQQdCsIM0tX+sSMT3LMNTf/hx+oxQde8ageqXRK3+Zg5aLHjIamZrw3zMbJey0R FkSB30i4MMaYkQN5MZINJ/mKY X-Received: by 2002:a17:902:d48b:b0:1cc:c0f:c163 with SMTP id c11-20020a170902d48b00b001cc0c0fc163mr2030475plg.17.1698332522043; Thu, 26 Oct 2023 08:02:02 -0700 (PDT) X-Received: by 2002:a17:902:d48b:b0:1cc:c0f:c163 with SMTP id c11-20020a170902d48b00b001cc0c0fc163mr2030417plg.17.1698332521352; Thu, 26 Oct 2023 08:02:01 -0700 (PDT) Received: from kernel-devel.local ([240d:1a:c0d:9f00:245e:16ff:fe87:c960]) by smtp.gmail.com with ESMTPSA id g11-20020a170902740b00b001c60e7bf5besm11032572pll.281.2023.10.26.08.01.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 08:02:00 -0700 (PDT) From: Shigeru Yoshida <syoshida@redhat.com> To: 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, Shigeru Yoshida <syoshida@redhat.com> Subject: [PATCH net] virtio/vsock: Fix uninit-value in virtio_transport_recv_pkt() Date: Fri, 27 Oct 2023 00:01:54 +0900 Message-ID: <20231026150154.3536433-1-syoshida@redhat.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 26 Oct 2023 08:04:45 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780830899564339537 X-GMAIL-MSGID: 1780830899564339537 |
Series |
[net] virtio/vsock: Fix uninit-value in virtio_transport_recv_pkt()
|
|
Commit Message
Shigeru Yoshida
Oct. 26, 2023, 3:01 p.m. UTC
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(+)
Comments
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
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
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>
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.
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
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);