Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1008629rdh; Fri, 27 Oct 2023 01:52:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE2MLe2yDN868dh8izf7vLOGpoqSPfeyaybki6W+sJfgsQs4RzVAWjB9hDtKEYKIIooSR/U X-Received: by 2002:a05:6808:8db:b0:3b2:eade:5e81 with SMTP id k27-20020a05680808db00b003b2eade5e81mr2088325oij.34.1698396759112; Fri, 27 Oct 2023 01:52:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698396759; cv=none; d=google.com; s=arc-20160816; b=Hy5H22e1TooSH7CxsMY16LL/S8yeTXHX+V+0tiGAHWqj4Y7+vp/rdFC5YjizK52v5G 4Q4K7T3tAt5XlAnOYN6SSOlgE30Ccl4tmGiEpYk0zFk/NWG4bqOs5ACJEROa4G4W6wTY TePWrMprfo5Ooxv5u6REIDpynUksHo+vzmkF4Suw5BD+WN73Ev/3ILD22qIEdifwq5bP /Emoem+vWMuSjnHHjqw0o7tyTO+4qb9yEcLMQYHVcTe6YtAWYDMRyRMDvVwMOODt0yom vFFUJ1p3ChlySqPlfM/CkF8zgnyVIi4v2gObJjMXjjFyru+NO23PEbSKkhcnjjalN+NM mDWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=HeqtBdHG7bcobHfiIzbFtER/jGjT7rW2oiFAlRzp+Fo=; fh=cZcRajNjnQGY8H8qZOGA96ixWgsAaJOzrd+y+R5snN0=; b=FfYKHL7oOCA1O6nFpMQOU9d11eCUVpO0Lq7ToztrQAehcHySRQtECET7k4jPClKYSi +JE2tmT5O8XivuAM/FcBgXWazOgBUHuyosj6BLnAxAsMrRFZWl8andLHtIDXyHMwzpw4 WJVTMImy025vvGBZy9Ds9uL6FocJgESV8ISoj8Dg6K7n8zw6WLaimptoGZ8InbbSDYUj fQ5IjcE2khA+tXiIJG6mOIPFn8rma99guqbtcPr1V+A74F1lSz3Ukj4UXfuKjj6x4JIr mLdVQ+29m277wq6NT3zDrVvU+87sO+OeCEl2fPfF3NtAFb/zQ8Tp6XUDNiARGsv44nTV 6rvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=aecwCwC7; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id u127-20020a256085000000b00d9ad81482a8si1780550ybb.21.2023.10.27.01.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 01:52:39 -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=@google.com header.s=20230601 header.b=aecwCwC7; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 19618804C492; Fri, 27 Oct 2023 01:51: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 S1345578AbjJ0IvI (ORCPT + 99 others); Fri, 27 Oct 2023 04:51:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345526AbjJ0IvH (ORCPT ); Fri, 27 Oct 2023 04:51:07 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5AAB106 for ; Fri, 27 Oct 2023 01:51:03 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-53f98cbcd76so7076a12.1 for ; Fri, 27 Oct 2023 01:51:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698396662; x=1699001462; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=HeqtBdHG7bcobHfiIzbFtER/jGjT7rW2oiFAlRzp+Fo=; b=aecwCwC7wf/tavm+WylLt3U8VkiIEbpWvvGDxdWAp0CbGBAB4PzKDneD/+wKYDMcmf c3PnY149u4AEiGXwjeyGFFjwwZ+opC5bGfdtzokdBHOJlRkNGNBwsJS06zMylomoB2Dh 0tYzpzhHLNd7m4CPrvPZkqJi+qIQpQOqO0U/TRa9sxDxQUE9R8S/oY7sCgyJ+TDf6afl jaJiX+GcZQpXbnS576AcAY4/iA8YbUWd8kjU0AsBM0eya4PndPjDbFO1eEHGdHGOgo8x pdCPGcRo8DVn9o8W4+qaX34h5CbjsZVWsmNC9fGZNzD50AW5vdqWRskhCy/UnBzykCEy Sm0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698396662; x=1699001462; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HeqtBdHG7bcobHfiIzbFtER/jGjT7rW2oiFAlRzp+Fo=; b=FrbEzTZ0OR9Z/V2PNsSRTg3Hpc+pwAsJeavD5ujHY3VDhSzqEvRO0R0ocvlg9VGyrB HMpmNdg/chDreBOldfX1CAADma+9O8bR+O1mPSwJwJKTxNOsjZsE2u0j009vZ/xiIkVE blSYUJlIF+mzah7boGrK3jLo4n73RTYzXy3pAr/J/iXz14oeBXLwFD6QR55XtSWPx3zL wAzQ7xpYKkvJJivstLBkRYzGSw5aQpc2Uwmr6r52dGDvquo9MQQ+a805IRC5XdGql0J/ a1s/S8jLtw+jCYU5ZCkN7aNA+1mulXyns4ITzG3nnBquvLYvBwTIVLKxioj1N4lt/bep D8Yg== X-Gm-Message-State: AOJu0YxhNfnUmo2UXpo7qipYL5SwMHRbn5hH8snwqXCATMyhfFZtP7W4 l2CqhBMOjwmXYxnrAmxUE/x9piB7uMM9CoXmQdq5RQ== X-Received: by 2002:a50:9ead:0:b0:53f:91cb:6904 with SMTP id a42-20020a509ead000000b0053f91cb6904mr105371edf.4.1698396661879; Fri, 27 Oct 2023 01:51:01 -0700 (PDT) MIME-Version: 1.0 References: <20231026150154.3536433-1-syoshida@redhat.com> In-Reply-To: From: Eric Dumazet Date: Fri, 27 Oct 2023 10:50:50 +0200 Message-ID: Subject: Re: [PATCH net] virtio/vsock: Fix uninit-value in virtio_transport_recv_pkt() To: Stefano Garzarella Cc: Shigeru Yoshida , stefanha@redhat.com, davem@davemloft.net, 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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]); Fri, 27 Oct 2023 01:51:22 -0700 (PDT) On Fri, Oct 27, 2023 at 10:18=E2=80=AFAM Stefano Garzarella wrote: > > On Fri, Oct 27, 2023 at 10:01=E2=80=AFAM Stefano Garzarella wrote: > > > > On Fri, Oct 27, 2023 at 12:01:54AM +0900, Shigeru Yoshida wrote: > > >KMSAN reported the following uninit-value access issue: > > > > > >=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D > > >BUG: KMSAN: uninit-value in virtio_transport_recv_pkt+0x1dfb/0x26a0 ne= t/vmw_vsock/virtio_transport_common.c:1421 > > > virtio_transport_recv_pkt+0x1dfb/0x26a0 net/vmw_vsock/virtio_transpor= t_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_transpor= t_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_transpor= t_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-g9f3eb= bef746f #3 > > >Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-1.f= c38 04/01/2014 > > >Workqueue: vsock-loopback vsock_loopback_work > > >=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D > > > > > >The following simple reproducer can cause the issue described above: > > > > > >int main(void) > > >{ > > > int sock; > > > struct sockaddr_vm addr =3D { > > > .svm_family =3D AF_VSOCK, > > > .svm_cid =3D VMADDR_CID_ANY, > > > .svm_port =3D 1234, > > > }; > > > > > > sock =3D 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 alloca= ted > > >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_b= uff") > > > > 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/v= irtio_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_i= nfo *info, > > > hdr->dst_port =3D cpu_to_le32(dst_port); > > > hdr->flags =3D cpu_to_le32(info->flags); > > > hdr->len =3D cpu_to_le32(len); > > >+ hdr->buf_alloc =3D cpu_to_le32(0); > > >+ hdr->fwd_cnt =3D cpu_to_le32(0); > > > > > > if (info->msg && len > 0) { > > > payload =3D 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.co= m/ Yes, I was about to add this tag as well, but you were fast ;) Reviewed-by: Eric Dumazet