From nobody Sun Oct 5 19:23:33 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582768603; cv=none; d=zohomail.com; s=zohoarc; b=EYQWk4icBkt3vAbyiI+BjePPlGUrJu+Rc1vpjgtCw7uoM6AD3aEJc3fmdYEmqJKU2f6KM3b4uysGNtnj+9ML4StL+vOrK98rj+bqC0/PeXkr2oGE3Sapfj9Mi7vvK4GAuQVb86tubRdY0236iHEOQAh2Y2CHkKRuId6CzEYoF1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582768603; 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=LUPXxxCKyagr4YZxReptWxzyXWpDfn+h00F9pRtBtOc=; b=hSGSz6eAaloDSDsP2JxnEXubzwcrliAbCWdsz9oxuWV0HAu3jH0vIa0Ynb/OdJaUHbyeCFajZFc1XC4nIazzgxjfDDJPLmlDqp2FaRGzjULe9CQRWDbkxP/eTlQalKSrByw7NAaXNOqFJ69RLrOD/O0JCCry394FyHaWZgt27u4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158276860385831.932267541061037; Wed, 26 Feb 2020 17:56:43 -0800 (PST) Received: from localhost ([::1]:52686 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j78Pp-0006co-Gf for importer@patchew.org; Wed, 26 Feb 2020 20:56:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36366) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j78OB-0004cA-7O for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:55:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j78O9-0002bX-S5 for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:54:59 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:42094) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j78O9-0002aH-Ow for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:54:57 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-10-Vr7GnvyIOK6_Ip3C3n4SmQ-1; Wed, 26 Feb 2020 20:54:53 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 508CA1005512; Thu, 27 Feb 2020 01:54:51 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-57.phx2.redhat.com [10.3.116.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8E515C21B; Thu, 27 Feb 2020 01:54:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582768497; 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=LUPXxxCKyagr4YZxReptWxzyXWpDfn+h00F9pRtBtOc=; b=RxAmLlTNhf5FyuOFS6cLhEE3471xJtdJ3NkWUh9LzL6dsr3tvwJSkh+OU4R4i4EtRkXsel d4j28jtBcx9TSZclpFXV8DG8QKBltQ9Qmso3uSsCH2himqJYcss6ny+V4bliyJ4jjNvX8x XGyGB0eQJcfiTGWNhm7uGoZEmtGy+lI= X-MC-Unique: Vr7GnvyIOK6_Ip3C3n4SmQ-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PULL 1/4] nbd: Fix regression with multiple meta contexts Date: Wed, 26 Feb 2020 19:54:45 -0600 Message-Id: <20200227015448.960538-2-eblake@redhat.com> In-Reply-To: <20200227015448.960538-1-eblake@redhat.com> References: <20200227015448.960538-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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: Laurent Vivier , "open list:Network Block Dev..." Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Detected by a hang in the libnbd testsuite. If a client requests multiple meta contexts (both base:allocation and qemu:dirty-bitmap:x) at the same time, our attempt to silence a false-positive warning about a potential uninitialized variable introduced botched logic: we were short-circuiting the second context, and never sending the NBD_REPLY_FLAG_DONE. Combining two 'if' into one 'if/else' in bdf200a55 was wrong (I'm a bit embarrassed that such a change was my initial suggestion after the v1 patch, then I did not review the v2 patch that actually got committed). Revert that, and instead silence the false positive warning by replacing 'return ret' with 'return 0' (the value it always has at that point in the code, even though it eluded the deduction abilities of the robot that reported the false positive). Fixes: bdf200a5535 Signed-off-by: Eric Blake Message-Id: <20200206173832.130004-1-eblake@redhat.com> Reviewed-by: Laurent Vivier --- nbd/server.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 87fcd2e7bfac..11a31094ff83 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2384,15 +2384,23 @@ static coroutine_fn int nbd_handle_request(NBDClien= t *client, !client->export_meta.bitmap, NBD_META_ID_BASE_ALLOCATION, errp); - } else { /* client->export_meta.bitmap */ + if (ret < 0) { + return ret; + } + } + + if (client->export_meta.bitmap) { ret =3D nbd_co_send_bitmap(client, request->handle, client->exp->export_bitmap, request->from, request->len, dont_fragment, true, NBD_META_ID_DIRTY_BITMAP, e= rrp); + if (ret < 0) { + return ret; + } } - return ret; + return 0; } else { return nbd_send_generic_reply(client, request->handle, -EINVAL, "CMD_BLOCK_STATUS not negotiated= ", --=20 2.24.1 From nobody Sun Oct 5 19:23:33 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582768595; cv=none; d=zohomail.com; s=zohoarc; b=KWH2QKQVhk6/OlUS3eRrsHER7afxywgiIAJSNd2sLmoALqrCIREbx6/YjL2DRiarPd7NOamJa8bYyAo9WrRIkHyL0cqh8SytBLAjNOgYIpNewv4PkXlMsOTe0lLBd/DmdCrYhhHWtUic7CUdQfvDIsKjYIFu4gmhTj7gwxpMqu8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582768595; 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=CoJGR4ZI+9m4O0mPGBL05+mvr80zAshpXsWSv07d0Ow=; b=BL1ySAh/WaDLBQLUNIN+f905PNB8v4SgwQ2gezJCc+TwdB8GFokdkQQTDrO8Lq3MvFNEIk0TV81tgf/oecu0tTyPPLWSp3uxYkESy3GjndWuctzeUkRVtUWXwceejeZnx5N9Bu7C5jyNSP1I9eNLan9RXev1HWDB4GS/cbXKZWQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158276859516299.35294427335009; Wed, 26 Feb 2020 17:56:35 -0800 (PST) Received: from localhost ([::1]:52680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j78Ph-0006Nq-2P for importer@patchew.org; Wed, 26 Feb 2020 20:56:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36342) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j78OA-0004c4-NJ for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:55:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j78O9-0002ZP-7S for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:54:58 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:58060 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j78O9-0002X8-40 for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:54:57 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-168-XIXfOmM1PjKlFp3HwhhTqA-1; Wed, 26 Feb 2020 20:54:52 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F09C5800D53; Thu, 27 Feb 2020 01:54:51 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-57.phx2.redhat.com [10.3.116.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7CB6C5C28E; Thu, 27 Feb 2020 01:54:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582768496; 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=CoJGR4ZI+9m4O0mPGBL05+mvr80zAshpXsWSv07d0Ow=; b=cUdGxyyPZkpI3dK1fwLqI4DoQ3IJsIJ5M7oa2nQ2S4Ubotwsvg2mDsoecvsZu4TII3/ZvD 39ZHgAryMFZTgq5hhAp12bna2qwJQn8+skWA5SKk8CQJX7QMdwRt0+PnLwIGZwBTuAymWj 5Qk+eg+K23v2pFHu8KQVOKa2oQE0f38= X-MC-Unique: XIXfOmM1PjKlFp3HwhhTqA-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PULL 2/4] nbd-client: Support leading / in NBD URI Date: Wed, 26 Feb 2020 19:54:46 -0600 Message-Id: <20200227015448.960538-3-eblake@redhat.com> In-Reply-To: <20200227015448.960538-1-eblake@redhat.com> References: <20200227015448.960538-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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: Kevin Wolf , =?UTF-8?q?J=C3=A1n=20Tomko?= , "open list:Network Block Dev..." , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The NBD URI specification [1] states that only one leading slash at the beginning of the URI path component is stripped, not all such slashes. This becomes important to a patch I just proposed to nbdkit [2], which would allow the exportname to select a file embedded within an ext2 image: ext2fs demands an absolute pathname beginning with '/', and because qemu was inadvertantly stripping it, my nbdkit patch had to work around the behavior. [1] https://github.com/NetworkBlockDevice/nbd/blob/master/doc/uri.md [2] https://www.redhat.com/archives/libguestfs/2020-February/msg00109.html Note that the qemu bug only affects handling of URIs such as nbd://host:port//abs/path (where '/abs/path' should be the export name); it is still possible to use --image-opts and pass the desired export name with a leading slash directly through JSON even without this patch. Signed-off-by: Eric Blake Message-Id: <20200212023101.1162686-1-eblake@redhat.com> Reviewed-by: J=C3=A1n Tomko --- block/nbd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index 6d3b22f844ea..f69e61e68ad6 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -1528,8 +1528,10 @@ static int nbd_parse_uri(const char *filename, QDict= *options) goto out; } - p =3D uri->path ? uri->path : "/"; - p +=3D strspn(p, "/"); + p =3D uri->path ? uri->path : ""; + if (p[0] =3D=3D '/') { + p++; + } if (p[0]) { qdict_put_str(options, "export", p); } --=20 2.24.1 From nobody Sun Oct 5 19:23:33 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582768672; cv=none; d=zohomail.com; s=zohoarc; b=LWUpSlNGcFHsolNIRqtbvRsAKtiSYBTb1qlMg/xA9VjkgTyGM2ZjD+el/vx7asfGYlKAQnQ1uqQe0wws46ndcdg/76yZjmcWPPIbA+RByo6nquH2lM1IoSjCmpMxHlS2UWtIM7muzLeMmesAbzUDCwWeVCDjm5fzrji0diYEg4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582768672; 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=rsUu0Tkg4IjYGzEi8JY5J1KyolilE13RDr+tqC7JBSE=; b=DIperlobnsazc0kQbrfP3uSF8bjHlbbaPAbPlK459+dDZrFttSmRfsZVYvROpfHpw1o9pJiJVm/VJyeP7Sr9awNe0ZtqPYXLbbIzJDKCcr2K9WJxfBapr+szrmeSzifeOHV4oAqJ/SCjpFIEQfGy9ucRrVUvK8kRy6V8KUUsDfQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582768672927939.0675702882388; Wed, 26 Feb 2020 17:57:52 -0800 (PST) Received: from localhost ([::1]:52702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j78Qx-0000LW-RK for importer@patchew.org; Wed, 26 Feb 2020 20:57:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36343) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j78OA-0004c5-NT for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:54:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j78O9-0002ZF-6v for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:54:58 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:53569 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j78O9-0002Ww-2y for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:54:57 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-88-MFB1uurqO6GzKwFcH6BciA-1; Wed, 26 Feb 2020 20:54:54 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E9A7413E5; Thu, 27 Feb 2020 01:54:52 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-57.phx2.redhat.com [10.3.116.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2161A5C578; Thu, 27 Feb 2020 01:54:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582768496; 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=rsUu0Tkg4IjYGzEi8JY5J1KyolilE13RDr+tqC7JBSE=; b=Jlks9anUsxJ1oIQIqlRtHdRuInKFEV5b1j6SnDgDro6fpmsN5kWugRPAMV2CmhypHElHLY +GFfmXby1Tcbca1Ep3WpALJBf1R/MZMKicG97LqAQniE7m/JGG/1d5Iq55a0qJJUZwUUwW ZfkkvMIxrK6IqJ56Y973VvnxKyJLHQA= X-MC-Unique: MFB1uurqO6GzKwFcH6BciA-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PULL 3/4] block/nbd: extract the common cleanup code Date: Wed, 26 Feb 2020 19:54:47 -0600 Message-Id: <20200227015448.960538-4-eblake@redhat.com> In-Reply-To: <20200227015448.960538-1-eblake@redhat.com> References: <20200227015448.960538-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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: Kevin Wolf , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Pan Nengyuan , Max Reitz , Stefano Garzarella Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Pan Nengyuan The BDRVNBDState cleanup code is common in two places, add nbd_clear_bdrvstate() function to do these cleanups. Suggested-by: Stefano Garzarella Signed-off-by: Pan Nengyuan Reviewed-by: Vladimir Sementsov-Ogievskiy Message-Id: <1575517528-44312-2-git-send-email-pannengyuan@huawei.com> Reviewed-by: Eric Blake [eblake: fix compilation error and commit message] Signed-off-by: Eric Blake --- block/nbd.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index f69e61e68ad6..ed0f93ab27a9 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -95,6 +95,19 @@ typedef struct BDRVNBDState { static int nbd_client_connect(BlockDriverState *bs, Error **errp); +static void nbd_clear_bdrvstate(BDRVNBDState *s) +{ + object_unref(OBJECT(s->tlscreds)); + qapi_free_SocketAddress(s->saddr); + s->saddr =3D NULL; + g_free(s->export); + s->export =3D NULL; + g_free(s->tlscredsid); + s->tlscredsid =3D NULL; + g_free(s->x_dirty_bitmap); + s->x_dirty_bitmap =3D NULL; +} + static void nbd_channel_error(BDRVNBDState *s, int ret) { if (ret =3D=3D -EIO) { @@ -1879,11 +1892,7 @@ static int nbd_process_options(BlockDriverState *bs,= QDict *options, error: if (ret < 0) { - object_unref(OBJECT(s->tlscreds)); - qapi_free_SocketAddress(s->saddr); - g_free(s->export); - g_free(s->tlscredsid); - g_free(s->x_dirty_bitmap); + nbd_clear_bdrvstate(s); } qemu_opts_del(opts); return ret; @@ -1962,12 +1971,7 @@ static void nbd_close(BlockDriverState *bs) BDRVNBDState *s =3D bs->opaque; nbd_client_close(bs); - - object_unref(OBJECT(s->tlscreds)); - qapi_free_SocketAddress(s->saddr); - g_free(s->export); - g_free(s->tlscredsid); - g_free(s->x_dirty_bitmap); + nbd_clear_bdrvstate(s); } static int64_t nbd_getlength(BlockDriverState *bs) --=20 2.24.1 From nobody Sun Oct 5 19:23:33 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582768605; cv=none; d=zohomail.com; s=zohoarc; b=bUCHKju8GTaq6fOnqZercDq3LVyFUdufiwAYiAqY+LS+waUmB+3f7H2voTFzI/iarWhVg8soDCkP3A8BkeUCeXq6lX2PqgYyu/auxHO92QKjHbI2TrmZVdfm8cGXPYcP9HQyCB8tXbKDt4ZSPFsl98Uu2RW9waAj6hb83+BFOF0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582768605; 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=S8IZ81wz+GqrsTJ4jOYNuawo0WpVuRcrvYE66jTI0Fg=; b=llTGxH2MitSrMs3DeLZCs6UcU3qyQ38GliFlRJdIP1d604bSEK378mtCP817Wwd1Mc/53pbvPe1zR3S4davSKxhrGlx185qI8lZ/2b/liavNTHxBYgcY9IVVju9giPJZXvZbREmTBmVm9Fw/krgvSenzrGwOQGMwMTKUKRZHK5g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582768605574282.9953739936334; Wed, 26 Feb 2020 17:56:45 -0800 (PST) Received: from localhost ([::1]:52684 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j78Ps-0006ck-2x for importer@patchew.org; Wed, 26 Feb 2020 20:56:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36346) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j78OA-0004c6-NO for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:55:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j78O9-0002aB-EQ for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:54:58 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:40790 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j78O9-0002Xv-9v for qemu-devel@nongnu.org; Wed, 26 Feb 2020 20:54:57 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-208-QGwgA4GtMuC_GFy0pLHs3w-1; Wed, 26 Feb 2020 20:54:55 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CDFFA107ACCA; Thu, 27 Feb 2020 01:54:53 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-57.phx2.redhat.com [10.3.116.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 216375C578; Thu, 27 Feb 2020 01:54:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582768496; 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=S8IZ81wz+GqrsTJ4jOYNuawo0WpVuRcrvYE66jTI0Fg=; b=h/FjqajGDBeyYSC1H2855WDn9IQoVa//N6zF6o2PlUa8YD6WBofzsEnhfbXt9OLfx413vm zZtiJNKzy48DyyE1DXg23hUGVpGqnznvQSI/qpUo9F05RbPDgIV/1J5JITI6yPVRmEUtoR /q2mNMGb3wsptGaESzwkfGfv0jQauBU= X-MC-Unique: QGwgA4GtMuC_GFy0pLHs3w-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PULL 4/4] block/nbd: fix memory leak in nbd_open() Date: Wed, 26 Feb 2020 19:54:48 -0600 Message-Id: <20200227015448.960538-5-eblake@redhat.com> In-Reply-To: <20200227015448.960538-1-eblake@redhat.com> References: <20200227015448.960538-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 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: Kevin Wolf , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Pan Nengyuan , qemu-stable , Max Reitz , Euler Robot , Stefano Garzarella Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Pan Nengyuan In currently implementation there will be a memory leak when nbd_client_connect() returns error status. Here is an easy way to reproduce: 1. run qemu-iotests as follow and check the result with asan: ./check -raw 143 Following is the asan output backtrack: Direct leak of 40 byte(s) in 1 object(s) allocated from: #0 0x7f629688a560 in calloc (/usr/lib64/libasan.so.3+0xc7560) #1 0x7f6295e7e015 in g_malloc0 (/usr/lib64/libglib-2.0.so.0+0x50015) #2 0x56281dab4642 in qobject_input_start_struct /mnt/sdb/qemu-4.2.0-rc= 0/qapi/qobject-input-visitor.c:295 #3 0x56281dab1a04 in visit_start_struct /mnt/sdb/qemu-4.2.0-rc0/qapi/q= api-visit-core.c:49 #4 0x56281dad1827 in visit_type_SocketAddress qapi/qapi-visit-sockets.= c:386 #5 0x56281da8062f in nbd_config /mnt/sdb/qemu-4.2.0-rc0/block/nbd.c:1= 716 #6 0x56281da8062f in nbd_process_options /mnt/sdb/qemu-4.2.0-rc0/block/= nbd.c:1829 #7 0x56281da8062f in nbd_open /mnt/sdb/qemu-4.2.0-rc0/block/nbd.c:1873 Direct leak of 15 byte(s) in 1 object(s) allocated from: #0 0x7f629688a3a0 in malloc (/usr/lib64/libasan.so.3+0xc73a0) #1 0x7f6295e7dfbd in g_malloc (/usr/lib64/libglib-2.0.so.0+0x4ffbd) #2 0x7f6295e96ace in g_strdup (/usr/lib64/libglib-2.0.so.0+0x68ace) #3 0x56281da804ac in nbd_process_options /mnt/sdb/qemu-4.2.0-rc0/block/= nbd.c:1834 #4 0x56281da804ac in nbd_open /mnt/sdb/qemu-4.2.0-rc0/block/nbd.c:1873 Indirect leak of 24 byte(s) in 1 object(s) allocated from: #0 0x7f629688a3a0 in malloc (/usr/lib64/libasan.so.3+0xc73a0) #1 0x7f6295e7dfbd in g_malloc (/usr/lib64/libglib-2.0.so.0+0x4ffbd) #2 0x7f6295e96ace in g_strdup (/usr/lib64/libglib-2.0.so.0+0x68ace) #3 0x56281dab41a3 in qobject_input_type_str_keyval /mnt/sdb/qemu-4.2.0-= rc0/qapi/qobject-input-visitor.c:536 #4 0x56281dab2ee9 in visit_type_str /mnt/sdb/qemu-4.2.0-rc0/qapi/qapi-v= isit-core.c:297 #5 0x56281dad0fa1 in visit_type_UnixSocketAddress_members qapi/qapi-vis= it-sockets.c:141 #6 0x56281dad17b6 in visit_type_SocketAddress_members qapi/qapi-visit-s= ockets.c:366 #7 0x56281dad186a in visit_type_SocketAddress qapi/qapi-visit-sockets.c= :393 #8 0x56281da8062f in nbd_config /mnt/sdb/qemu-4.2.0-rc0/block/nbd.c:1716 #9 0x56281da8062f in nbd_process_options /mnt/sdb/qemu-4.2.0-rc0/block/= nbd.c:1829 #10 0x56281da8062f in nbd_open /mnt/sdb/qemu-4.2.0-rc0/block/nbd.c:1873 Fixes: 8f071c9db506e03ab Reported-by: Euler Robot Signed-off-by: Pan Nengyuan Reviewed-by: Vladimir Sementsov-Ogievskiy Cc: qemu-stable Cc: Vladimir Sementsov-Ogievskiy Message-Id: <1575517528-44312-3-git-send-email-pannengyuan@huawei.com> Reviewed-by: Stefano Garzarella Signed-off-by: Eric Blake --- block/nbd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/nbd.c b/block/nbd.c index ed0f93ab27a9..976be7664786 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -1915,6 +1915,7 @@ static int nbd_open(BlockDriverState *bs, QDict *opti= ons, int flags, ret =3D nbd_client_connect(bs, errp); if (ret < 0) { + nbd_clear_bdrvstate(s); return ret; } /* successfully connected */ --=20 2.24.1