Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp995040rdh; Fri, 27 Oct 2023 01:20:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG0mXULFfUsBmp42+dWojaojrry3PR6urquGzl1VS3ahb2Flvsoshb04F54Ag5cibNZV0PL X-Received: by 2002:a67:cc1a:0:b0:458:19d4:415e with SMTP id q26-20020a67cc1a000000b0045819d4415emr2190228vsl.1.1698394808486; Fri, 27 Oct 2023 01:20:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698394808; cv=none; d=google.com; s=arc-20160816; b=z71rbUsUL/ssxem6n3ACfohWmgUtSMSLjtV4xPTO9oaqLkBTb0A2aIbzkLotVuWf4d C67Fh1Tv3XYH/p3/C0uBclj8XSjROaESsmDLaw9n1IUTgswU2WhH8hiozDtJldjz9v79 6s6LE99Dx8eEsuPYUbUDWto5HSaml6vpva9s57GtnXh+E018vgItkXleip/bB2u9Enfc FQblkSnL+Z1oxruLZlB/MA/JMj3K0PJKy7PZSIV8bCZ9EhNnotSIK9cI8lJ3hY/fml28 vSewmsZpoTBnQ7efRid3OqYG1bUbmaLEzErbOm82AFijcDMFQ6zPB5IXl0NqslU9JuOp qGkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=JfITEsiltCW1D4ziBTO0kE6Y9MiSeu2U9dsQlUHf3Iw=; fh=0cAkcOiX6BqlG0WkYyLekXUay/VCpESjGDtmV0a00lM=; b=A6W9psIGNrjrHks1UkQsDuKLo8zsxcGUwffoxh3PRlaxTOI5XaWFfJBEblxTOl/NJu wJu2vItfY0zDdNPLFEdydGClcWA0HrWl7WrlM0Zt1GmzIs6h3ZbuwSmPlsmSoZKhKrv1 dQ/K7u+3k2WJxNm0isIcufX3E0Px52k7Dg2/6b1Zb/KpEOhs5ygzPVDhyFGfY4iIKONf XJL6jUKTJ5Ob3v2yris9RplCrR7vxCaI2kNgSi1MjBpKY6RMV8TzuQznOzXba21x3GB8 Joq/SEdDpibKpyAvdSmHCZ2ApKm2gSKQ0FyV9Kd7RHx10/hxZBop2TIgTsBINCOdk0ME tCyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bHwZZeYw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id 78-20020a250551000000b00da0c88823basi1664871ybf.151.2023.10.27.01.20.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:20:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bHwZZeYw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id E069C8330E91; Fri, 27 Oct 2023 01:19:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235134AbjJ0ITq (ORCPT + 99 others); Fri, 27 Oct 2023 04:19:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235158AbjJ0IT3 (ORCPT ); Fri, 27 Oct 2023 04:19:29 -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 23D9C1B4 for ; Fri, 27 Oct 2023 01:18:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698394716; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JfITEsiltCW1D4ziBTO0kE6Y9MiSeu2U9dsQlUHf3Iw=; b=bHwZZeYwiQEsRRfU/d4epJ2XH0PNd2JCFMsIOJamEKycoDEVrKBHYbz/TrjPAI+vU6y1cR UBhJpqaJFKOSgWN4bDw7FxNhSronpR2SrEho/9cJzok7uEaud4balYSYh5mI/z6xfU86Ha GecFEiEQCXN+zS5oSF0/APdWI4kPLXc= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-648-aw_bgI32O5C7_PO2tw0mGQ-1; Fri, 27 Oct 2023 04:18:34 -0400 X-MC-Unique: aw_bgI32O5C7_PO2tw0mGQ-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4084e263ec4so13650255e9.2 for ; Fri, 27 Oct 2023 01:18:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698394713; x=1698999513; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JfITEsiltCW1D4ziBTO0kE6Y9MiSeu2U9dsQlUHf3Iw=; b=eNRTmL9F9Q9WmFuDlbCvQVC6vzMaKBD12dNjXRIUr7ipPsiqD7pWEaKpfXKRp1kKTC dgQcV13+Izp8ZWGwV5sDxCIF2OvIwn0T4AdBHxRik8PxxbbPKB5wsT2IItyPnfq95gmq ij3OemXvXOaE/WoSjQHuxa+5hWbcACJKmw4Gb+ROK4lyz76gGpwLIxzJupwautjFkEwq CRdZo5vHPOupm0HuMbWRVhwRzFWc5k/k9C120nQl/gbV+fPw2rWNx+M2GeEpLQcQyF2l IUtVJQcgqwhzKor7OXGodldRCiARNidz2ImriXqMyd9QxwcYgSG0gENjFOlGU2SVmJ30 nnPA== X-Gm-Message-State: AOJu0YyTqN1iVyzBtjUZVvGkwgNtcszrs9ELqhyGl7GzErgI/A/LSLfl uQzsI8KcPPMAyanKEH1IBW1fs6n71ZhSSsslcK95ZzaQubeAiMLFriRy8/GsIKZ4IepYUoOJlFQ VH1qGqz/Bws52pzaXIQo/t0wO X-Received: by 2002:a05:600c:259:b0:407:5a7d:45a8 with SMTP id 25-20020a05600c025900b004075a7d45a8mr1874918wmj.31.1698394713569; Fri, 27 Oct 2023 01:18:33 -0700 (PDT) X-Received: by 2002:a05:600c:259:b0:407:5a7d:45a8 with SMTP id 25-20020a05600c025900b004075a7d45a8mr1874889wmj.31.1698394713124; Fri, 27 Oct 2023 01:18:33 -0700 (PDT) Received: from sgarzare-redhat (host-87-12-185-56.business.telecomitalia.it. [87.12.185.56]) by smtp.gmail.com with ESMTPSA id d17-20020adff851000000b0031ad5fb5a0fsm1211238wrq.58.2023.10.27.01.18.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:18:32 -0700 (PDT) Date: Fri, 27 Oct 2023 10:18:26 +0200 From: Stefano Garzarella To: Shigeru Yoshida Cc: stefanha@redhat.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bobby.eshleman@bytedance.com, bobbyeshleman@gmail.com Subject: Re: [PATCH net] virtio/vsock: Fix uninit-value in virtio_transport_recv_pkt() Message-ID: References: <20231026150154.3536433-1-syoshida@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 howler.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 (howler.vger.email [0.0.0.0]); Fri, 27 Oct 2023 01:20:00 -0700 (PDT) On Fri, Oct 27, 2023 at 10:01 AM Stefano Garzarella 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 > >--- > > 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 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