All of lore.kernel.org
 help / color / mirror / Atom feed
* [PULL 0/4] NBD patches for 2020-02-26
@ 2020-02-27  1:54 Eric Blake
  2020-02-27  1:54 ` [PULL 1/4] nbd: Fix regression with multiple meta contexts Eric Blake
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Eric Blake @ 2020-02-27  1:54 UTC (permalink / raw)
  To: qemu-devel

The following changes since commit db736e0437aa6fd7c1b7e4599c17f9619ab6b837:

  Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2020-02-25 13:31:16 +0000)

are available in the Git repository at:

  https://repo.or.cz/qemu/ericb.git tags/pull-nbd-2020-02-26

for you to fetch changes up to 8198cf5ef0ef98118b4176970d1cd998d93ec849:

  block/nbd: fix memory leak in nbd_open() (2020-02-26 17:29:00 -0600)

----------------------------------------------------------------
nbd patches for 2020-02-26

- ensure multiple meta contexts work
- allow leading / in export names
- fix a failure path memory leak

----------------------------------------------------------------
Eric Blake (2):
      nbd: Fix regression with multiple meta contexts
      nbd-client: Support leading / in NBD URI

Pan Nengyuan (2):
      block/nbd: extract the common cleanup code
      block/nbd: fix memory leak in nbd_open()

 block/nbd.c  | 33 ++++++++++++++++++++-------------
 nbd/server.c | 12 ++++++++++--
 2 files changed, 30 insertions(+), 15 deletions(-)

-- 
2.24.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PULL 1/4] nbd: Fix regression with multiple meta contexts
  2020-02-27  1:54 [PULL 0/4] NBD patches for 2020-02-26 Eric Blake
@ 2020-02-27  1:54 ` Eric Blake
  2020-02-27  1:54 ` [PULL 2/4] nbd-client: Support leading / in NBD URI Eric Blake
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Blake @ 2020-02-27  1:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier, open list:Network Block Dev...

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 <eblake@redhat.com>
Message-Id: <20200206173832.130004-1-eblake@redhat.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
---
 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(NBDClient *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 = nbd_co_send_bitmap(client, request->handle,
                                          client->exp->export_bitmap,
                                          request->from, request->len,
                                          dont_fragment,
                                          true, NBD_META_ID_DIRTY_BITMAP, errp);
+                if (ret < 0) {
+                    return ret;
+                }
             }

-            return ret;
+            return 0;
         } else {
             return nbd_send_generic_reply(client, request->handle, -EINVAL,
                                           "CMD_BLOCK_STATUS not negotiated",
-- 
2.24.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PULL 2/4] nbd-client: Support leading / in NBD URI
  2020-02-27  1:54 [PULL 0/4] NBD patches for 2020-02-26 Eric Blake
  2020-02-27  1:54 ` [PULL 1/4] nbd: Fix regression with multiple meta contexts Eric Blake
@ 2020-02-27  1:54 ` Eric Blake
  2020-02-27  1:54 ` [PULL 3/4] block/nbd: extract the common cleanup code Eric Blake
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Blake @ 2020-02-27  1:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Ján Tomko, open list:Network Block Dev..., Max Reitz

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 <eblake@redhat.com>
Message-Id: <20200212023101.1162686-1-eblake@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 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 = uri->path ? uri->path : "/";
-    p += strspn(p, "/");
+    p = uri->path ? uri->path : "";
+    if (p[0] == '/') {
+        p++;
+    }
     if (p[0]) {
         qdict_put_str(options, "export", p);
     }
-- 
2.24.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PULL 3/4] block/nbd: extract the common cleanup code
  2020-02-27  1:54 [PULL 0/4] NBD patches for 2020-02-26 Eric Blake
  2020-02-27  1:54 ` [PULL 1/4] nbd: Fix regression with multiple meta contexts Eric Blake
  2020-02-27  1:54 ` [PULL 2/4] nbd-client: Support leading / in NBD URI Eric Blake
@ 2020-02-27  1:54 ` Eric Blake
  2020-02-27  1:54 ` [PULL 4/4] block/nbd: fix memory leak in nbd_open() Eric Blake
  2020-02-27 19:14 ` [PULL 0/4] NBD patches for 2020-02-26 Peter Maydell
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Blake @ 2020-02-27  1:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Vladimir Sementsov-Ogievskiy,
	open list:Network Block Dev...,
	Pan Nengyuan, Max Reitz, Stefano Garzarella

From: Pan Nengyuan <pannengyuan@huawei.com>

The BDRVNBDState cleanup code is common in two places, add
nbd_clear_bdrvstate() function to do these cleanups.

Suggested-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <1575517528-44312-2-git-send-email-pannengyuan@huawei.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[eblake: fix compilation error and commit message]
Signed-off-by: Eric Blake <eblake@redhat.com>
---
 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 = NULL;
+    g_free(s->export);
+    s->export = NULL;
+    g_free(s->tlscredsid);
+    s->tlscredsid = NULL;
+    g_free(s->x_dirty_bitmap);
+    s->x_dirty_bitmap = NULL;
+}
+
 static void nbd_channel_error(BDRVNBDState *s, int ret)
 {
     if (ret == -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 = 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)
-- 
2.24.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PULL 4/4] block/nbd: fix memory leak in nbd_open()
  2020-02-27  1:54 [PULL 0/4] NBD patches for 2020-02-26 Eric Blake
                   ` (2 preceding siblings ...)
  2020-02-27  1:54 ` [PULL 3/4] block/nbd: extract the common cleanup code Eric Blake
@ 2020-02-27  1:54 ` Eric Blake
  2020-02-27 19:14 ` [PULL 0/4] NBD patches for 2020-02-26 Peter Maydell
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Blake @ 2020-02-27  1:54 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Vladimir Sementsov-Ogievskiy,
	open list:Network Block Dev...,
	Pan Nengyuan, qemu-stable, Max Reitz, Euler Robot,
	Stefano Garzarella

From: Pan Nengyuan <pannengyuan@huawei.com>

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-rc0/qapi/qobject-input-visitor.c:295
    #3 0x56281dab1a04 in visit_start_struct  /mnt/sdb/qemu-4.2.0-rc0/qapi/qapi-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:1716
    #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-visit-core.c:297
    #5 0x56281dad0fa1 in visit_type_UnixSocketAddress_members qapi/qapi-visit-sockets.c:141
    #6 0x56281dad17b6 in visit_type_SocketAddress_members qapi/qapi-visit-sockets.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 <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Cc: qemu-stable <qemu-stable@nongnu.org>
Cc: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <1575517528-44312-3-git-send-email-pannengyuan@huawei.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
---
 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 *options, int flags,

     ret = nbd_client_connect(bs, errp);
     if (ret < 0) {
+        nbd_clear_bdrvstate(s);
         return ret;
     }
     /* successfully connected */
-- 
2.24.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PULL 0/4] NBD patches for 2020-02-26
  2020-02-27  1:54 [PULL 0/4] NBD patches for 2020-02-26 Eric Blake
                   ` (3 preceding siblings ...)
  2020-02-27  1:54 ` [PULL 4/4] block/nbd: fix memory leak in nbd_open() Eric Blake
@ 2020-02-27 19:14 ` Peter Maydell
  4 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2020-02-27 19:14 UTC (permalink / raw)
  To: Eric Blake; +Cc: QEMU Developers

On Thu, 27 Feb 2020 at 01:56, Eric Blake <eblake@redhat.com> wrote:
>
> The following changes since commit db736e0437aa6fd7c1b7e4599c17f9619ab6b837:
>
>   Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2020-02-25 13:31:16 +0000)
>
> are available in the Git repository at:
>
>   https://repo.or.cz/qemu/ericb.git tags/pull-nbd-2020-02-26
>
> for you to fetch changes up to 8198cf5ef0ef98118b4176970d1cd998d93ec849:
>
>   block/nbd: fix memory leak in nbd_open() (2020-02-26 17:29:00 -0600)
>
> ----------------------------------------------------------------
> nbd patches for 2020-02-26
>
> - ensure multiple meta contexts work
> - allow leading / in export names
> - fix a failure path memory leak
>
> ----------------------------------------------------------------
> Eric Blake (2):
>       nbd: Fix regression with multiple meta contexts
>       nbd-client: Support leading / in NBD URI
>
> Pan Nengyuan (2):
>       block/nbd: extract the common cleanup code
>       block/nbd: fix memory leak in nbd_open()
>
>  block/nbd.c  | 33 ++++++++++++++++++++-------------
>  nbd/server.c | 12 ++++++++++--
>  2 files changed, 30 insertions(+), 15 deletions(-)


Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/5.0
for any user-visible changes.

-- PMM


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-02-27 19:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-27  1:54 [PULL 0/4] NBD patches for 2020-02-26 Eric Blake
2020-02-27  1:54 ` [PULL 1/4] nbd: Fix regression with multiple meta contexts Eric Blake
2020-02-27  1:54 ` [PULL 2/4] nbd-client: Support leading / in NBD URI Eric Blake
2020-02-27  1:54 ` [PULL 3/4] block/nbd: extract the common cleanup code Eric Blake
2020-02-27  1:54 ` [PULL 4/4] block/nbd: fix memory leak in nbd_open() Eric Blake
2020-02-27 19:14 ` [PULL 0/4] NBD patches for 2020-02-26 Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.