Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1232840rdf; Sat, 4 Nov 2023 11:29:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGoDi7o5zmh7ZkWiH7hrgtT7nrDNhEmrrFp7FuYk0ksx6+jVCehDOtll8IYp0Akb/g/jzhX X-Received: by 2002:a05:6a20:938f:b0:17d:f127:d435 with SMTP id x15-20020a056a20938f00b0017df127d435mr28070688pzh.45.1699122565024; Sat, 04 Nov 2023 11:29:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699122565; cv=none; d=google.com; s=arc-20160816; b=fn7JsJDrtjBGIlT4AXPqXh/oG4UEVM7sDgEI6xeULzeQd3BO9AOAGdYIgoH7wHI3a4 cM53Ryi/NJd66iQBJNFGrYo/8BZmQ8ecRNZtu70VwDZmclwLJvkMPKc2m8imaimVVsQm fkIuSV+ArxVmdKNWkHvGyJKPMpTP8zaMMeYeL+MMpjOOVDprZoz/SVweTq0sGNMASmpC EXYBHmKtgrq/AjJ7PL0OIuNn9KRQBLkXskOATj8mf6M1z5OXbP50yS4VvHuC4mX1uI3+ kWVoYBHRzEuAzDFBP8QNfVwnzG4shMrWvmG5+/GRihBq5ogLhcuN62tgECDmKSvLoPBP B1+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=1Raflo2MBCaVxBeRy7GF6tekllGnegpXQwpqv2rpEa4=; fh=ffbU+9pGJhduvI+Qxqz52cuin1tqfLzebV8u4v+s67E=; b=vBIga7mUU7FgDmT8c6FCHl4ksmfdKaSbb02+pBGavfPRTdbjtaZJC/0VoTNFRowjwg QQ+SoUdDWrly3Tlsc2bDbsShm1uh9W1x6ojC/JlUY5m1kmIlvb5lugN+YpAGdVwsRWRS KBY+w8pTVyWZE4pUQ7/8PuL/pvKgScqvOxPx6ID9E/LG13ZWmFZWlKQCE+Mw7OmBSaFX gKUahQKZAT3YCXqdoBMOcIrsO9Mz+umP9d2xk5kOOojfBZbsEqc5RToiu1OO959+qTdi hgBoFSePbeDngVBWhd5YMe/zrACx5PVOfz34F1RnUXJ8mBkeIufO2itBPfHWKsm5Ofal j3LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@davidwei-uk.20230601.gappssmtp.com header.s=20230601 header.b=ScwqdFiH; 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 Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id lm15-20020a170903298f00b001c604fdbb14si4567758plb.81.2023.11.04.11.29.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Nov 2023 11:29:25 -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=@davidwei-uk.20230601.gappssmtp.com header.s=20230601 header.b=ScwqdFiH; 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 Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 6BFB880926B7; Sat, 4 Nov 2023 11:29:22 -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 S229470AbjKDS2n (ORCPT + 99 others); Sat, 4 Nov 2023 14:28:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229657AbjKDS2g (ORCPT ); Sat, 4 Nov 2023 14:28:36 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 649951BC for ; Sat, 4 Nov 2023 11:28:32 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6c10f098a27so2632857b3a.2 for ; Sat, 04 Nov 2023 11:28:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1699122512; x=1699727312; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=1Raflo2MBCaVxBeRy7GF6tekllGnegpXQwpqv2rpEa4=; b=ScwqdFiHbXZNgbXoMVlLHyOWjkB3JCmJGcSM1LgTY1yV3eOfjh0d7ddz0j74dkmzGp xQHsfNaSo7NW+aSpEV0GV7/H4XAHxPjN/ZxqhlI3ACUhkiWgI1+PkzyueL1yMM1gkq2J S2UZBkIwbFO7sNJYOz9XivhzOkvLm47TrjhcWt5NVuX0/XAkO8R57XmCTXKxZLNSC0zW FCfGnHlJClnbdX79VS2+azRCS0eqY9oMSz34+IDKZ4H+sZaG8J8ZWbPIIsxpCgbdgu5T 9Q5rPh21kJ+6FwfB6JUPBS5YC9TJsLDGc9z+e5SXy3szoiANAZwhEBXuulcyQzCRvNkL aeow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699122512; x=1699727312; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1Raflo2MBCaVxBeRy7GF6tekllGnegpXQwpqv2rpEa4=; b=Em1p21SPWa6zUTc1q5/mqwEw66JmWz/6pfifR/A+EDsAxoIv5AZ+uQ4IGW13WatuYi jmmoti9pUlkVvGle77kA7OjZKWrlSnF6z35gqgboDJr1OmGoeBjf7Vj9fUr7cKPaXohU ee8IDueQTuKlLQBg5uUIxggdg4tXxtCNVWTbN/WEwjFORj2MHaIJ/UD7hYlxe2MB/56W spCd7Pbo9dclgHRHV6ghLw2KEAEHonqBsOuyLUX3oAXD42UFWRa65mQWMiFWuwl882ME ls9UQuKcYlkWQqFHBlDfS8lrduYlwQH3lwOcLXGS87KtqT801oWlGIeceH9FFf0y8oU3 fGDw== X-Gm-Message-State: AOJu0YxxYc9PjVvQPSby1Vo3RiK00ftjxOTQ/umqeNhmq6FxDdcxyZig fujofdAhYq1SaevTZmjdSyvb2Q== X-Received: by 2002:a05:6a00:3a0e:b0:6c3:402a:d54d with SMTP id fj14-20020a056a003a0e00b006c3402ad54dmr6843336pfb.11.1699122511816; Sat, 04 Nov 2023 11:28:31 -0700 (PDT) Received: from ?IPV6:2620:10d:c085:21e1::1052? ([2620:10d:c090:400::4:56eb]) by smtp.gmail.com with ESMTPSA id h1-20020a056a00230100b006889511ab14sm3187642pfh.37.2023.11.04.11.28.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 04 Nov 2023 11:28:31 -0700 (PDT) Message-ID: <67c45ff3-4f98-4ca5-bd68-2d90cc52a775@davidwei.uk> Date: Sat, 4 Nov 2023 11:28:28 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net v2] virtio/vsock: Fix uninit-value in virtio_transport_recv_pkt() To: Shigeru Yoshida , 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 References: <20231104150531.257952-1-syoshida@redhat.com> Content-Language: en-GB From: David Wei In-Reply-To: <20231104150531.257952-1-syoshida@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, 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 11:29:22 -0700 (PDT) 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 > --- > 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,