[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 78/78] block: Call attention to truncation of long NBD exports
From: |
Michael Roth |
Subject: |
[PATCH 78/78] block: Call attention to truncation of long NBD exports |
Date: |
Tue, 16 Jun 2020 09:15:47 -0500 |
From: Eric Blake <eblake@redhat.com>
Commit 93676c88 relaxed our NBD client code to request export names up
to the NBD protocol maximum of 4096 bytes without NUL terminator, even
though the block layer can't store anything longer than 4096 bytes
including NUL terminator for display to the user. Since this means
there are some export names where we have to truncate things, we can
at least try to make the truncation a bit more obvious for the user.
Note that in spite of the truncated display name, we can still
communicate with an NBD server using such a long export name; this was
deemed nicer than refusing to even connect to such a server (since the
server may not be under our control, and since determining our actual
length limits gets tricky when nbd://host:port/export and
nbd+unix:///export?socket=/path are themselves variable-length
expansions beyond the export name but count towards the block layer
name length).
Reported-by: Xueqiang Wei <xuwei@redhat.com>
Fixes: https://bugzilla.redhat.com/1843684
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200610163741.3745251-3-eblake@redhat.com>
(cherry picked from commit 5c86bdf1208916ece0b87e1151c9b48ee54faa3e)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
block.c | 7 +++++--
block/nbd.c | 21 +++++++++++++--------
2 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/block.c b/block.c
index 2e5e8b639a..19c25da305 100644
--- a/block.c
+++ b/block.c
@@ -6486,8 +6486,11 @@ void bdrv_refresh_filename(BlockDriverState *bs)
pstrcpy(bs->filename, sizeof(bs->filename), bs->exact_filename);
} else {
QString *json = qobject_to_json(QOBJECT(bs->full_open_options));
- snprintf(bs->filename, sizeof(bs->filename), "json:%s",
- qstring_get_str(json));
+ if (snprintf(bs->filename, sizeof(bs->filename), "json:%s",
+ qstring_get_str(json)) >= sizeof(bs->filename)) {
+ /* Give user a hint if we truncated things. */
+ strcpy(bs->filename + sizeof(bs->filename) - 4, "...");
+ }
qobject_unref(json);
}
}
diff --git a/block/nbd.c b/block/nbd.c
index 3d369fc8eb..eb380102c0 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -1971,6 +1971,7 @@ static void nbd_refresh_filename(BlockDriverState *bs)
{
BDRVNBDState *s = bs->opaque;
const char *host = NULL, *port = NULL, *path = NULL;
+ size_t len = 0;
if (s->saddr->type == SOCKET_ADDRESS_TYPE_INET) {
const InetSocketAddress *inet = &s->saddr->u.inet;
@@ -1983,17 +1984,21 @@ static void nbd_refresh_filename(BlockDriverState *bs)
} /* else can't represent as pseudo-filename */
if (path && s->export) {
- snprintf(bs->exact_filename, sizeof(bs->exact_filename),
- "nbd+unix:///%s?socket=%s", s->export, path);
+ len = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
+ "nbd+unix:///%s?socket=%s", s->export, path);
} else if (path && !s->export) {
- snprintf(bs->exact_filename, sizeof(bs->exact_filename),
- "nbd+unix://?socket=%s", path);
+ len = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
+ "nbd+unix://?socket=%s", path);
} else if (host && s->export) {
- snprintf(bs->exact_filename, sizeof(bs->exact_filename),
- "nbd://%s:%s/%s", host, port, s->export);
+ len = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
+ "nbd://%s:%s/%s", host, port, s->export);
} else if (host && !s->export) {
- snprintf(bs->exact_filename, sizeof(bs->exact_filename),
- "nbd://%s:%s", host, port);
+ len = snprintf(bs->exact_filename, sizeof(bs->exact_filename),
+ "nbd://%s:%s", host, port);
+ }
+ if (len > sizeof(bs->exact_filename)) {
+ /* Name is too long to represent exactly, so leave it empty. */
+ bs->exact_filename[0] = '\0';
}
}
--
2.17.1
- Re: [PATCH 72/78] 9p: Lock directory streams with a CoMutex, (continued)
[PATCH 73/78] net: Do not include a newline in the id of -nic devices, Michael Roth, 2020/06/16
[PATCH 75/78] virtio-balloon: fix free page hinting without an iothread, Michael Roth, 2020/06/16
[PATCH 76/78] virtio-balloon: fix free page hinting check on unrealize, Michael Roth, 2020/06/16
[PATCH 74/78] nbd/server: Avoid long error message assertions CVE-2020-10761, Michael Roth, 2020/06/16
[PATCH 77/78] virtio-balloon: unref the iothread when unrealizing, Michael Roth, 2020/06/16
[PATCH 78/78] block: Call attention to truncation of long NBD exports,
Michael Roth <=
[PATCH 07/78] virtio-blk: fix out-of-bounds access to bitmap in notify_guest_bh, Michael Roth, 2020/06/16
[PATCH 08/78] numa: remove not needed check, Michael Roth, 2020/06/16
Re: [PATCH 00/78] Patch Round-up for stable 4.2.1, freeze on 2020-06-22, Cole Robinson, 2020/06/17
Re: [PATCH 00/78] Patch Round-up for stable 4.2.1, freeze on 2020-06-22, Liam Merwick, 2020/06/17
Re: [PATCH 00/78] Patch Round-up for stable 4.2.1, freeze on 2020-06-22, Karl Heubaum, 2020/06/17
Re: [PATCH 00/78] Patch Round-up for stable 4.2.1, freeze on 2020-06-22, Finn Thain, 2020/06/19
Re: [PATCH 00/78] Patch Round-up for stable 4.2.1, freeze on 2020-06-22, Bruce Rogers, 2020/06/20
Re: [PATCH 00/78] Patch Round-up for stable 4.2.1, freeze on 2020-06-22, Michael Roth, 2020/06/22