From nobody Sun May 19 02:06:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1687952524; cv=none; d=zohomail.com; s=zohoarc; b=HKBW48Y7KMQMSmnPWhrr9+In4GL/HndAPg2fuNhMZK4T+0J4/AFV3EufojhVFBED0nzCafhUOCAfQsPWEeG2iXT6YWoUJwYCbaDC4TV13YRu35PK3HGM1iGHrISyT8/aQFcw2pwMrDmEcOjqUmE4f0YCDTn36Puvr68h8bWtcP4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687952524; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2fTK9GwBDg4mE+sgETpJKJTdC5LWsXGre4VDShxla8I=; b=YcSrek62ipY1iD0zM6BXk43bLpKaemKZr4LDaJDBn3GZumAzVOfmE7zVG+i4q3tiA6tO0g3F1tl5E94Zd/lYps6zqTWMAJ9s40oLYEvhH+EJN6vlKg9EFZDjbVzuM+8acR8OvKyK1MB7JEv6GEFs3EaHipUyGQZZpIvxl5KajyA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168795252427947.23150388318186; Wed, 28 Jun 2023 04:42:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qETYO-0006QU-NV; Wed, 28 Jun 2023 07:41:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qETYM-0006Po-G4 for qemu-devel@nongnu.org; Wed, 28 Jun 2023 07:41:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qETYK-0000bq-Qy for qemu-devel@nongnu.org; Wed, 28 Jun 2023 07:41:42 -0400 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-175-_YcKtDJFNFG2tTH480aVCA-1; Wed, 28 Jun 2023 07:41:39 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-3f9b003507bso28640745e9.0 for ; Wed, 28 Jun 2023 04:41:38 -0700 (PDT) Received: from redhat.com ([176.12.183.225]) by smtp.gmail.com with ESMTPSA id er8-20020a05600c84c800b003f7f475c3bcsm5742508wmb.1.2023.06.28.04.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 04:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687952500; 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=2fTK9GwBDg4mE+sgETpJKJTdC5LWsXGre4VDShxla8I=; b=SyqXUovMc86770N3+HBksjswQP/lNSy73XppisRBbUA56CbKpnUpFg+ifohOyczMhnHT/c DeAuDlWWJA01DTo9sTp25F+N9IOMoN02M9XnZyXTGVeGveAOd7TjqD9e4QwL1PEqGqa6On 0zuLXXe1amgO+ovpj+acHQOBzPnixxk= X-MC-Unique: _YcKtDJFNFG2tTH480aVCA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687952497; x=1690544497; 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=2fTK9GwBDg4mE+sgETpJKJTdC5LWsXGre4VDShxla8I=; b=NI6N4z1pm6mRpsRMXYwiVdPhiyE7UUnMppuLBPABqClck3avKfYSC7ZitmDL/RsZbK Yxb7xiItdyjHuSjL76NbOi0efUoAe0Culz9FjHngRYg8IgYUUBWXIXKG8jWjVB9nF/Hl E/ub94UQQndLpTUkvKFjs6p3fg5xuoXjxa8CHcd6cJLJT6lDDsAih6jeVC496wTb3qaf WAoSa6uRycBhQ5kTtIUqSWRTsYDdFO5D0v2bwfx3Q9a4gQLoFitBzuuo/Voznjp/j1L5 yh+Yo4QR7W61aIpugnZtw4XafY+35FB9EurZcGjvnAIBXLH6ZWebCdkGx8tsnDk7Chsf Ib0w== X-Gm-Message-State: AC+VfDxo0PNehwKC/b+llkmRFsbgwDb+5rrGPX3iau23mvQE2s6GGSZX tLRz5sdQ6eAzVdtmnvYFO9hAVFqt+Bxlbj/apfk4nluHF4UhqFYegVLULn4f3nNjFtqHOiSDGf2 7CC7lgElmrWBqkRlYSSYFGpz+SYxb0f6E0ia0ZBPYeVPbubAR1UxvjwS3SBk1NP3x6Lbo5ag= X-Received: by 2002:a05:600c:215a:b0:3fb:b34f:6cd4 with SMTP id v26-20020a05600c215a00b003fbb34f6cd4mr833522wml.36.1687952497407; Wed, 28 Jun 2023 04:41:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4oMhqTC8XubzXynwekukMgz2sP/q1ISLRytryN92AByIJUelUaAwqeJYvPF5Z4e+uC3VEP5Q== X-Received: by 2002:a05:600c:215a:b0:3fb:b34f:6cd4 with SMTP id v26-20020a05600c215a00b003fbb34f6cd4mr833502wml.36.1687952497035; Wed, 28 Jun 2023 04:41:37 -0700 (PDT) Date: Wed, 28 Jun 2023 07:41:34 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Ani Sinha , =?utf-8?Q?C=C3=A9dric?= Le Goater , Jason Wang Subject: [PULL 1/1] net/vhost-net: do not assert on null pointer return from tap_get_vhost_net() Message-ID: <0585e97f070014265e5ec3b28d27dcb963cde25b.1687952477.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1687952526520100003 From: Ani Sinha When 'vhost=3Doff' or no vhost specific options at all are passed for the t= ap net-device backend, tap_get_vhost_net() can return NULL. The function net_init_tap_one() does not call vhost_net_init() on such cases and therefo= re vhost_net pointer within the tap device state structure remains NULL. Hence, assertion here on a NULL pointer return from tap_get_vhost_net() would not = be correct. Remove it and fix the crash generated by qemu upon initialization = in the following call chain : qdev_realize() -> pci_qdev_realize() -> virtio_device_realize() -> virtio_bus_device_plugged() -> virtio_net_get_features() -> get_vhost_net() Fixes: 0e994668d00c9c ("vhost_net: add an assertion for TAP client backends= ") Reported-by: C=C3=A9dric Le Goater Report: Signed-off-by: Ani Sinha Message-Id: <20230628112804.36676-1-anisinha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/net/vhost_net.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 6db23ca323..6b958d6363 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -507,7 +507,12 @@ VHostNetState *get_vhost_net(NetClientState *nc) switch (nc->info->type) { case NET_CLIENT_DRIVER_TAP: vhost_net =3D tap_get_vhost_net(nc); - assert(vhost_net); + /* + * tap_get_vhost_net() can return NULL if a tap net-device backend= is + * created with 'vhost=3Doff' option, 'vhostforce=3Doff' or no vho= st or + * vhostforce or vhostfd options at all. Please see net_init_tap_o= ne(). + * Hence, we omit the assertion here. + */ break; #ifdef CONFIG_VHOST_NET_USER case NET_CLIENT_DRIVER_VHOST_USER: --=20 MST