Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp4676250rwb; Wed, 17 Aug 2022 04:24:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR6Ha4pB4P8dhUbOcbRNE4+Zl/15dGUrgcrkDlWdFNxu1QJmM6VzRt9lMirxfEhf2r9TQYpT X-Received: by 2002:a17:902:854b:b0:170:d646:d69 with SMTP id d11-20020a170902854b00b00170d6460d69mr26230621plo.135.1660735449189; Wed, 17 Aug 2022 04:24:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660735449; cv=none; d=google.com; s=arc-20160816; b=g1l2/bGDdHuhFKxOxKMWx/q0jEQeLd8HCq3PwBfdH7Xd36sZVPd5P6eV5TqqT50IrH fAoVUbclqkegKbCUPyVuXnMntndmydrQJeFf+x9mGnVfz9rH8pcNA9Tz5eLgFpcUJnDM qIROuEJ05o/zAZm9bW6TTwz4ewmpNjFD5i4O3kN8OLZNeRGZ3DEQuaXpHclOvCBbqPg6 ewnBWcuYXFVBmSb03d3NXoW+rXxTp39vorBznEOjtqDJzws5Rc/UYrPghL6XaDYVYeCg qRFhmpLgj2Cihr/Azvv+XSYQkvFnQ1gKIdMGc1rUiDOMm0+sHOi7fjdRLJt0Uk8a6/R3 AAwA== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=gWHtHY6d40uY0Ij4s58yaxGtL5XuSJS0/N+jf5H/pmM=; b=xxUPKqC0F/OqbsXw5cdfGjLNazTPjleZL8tzi9k7IRHrXMwamvIUlsG4xngG0SKj39 4QC34Wa/o7l0kOAzFvy7mxJkYOy5NRoFBZrsnp8z7UFP4VCQw0ln8ytN5qfw8xPh3xCj KljmMOhZNVLjVmC+UFIsTlYfJu9z29uIy/qWBqYYgoSwCt1GSujpHpGnY+U8zhefet7u KhBcmJBx2HGH4no2R+0Uaxuk5KY3fImO17Vwfw/hA9BrYZr67X6+mvIOqR4xc5qFmv/J 7P3YsW8VFWAyfpEvugMy7W2vIil2GL/I7P1wdQcMofnd5AsO59JJPA3bebhK1AlLOxcc /Aag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S8+n9d3K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j12-20020a170903024c00b0016c049ada3csi1133463plh.454.2022.08.17.04.23.58; Wed, 17 Aug 2022 04:24:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S8+n9d3K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229930AbiHQKyI (ORCPT + 99 others); Wed, 17 Aug 2022 06:54:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234506AbiHQKyE (ORCPT ); Wed, 17 Aug 2022 06:54:04 -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 2AD844A83F for ; Wed, 17 Aug 2022 03:54:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660733642; 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: in-reply-to:in-reply-to:references:references; bh=gWHtHY6d40uY0Ij4s58yaxGtL5XuSJS0/N+jf5H/pmM=; b=S8+n9d3Kax4NRRwTfe9hCHnS0x43t5BvUwNfVbbp8VBEi6ndhK9Y15mKdOCFx+MSZ5+Uwi sF3WUmXKrMhtgWLak5q6Pj8lyU8htzgmXEgXfkOBL7qUbaLV4VT5sQoGeQSXzVBTo21pD1 6iP3wN9tU5lGa6efxaZd/aVjhomF5bc= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-556-PvU81CrMMaibchX8botS0g-1; Wed, 17 Aug 2022 06:54:01 -0400 X-MC-Unique: PvU81CrMMaibchX8botS0g-1 Received: by mail-wm1-f72.google.com with SMTP id r10-20020a1c440a000000b003a538a648a9so6174832wma.5 for ; Wed, 17 Aug 2022 03:54:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=gWHtHY6d40uY0Ij4s58yaxGtL5XuSJS0/N+jf5H/pmM=; b=3xf4eAbdTfMPTPlbdDGuGJX9AMlt6UVHaEQE0Da+UG+92x+37djnrBdiy1IVGiOQhz hTiVrndCOWwf8EA+uJ6YK88vb0J0waqecx8ZwvX7mtXJNarc8d7MEbeTtLuObuODGHQa jXWBZXEpxbIJdo7eeLhePB7H557R92RHicO9Qtl/XR9dVEzlhvzyTNc+HOuNJLLcBwQQ GKu5oudQyxrWePyPHXdxTn6aDL0/Kqf4rwJbMsfIxVbtlsWrtxwz5VV2/QVPFvdc+bdE a6o294Gw7L4ZJ6Og3+M6CE9KYSR0Q13XiR1WjjiiXIAKyjYA3K91oOyP5adHt6OjDtSW w9/Q== X-Gm-Message-State: ACgBeo23ZXtoWoUCz9yQapmbI3HYNKbKaiVJasT+sX/CNyEn46LHZeDo qOoosSHY2N5TO4MvJJt8koDyEpQeM200ETuNrZZh9V0DGFdYO3Qo6eQZPk4UUNiLV1fR9dnMOmd 2PPFd5SQ6oycD0tAgwT0FeXSS X-Received: by 2002:a05:600c:4e11:b0:3a5:bfd3:a899 with SMTP id b17-20020a05600c4e1100b003a5bfd3a899mr1743689wmq.185.1660733639794; Wed, 17 Aug 2022 03:53:59 -0700 (PDT) X-Received: by 2002:a05:600c:4e11:b0:3a5:bfd3:a899 with SMTP id b17-20020a05600c4e1100b003a5bfd3a899mr1743679wmq.185.1660733639576; Wed, 17 Aug 2022 03:53:59 -0700 (PDT) Received: from redhat.com ([2.55.4.37]) by smtp.gmail.com with ESMTPSA id p27-20020a05600c1d9b00b003a35ec4bf4fsm1905896wms.20.2022.08.17.03.53.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Aug 2022 03:53:59 -0700 (PDT) Date: Wed, 17 Aug 2022 06:53:53 -0400 From: "Michael S. Tsirkin" To: Xuan Zhuo Cc: Dmitry Vyukov , James.Bottomley@hansenpartnership.com, andres@anarazel.de, axboe@kernel.dk, c@redhat.com, davem@davemloft.net, edumazet@google.com, gregkh@linuxfoundation.org, jasowang@redhat.com, kuba@kernel.org, linux-kernel@vger.kernel.org, linux@roeck-us.net, martin.petersen@oracle.com, netdev@vger.kernel.org, pabeni@redhat.com, torvalds@linux-foundation.org, virtualization@lists.linux-foundation.org, kasan-dev@googlegroups.com Subject: Re: upstream kernel crashes Message-ID: <20220817065207-mutt-send-email-mst@kernel.org> References: <20220815113729-mutt-send-email-mst@kernel.org> <20220815164503.jsoezxcm6q4u2b6j@awork3.anarazel.de> <20220815124748-mutt-send-email-mst@kernel.org> <20220815174617.z4chnftzcbv6frqr@awork3.anarazel.de> <20220815161423-mutt-send-email-mst@kernel.org> <20220815205330.m54g7vcs77r6owd6@awork3.anarazel.de> <20220815170444-mutt-send-email-mst@kernel.org> <20220817061359.200970-1-dvyukov@google.com> <1660718191.3631961-1-xuanzhuo@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1660718191.3631961-1-xuanzhuo@linux.alibaba.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 17, 2022 at 02:36:31PM +0800, Xuan Zhuo wrote: > On Wed, 17 Aug 2022 08:13:59 +0200, Dmitry Vyukov wrote: > > On Mon, 15 Aug 2022 17:32:06 -0400, Michael wrote: > > > So if you pass the size parameter for a legacy device it will > > > try to make the ring smaller and that is not legal with > > > legacy at all. But the driver treats legacy and modern > > > the same, it allocates a smaller queue anyway. > > > > > > Lo and behold, I pass disable-modern=on to qemu and it happily > > > corrupts memory exactly the same as GCP does. > > > > Ouch! > > > > I understand that the host does the actual corruption, > > but could you think of any additional debug checking in the guest > > that would caught this in future? Potentially only when KASAN > > is enabled which can verify validity of memory ranges. > > Some kind of additional layer of sanity checking. > > > > This caused a bit of a havoc for syzbot with almost 100 unique > > crash signatures, so would be useful to catch such issues more > > reliably in future. > > We can add a check to vring size before calling vp_legacy_set_queue_address(). > Checking the memory range directly is a bit cumbersome. > > Thanks. With a comment along the lines of /* Legacy virtio pci has no way to communicate a change in vq size to * the hypervisor. If ring sizes don't match hypervisor will happily * corrupt memory. */ > diff --git a/drivers/virtio/virtio_pci_legacy.c b/drivers/virtio/virtio_pci_legacy.c > index 2257f1b3d8ae..0673831f45b6 100644 > --- a/drivers/virtio/virtio_pci_legacy.c > +++ b/drivers/virtio/virtio_pci_legacy.c > @@ -146,6 +146,8 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, > goto out_del_vq; > } > > + BUG_ON(num != virtqueue_get_vring_size(vq)); > + > /* activate the queue */ > vp_legacy_set_queue_address(&vp_dev->ldev, index, q_pfn); > > > > > > Thanks