From patchwork Mon Jul 22 13:24:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11052369 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CFD526C5 for ; Mon, 22 Jul 2019 13:25:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEC7D2847E for ; Mon, 22 Jul 2019 13:25:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B228B28508; Mon, 22 Jul 2019 13:25:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HK_RANDOM_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4D3102847E for ; Mon, 22 Jul 2019 13:25:18 +0000 (UTC) Received: from localhost ([::1]:33494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpYJZ-0000GZ-49 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 22 Jul 2019 09:25:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50024) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpYJF-0007Ub-2L for qemu-devel@nongnu.org; Mon, 22 Jul 2019 09:24:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hpYJD-0003sO-9G for qemu-devel@nongnu.org; Mon, 22 Jul 2019 09:24:57 -0400 Received: from mail-eopbgr710112.outbound.protection.outlook.com ([40.107.71.112]:26272 helo=NAM05-BY2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hpYJC-0003nE-I4 for qemu-devel@nongnu.org; Mon, 22 Jul 2019 09:24:55 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cr5bwF0d11UalUZ0egDm5+pe2QctAcDYnsVr7GGrjO0Eg0lDqyHswE4njuJwzMd//XwuT88rwI51HxW6v9dSpZOmueo5FcoH873Yx6M+n9upmK5k1c9gWaDbho6ouKRSkYkDfRdRCuGwSc4lk+1e8FqMqwrr2NuQn3mICl3qlCZW2fDetzPDLrlybcb/SlBSDKGpaLFaM3f+ynuFfAW4a7c4X8HWJbA4lTRherwr7AYQqTiiZGBPpoltTvK1UQtPs72rJpQLpgrgTBpJ+VrO7qYN0R80U1HweoQgN2UynH0N+sq45FaE1LlLWa38on2btAPOECNgqZk/S/6rHV0uyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=myA7iWQ2TtHlhGDHyUCyhouxeVXMtA/7+hPJnDKpTNI=; b=AhJUGK3TlvqULSVV8nzdg6F42aQjs4dF4Wxe2FwMH8xcqgS3GFqlcmU+oKOmHPg3/l0RF2c8EK7AvDcg5YoBJz2BdVurXLVG3wenI2jwoFRmGeO/OLOpiuLdERo4ROCg/UOBxQZl6H8fo3LohxOtTZYLDDO61U4B/u1EHbJ/Ez0TKVTVqiF18I4GthVaSF0OwTleb8+UaIVp/TPnWzIuNnGTLwmS9kkGYE65STM82+QY9Z7IS9INqOrpOUqvc2jEhrSbGXL2o5Z7R7IXSCZHzXPbUtFtBkRHxBKDDoiTBvJ1kUhSYrQdRWiU2uHxFJ2AdA1/GGRlSgcYQZDiIJFxjA== ARC-Authentication-Results: i=1; mx.microsoft.com 1;spf=pass smtp.mailfrom=bu.edu;dmarc=pass action=none header.from=bu.edu;dkim=pass header.d=bu.edu;arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=myA7iWQ2TtHlhGDHyUCyhouxeVXMtA/7+hPJnDKpTNI=; b=q+DYBhQ31toVpGnulUJAagDp0290kTNM4vl1IDkoqkW6vgeoxrbar9xPiss/DfmGMMCQwdGHi7q3oT1LBZoN83juJk/EG7XZqNeBeEbo4G5Jhl/PvKNMGDCCfAldiR7jDlZ2Hyl1KoE2zLg1mgvrcU/AxfKqjK1A8XvYt168AMQ= Received: from CY4PR03MB2872.namprd03.prod.outlook.com (10.175.118.17) by CY4PR03MB3271.namprd03.prod.outlook.com (10.171.246.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2094.17; Mon, 22 Jul 2019 13:24:47 +0000 Received: from CY4PR03MB2872.namprd03.prod.outlook.com ([fe80::25e1:d1e3:2ad8:e6b5]) by CY4PR03MB2872.namprd03.prod.outlook.com ([fe80::25e1:d1e3:2ad8:e6b5%5]) with mapi id 15.20.2094.013; Mon, 22 Jul 2019 13:24:47 +0000 From: "Oleinik, Alexander" To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH v2 1/2] net: assert that tx packets have nonzero size Thread-Index: AQHVQJDVev5Tqr//HkGF9a/5kASLxg== Date: Mon, 22 Jul 2019 13:24:47 +0000 Message-ID: <20190722132344.30798-2-alxndr@bu.edu> References: <20190722132344.30798-1-alxndr@bu.edu> In-Reply-To: <20190722132344.30798-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.20.1 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR01CA0030.prod.exchangelabs.com (2603:10b6:208:10c::43) To CY4PR03MB2872.namprd03.prod.outlook.com (2603:10b6:903:134::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ca7dfd70-d28b-4bc6-9f24-08d70ea7f784 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:CY4PR03MB3271; x-ms-traffictypediagnostic: CY4PR03MB3271: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 01068D0A20 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(39860400002)(396003)(136003)(366004)(376002)(346002)(189003)(199004)(86362001)(1076003)(75432002)(478600001)(446003)(11346002)(6916009)(486006)(476003)(2616005)(4744005)(52116002)(66066001)(76176011)(26005)(2351001)(186003)(102836004)(6506007)(386003)(3846002)(6116002)(66946007)(88552002)(66476007)(66556008)(64756008)(66446008)(2906002)(5660300002)(99286004)(8936002)(6486002)(4326008)(25786009)(81156014)(81166006)(6512007)(53936002)(7736002)(6436002)(8676002)(50226002)(68736007)(5640700003)(2501003)(36756003)(54906003)(71190400001)(71200400001)(14454004)(256004)(305945005)(786003)(316002)(42522002); DIR:OUT; SFP:1102; SCL:1; SRVR:CY4PR03MB3271; H:CY4PR03MB2872.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: KjGy7fZpk8x7wZQcpRyK2ARps7lAQ3rpkuK0SaqH2+CdIsqassI7jZvEPvvKCpCPfgLVoabWl14oawVkUxVCZKZAJNSkVGHgaU41lqEKBfADPbQbxER/hPP/PPEatluJzaOQf9uEKS0hJGfi1POijq8awXgrkOySPU4hhQFL0reRiS8WdyqBKViyD1VELsJ7agfxU/V4Nh7QZUmdf88eJ2sqDMY/EnjF5hVQpIzO32HgM0NzPRo5D7pUhUum5s81k5CmdmOS90kBa6MkRYLEI3gKLDgVGbiUL7jzdJ8u+G6wExrih/zb9iFGpLovyzUmUWXBZG94Er1QFjyAuzq/Nw2xCZ5Nvo+xAKstas18aku1lou6we065JW542WhfiqsYelBBMH/LpYNuXO4SnhgmcR4ZdCuXtPVKeUPtSpR/6Q= MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: ca7dfd70-d28b-4bc6-9f24-08d70ea7f784 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Jul 2019 13:24:47.3014 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: alxndr@bu.edu X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR03MB3271 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.71.112 Subject: [Qemu-devel] [PATCH v2 1/2] net: assert that tx packets have nonzero size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "pbonzini@redhat.com" , "bsd@redhat.com" , Jason Wang , "stefanha@redhat.com" , "Oleinik, Alexander" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Virtual devices should not try to send zero-sized packets. The caller should check the size prior to calling qemu_sendv_packet_async. Signed-off-by: Alexander Oleinik --- v2: * Improve the comment to explain the rationale for adding the assert. net/net.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/net.c b/net/net.c index 7d4098254f..4ad21df36f 100644 --- a/net/net.c +++ b/net/net.c @@ -741,6 +741,15 @@ ssize_t qemu_sendv_packet_async(NetClientState *sender, size_t size = iov_size(iov, iovcnt); int ret; + /* + * Since this function returns the size of the sent packets, and a return + * value of zero indicates that the packet will be sent asynchronously, + * there is currently no way to report that a 0-sized packet has been sent + * successfully. Forbid it for now, and if someone needs this functionality + * later, the API will require a change. + */ + assert(size); + if (size > NET_BUFSIZE) { return size; } From patchwork Mon Jul 22 13:24:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11052371 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 709881399 for ; Mon, 22 Jul 2019 13:25:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F4FB28445 for ; Mon, 22 Jul 2019 13:25:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5359F2849B; Mon, 22 Jul 2019 13:25:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HK_RANDOM_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5728A28445 for ; Mon, 22 Jul 2019 13:25:17 +0000 (UTC) Received: from localhost ([::1]:33490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpYJY-0000Bu-8I for patchwork-qemu-devel@patchwork.kernel.org; Mon, 22 Jul 2019 09:25:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50013) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hpYJE-0007UV-4U for qemu-devel@nongnu.org; Mon, 22 Jul 2019 09:24:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hpYJC-0003rj-Fn for qemu-devel@nongnu.org; Mon, 22 Jul 2019 09:24:55 -0400 Received: from mail-eopbgr730122.outbound.protection.outlook.com ([40.107.73.122]:19328 helo=NAM05-DM3-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hpYJB-0003p7-9U for qemu-devel@nongnu.org; Mon, 22 Jul 2019 09:24:54 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lvBOUKr4c0RXjnenB0bl8GwrkXtzms4Qzl3ndzCsO+H4yGiC/xz0qBMKXNs/YKzxbCNdLtRDE+lu2cEk4s7oZLgnrTISDTbUiMceE9w/NYY7dIXTTYsxj2QWaGUpXVJaq5NBpSxEZhqH9yBPvRMDq5nq/aYPAFa1oJ+JsGga1tSkiAvoc8A8x5sNaxNJANlLe44KmsYa+P3z9pu45m1NVBvbGTccWSqhj0E+TGMfjpj1q6R3z2mpr0CT2rTH2ROOfAqTQL83NJARV7gJ5POXRoga1Q+L7dvV/U4TtquXy34t0mT8ds23/G+venhW+ZVXnNbrNrz6DQz0YDhDSKkLKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ok+eCycc9CSSwvwyMltlEx3Nn6KUMUUqeqv64dBoap0=; b=SdlcscIN+2AMN/dFX3jpbREZr3iaPOx/S9GOhM8aXIWL2QyUdozEs2oUwI6Cnd7uH2oDiyNQKk+DmAA04+MKd2RiBZ+pEOSfHFyvHKNjGKK+INv5XcL8647niMFThdz8Kpp/rhOEEyki0MSlD6Ne1FsZkJ/8K4isPTUid3AMWjgJS1QmnZqp/ZOTidHuqNm40mHbwfAgROA+6Ju3HqPLc6u8cl1W/lL+Dj5aZBwD9zpY7tL835R3aJi2wxMDH60iYyiYtVfxSPL3Brokqe46DjDGhmpvj7+o6uFQaQ9rLvvh5F4r1WjCs7trQjpOKjp78oVe+m+NP8VBykgT1rqqKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1;spf=pass smtp.mailfrom=bu.edu;dmarc=pass action=none header.from=bu.edu;dkim=pass header.d=bu.edu;arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ok+eCycc9CSSwvwyMltlEx3Nn6KUMUUqeqv64dBoap0=; b=RLlrIE5FLPmZwC1ABCKqLxda/5xEOefMj9yMifwZwP4K+QxYYiMAmGkt9rYObAsJ3LNvNKSr5cbsuHjLTwswDOFteDx/KSDstKjTnID6btNAEh846PKvP3vtGYN56f0YxHanxtcCowy+/emEGTkVVBoV8sUH7atqzn1Gm98SrVo= Received: from CY4PR03MB2872.namprd03.prod.outlook.com (10.175.118.17) by CY4PR03MB2646.namprd03.prod.outlook.com (10.173.43.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2094.16; Mon, 22 Jul 2019 13:24:48 +0000 Received: from CY4PR03MB2872.namprd03.prod.outlook.com ([fe80::25e1:d1e3:2ad8:e6b5]) by CY4PR03MB2872.namprd03.prod.outlook.com ([fe80::25e1:d1e3:2ad8:e6b5%5]) with mapi id 15.20.2094.013; Mon, 22 Jul 2019 13:24:48 +0000 From: "Oleinik, Alexander" To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH v2 2/2] virtio-net: check that tx packet has positive size Thread-Index: AQHVQJDWdJGlkkjH4kGonOrv/UHtcw== Date: Mon, 22 Jul 2019 13:24:48 +0000 Message-ID: <20190722132344.30798-3-alxndr@bu.edu> References: <20190722132344.30798-1-alxndr@bu.edu> In-Reply-To: <20190722132344.30798-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.20.1 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR01CA0030.prod.exchangelabs.com (2603:10b6:208:10c::43) To CY4PR03MB2872.namprd03.prod.outlook.com (2603:10b6:903:134::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d3a5db6b-ae85-4991-6643-08d70ea7f872 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:CY4PR03MB2646; x-ms-traffictypediagnostic: CY4PR03MB2646: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7219; x-forefront-prvs: 01068D0A20 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(376002)(346002)(136003)(366004)(39860400002)(396003)(199004)(189003)(66946007)(66476007)(66446008)(64756008)(66556008)(256004)(14444005)(99286004)(1076003)(316002)(486006)(71190400001)(54906003)(2351001)(50226002)(8936002)(3846002)(6116002)(786003)(88552002)(2906002)(71200400001)(81166006)(81156014)(478600001)(7736002)(6512007)(2501003)(26005)(186003)(11346002)(8676002)(25786009)(476003)(66066001)(2616005)(305945005)(36756003)(5660300002)(53936002)(6436002)(446003)(6916009)(76176011)(4326008)(68736007)(14454004)(52116002)(75432002)(86362001)(102836004)(6486002)(6506007)(5640700003)(386003)(42522002); DIR:OUT; SFP:1102; SCL:1; SRVR:CY4PR03MB2646; H:CY4PR03MB2872.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: DBLK7yJfVUwsU7LLyhseDul90yDadaKt9LVWc12e8v21Q2kTsc15vWXhNoYF04ww/QSGttkabLT0jQ3vB1jCGJumnbCmufjRs60f+a3EYh6a/pg7t22MnYggcip51naKnyHcA0kgA3SBi2r+50IBAdFQ35vRLI8NA/A7zOJ569kJHY0uMQBkoy56QNE5g5HnJ3jT7DHaM5XFZyv32YoRG2moVP8f4xoqX42qM3NyTgYc5F1vw0WBGKSXdDNzUartewWXHaPQL1xLodEmyrdags/1XCKv0D3Jb5Dkcsapr0btXe3lLpogFrLh7ViMx8pzcz1hR7RvsVaNwlCaGIB8M+gl598f+ZIJrEw0ZLPPFQU0pDvtGvQExG6NIrtKKuVZ03HHgRM7oqsV/h33CvBiaujIBDaPqGx0ZmanYuMc63E= MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: d3a5db6b-ae85-4991-6643-08d70ea7f872 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Jul 2019 13:24:48.7928 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: alxndr@bu.edu X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR03MB2646 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.73.122 Subject: [Qemu-devel] [PATCH v2 2/2] virtio-net: check that tx packet has positive size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Michael S. Tsirkin" , Jason Wang , "Oleinik, Alexander" , "bsd@redhat.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP virtio_net_flush_tx does not check that the packet size is nonzero, which causes q->aysnc_tx.elem to be set. Then, when the device is reset, there is an assertion failure since q->aysnc_tx.elem must be flushed/cleared. Zero-sized packets are unsupported - check packet size, prior to sending. Found while fuzzing virtio-net. The relevant stack-trace: #8 in __assert_fail (libc.so.6+0x30101) #9 in virtio_net_reset virtio-net.c:520:13 #10 in virtio_reset virtio.c:1214:9 #11 in virtio_pci_reset virtio-pci.c:1810:5 #12 in qdev_reset_one qdev.c:259:5 #13 in qdev_walk_children qdev.c:575:15 #14 in qbus_walk_children bus.c:52:15 #15 in qdev_walk_children qdev.c:567:15 #16 in qbus_walk_children bus.c:52:15 #17 in qemu_devices_reset reset.c:69:9 #18 in pc_machine_reset pc.c:2628:5 #19 in qemu_system_reset vl.c:1621:9 #20 in LLVMFuzzerTestOneInput fuzz.c:184:4 Signed-off-by: Alexander Oleinik --- hw/net/virtio-net.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index b9e1cd71cf..743f1c827c 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -2074,12 +2074,15 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q) out_sg = sg; } - ret = qemu_sendv_packet_async(qemu_get_subqueue(n->nic, queue_index), - out_sg, out_num, virtio_net_tx_complete); - if (ret == 0) { - virtio_queue_set_notification(q->tx_vq, 0); - q->async_tx.elem = elem; - return -EBUSY; + /* Do not try to send 0-sized packets */ + if (iov_size(out_sg, out_num)) { + ret = qemu_sendv_packet_async(qemu_get_subqueue(n->nic, + queue_index), out_sg, out_num, virtio_net_tx_complete); + if (ret == 0) { + virtio_queue_set_notification(q->tx_vq, 0); + q->async_tx.elem = elem; + return -EBUSY; + } } drop: