From nobody Sat May 18 23:14:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1670250255; cv=none; d=zohomail.com; s=zohoarc; b=NpB3Zi2+iy2OQ5nJsjQybRfHiN+Uqgjm8EaSkm16y44GCbovI9PeINHLfrbucdPddXJBejpUtYvV6WhNutm2c28DidMsfAON7xiqFqM80hNhW7EQJXxUWJ5Q4PWTvrhukBkRqon1t6NS/0tws9ERJ2uQdjZYC0Mjt0SVSzAUPuM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670250255; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=gv/ji/spQ+QL/0x+hNJxAEagajO9tnSwvuQdlmrPNj8=; b=K55GB0PPeuPrCwa2G/LZiftaOHZGHqsa27MLSGcDXi2DToRkdUNZCDSgkp9exKnrsP7YppziI2/Z4HTA7D8c1L7S5n9Tmss4RHMBBkbyCx78NIygUivPwYqFTH1NYuMsDTqKAL1FV+HWcflxTuSadfqEx1YZEYYgbTikjOiRaP0= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1670250255394667.3994548085503; Mon, 5 Dec 2022 06:24:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p2CN3-00018T-0G; Mon, 05 Dec 2022 09:23:01 -0500 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 1p26Xs-0005nU-50 for qemu-devel@nongnu.org; Mon, 05 Dec 2022 03:09:52 -0500 Received: from szxga02-in.huawei.com ([45.249.212.188]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p26Xp-0007Sj-Kx for qemu-devel@nongnu.org; Mon, 05 Dec 2022 03:09:47 -0500 Received: from dggpemm500010.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NQblv4CTvzFqfQ; Mon, 5 Dec 2022 16:08:43 +0800 (CST) Received: from huawei.com (10.174.185.41) by dggpemm500010.china.huawei.com (7.185.36.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 5 Dec 2022 16:09:30 +0800 To: , CC: , , , Subject: [PATCH] net/net.c: Fix qemu crash when hot-pluging a vhost-net failed. Date: Mon, 5 Dec 2022 16:08:59 +0800 Message-ID: <20221205080859.2216-1-yangming73@huawei.com> X-Mailer: git-send-email 2.32.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.185.41] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500010.china.huawei.com (7.185.36.134) X-CFilter-Loop: Reflected 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=45.249.212.188; envelope-from=yangming73@huawei.com; helo=szxga02-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 05 Dec 2022 09:22:55 -0500 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: , Reply-to: Ming Yang From: Ming Yang via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1670250255815100001 Content-Type: text/plain; charset="utf-8" Hot-pluging a vhost-net may cause virtual machine crash in following steps: 1. Starting a vm without net devices. 2. Hot-pluging 70 memory devices. 3. Hot-pluging a vhost-net device. The reason is : if hotplug a vhost-net failed, the nc cannot be found via f= unction qemu_find_netdev, as it has been cleaned up through function qemu_cleanup_net_client. Which lead= s to the result that assert(nc) failed, then qemu crashed. While, the root reason is that, in commit 46d4d36d0bf2 if not both has_vhos= tforce and vhostforce flags are true, the errp would not be set. Then net_init_tap would not return a n= egative value, fallowed by founding nc and assert nc. In this patch, asserting nc is replaced with setting an error message. Fixes: 46d4d36d0bf2("tap: setting error appropriately when calling net_init= _tap_one()") Signed-off-by: Ming Yang Signed-off-by: Liang Zhang --- net/net.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/net/net.c b/net/net.c index 840ad9dca5..1d1d7e54c4 100644 --- a/net/net.c +++ b/net/net.c @@ -1103,7 +1103,16 @@ static int net_client_init1(const Netdev *netdev, bo= ol is_netdev, Error **errp) =20 if (is_netdev) { nc =3D qemu_find_netdev(netdev->id); - assert(nc); + /* + * If the tap of hotpluged net device do not has both has_vhostfor= ce flag and vhostforce flags, + * when error occurs, the error messags will be report but not set= to errp. Thus net_client_init_fun + * will not return a negatave value. Therefore the value of nc mig= ht be NULL. To make qemu robust, + * it is better to judge if nc is NULL. + */ + if (!nc) { + error_setg(errp, "Device '%s' could not be initialized", netde= v->id); + return -1; + } nc->is_netdev =3D true; } =20 --=20 2.33.0