Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1153585rdf; Sat, 4 Nov 2023 08:21:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGux8AxTyQ1/AjYOuRh9okeoWynNJJ5T/7b9qb/vyU3kexV1dxKlGBClN4AylPqO9Yf8Hor X-Received: by 2002:a17:90a:208:b0:25e:a8ab:9157 with SMTP id c8-20020a17090a020800b0025ea8ab9157mr21164205pjc.22.1699111292847; Sat, 04 Nov 2023 08:21:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699111292; cv=none; d=google.com; s=arc-20160816; b=yCeYQgQEUHtjwDQ9GP3rUs23xt3YX4ehgqNfc66Z57lvF7SOWqpxIS+Gg8SNP6mM8K 9BV2EfSgsKGCSZeWWHr6IXNPmUhjNULFFRCGDNeFlhAkXwjbyrIqkoivhx5iwl6YKxvm VbhtcVl2tOaygB8IxAs0tkiYJ6B5j7maHuUUppApRXBnaYto7NVzKQNCcrQwSq+p081b rtFxEHmPrERJSweE2byB3PFuNz9ps30DpE57/yhBJOCi1tkdL2JvGLaI+EO7Tt0DNGwf Q9AtsjASjkshbj51PiK7MwsrrG79PPuvfKPNg9Wm7QsjXdClujNmHt6Q3K0jfYE9Jvr/ ScOA== 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=i9z4ksAJKoBaMot+I42cegftv20OKEb1WSe8JorPWis=; fh=jsrvNFlwLWdD2RzyiZiS2RWIuye1OzvzU7zFnQXaaR4=; b=FdLF5A1w8e36CUR7QfUDl2+tVswLATvTMxMRMlmd9ANYRqJ+r4sD8TzfuQaREugEPQ FmmG0K3CywC0e2rmaICVjOlfYuL4LleWtSgJ4gzO/S4+NmguCmSSEiAC/BfRmdeFhPtc 9lbBwpqH6hq5p7liqXyaqvYxQbK8XFoTOQaPOlZETlOJYTeQkKcNLF9axte0GqzVxL6k VvaMdePm9w8YyHVCBl8/BqDEVwdN5dZ15o7voQFnjJ5dpCKJB/Blvbda+g5wG5PWZwJ7 4oP9Vcjkck74O+VzD9Ln3YA+UaJ/M1Fyiy8EmPI+ot2x+w8sgHGhJJcys+KlK06hBMU/ myXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LzRdBNgd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id o11-20020a17090ac70b00b0026c198d8182si4125463pjt.105.2023.11.04.08.21.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Nov 2023 08:21:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LzRdBNgd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 14CF980AA253; Sat, 4 Nov 2023 08:21:29 -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 S229491AbjKDPGc (ORCPT + 99 others); Sat, 4 Nov 2023 11:06:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjKDPGb (ORCPT ); Sat, 4 Nov 2023 11:06:31 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 629671BF for ; Sat, 4 Nov 2023 08:05:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699110341; 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=i9z4ksAJKoBaMot+I42cegftv20OKEb1WSe8JorPWis=; b=LzRdBNgdwHzFiu4aFvzRj+HyKpTMQLvsPl8BrnxdzHAdLaI7D8LoGQ26oU3wDpQ2FLVRs/ 3QNAOj+8xB9ZrHCejqOrL+OXgZng7oeykNSXOVKMVQS9q9E9HZ7uOFrQSQ15m4VSB2NShV BHOxCqYZbuLJxGnWTfcZvCNbFmzxs0k= 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-352-w0JeEimTMs6biwJAgfJoQw-1; Sat, 04 Nov 2023 11:05:39 -0400 X-MC-Unique: w0JeEimTMs6biwJAgfJoQw-1 Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-1cc2efd22ccso26037285ad.1 for ; Sat, 04 Nov 2023 08:05:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699110339; x=1699715139; 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=i9z4ksAJKoBaMot+I42cegftv20OKEb1WSe8JorPWis=; b=ZE3htOF8MnKUAvYgw0wNTMAAP5RvI+QCPVnJnJoXQYbRXaOG3TruJrrPYR4VBsexl+ 7X1+rKc1edbrpudSePBN9iTs57VoXugG82FyjNMSwBmUIxhtS8BIut5P6kiXSmM2wD6X fEscywTykZnNBAh1fA0ufgL2oo/pVr8aIqQtDLZcOpzTXunjc21YjUoXA/yXiwDfnjdh V2tQsmO5/F6cp2bkMdC+dqW9jd8s4fVRUIWmHYmX2nnDOn8WkgGiU33YYvoDydOBm+Eo 3qSe2RaDwfqLChUjJSLWw84HnSK1pxOVB5vxvGLjuBVfHzd5UU0iuG27FxUyO3SjMNce b3SA== X-Gm-Message-State: AOJu0YzAy6WmeFKRSA94epLaFFofPSGrN3IWVZNK9dBqVrR06Rls74n/ mPlxlMEEyADLFox7YB3qfR+kDMiRXMy7TD44ptXCYjZIkTOxwZ/eVE7tVUpNthhKsxIQ9ziwOeI p0SI6WaCBaX4VV/R+6gqiyMk0 X-Received: by 2002:a17:902:e811:b0:1cc:569b:1df4 with SMTP id u17-20020a170902e81100b001cc569b1df4mr20338642plg.1.1699110338876; Sat, 04 Nov 2023 08:05:38 -0700 (PDT) X-Received: by 2002:a17:902:e811:b0:1cc:569b:1df4 with SMTP id u17-20020a170902e81100b001cc569b1df4mr20338619plg.1.1699110338500; Sat, 04 Nov 2023 08:05:38 -0700 (PDT) Received: from kernel-devel.local ([240d:1a:c0d:9f00:245e:16ff:fe87:c960]) by smtp.gmail.com with ESMTPSA id jf7-20020a170903268700b001ca21c8abf7sm3101797plb.188.2023.11.04.08.05.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Nov 2023 08:05:38 -0700 (PDT) From: Shigeru Yoshida 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 , syzbot+0c8ce1da0ac31abbadcd@syzkaller.appspotmail.com Subject: [PATCH net v2] virtio/vsock: Fix uninit-value in virtio_transport_recv_pkt() Date: Sun, 5 Nov 2023 00:05:31 +0900 Message-ID: <20231104150531.257952-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=-1.4 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,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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: 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]); Sat, 04 Nov 2023 08:21:29 -0700 (PDT) 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 --- 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); } static void virtio_transport_copy_nonlinear_skb(const struct sk_buff *skb, -- 2.41.0