diff options
author | Eric Blake | 2019-11-14 03:46:34 +0100 |
---|---|---|
committer | Eric Blake | 2019-11-18 23:01:34 +0100 |
commit | 93676c88d7a5cd5971de94f9091eff8e9773b1af (patch) | |
tree | c6711a35024de53f6af0bacebc3063d40b41d291 /include/block | |
parent | bitmap: Enforce maximum bitmap name length (diff) | |
download | qemu-93676c88d7a5cd5971de94f9091eff8e9773b1af.tar.gz qemu-93676c88d7a5cd5971de94f9091eff8e9773b1af.tar.xz qemu-93676c88d7a5cd5971de94f9091eff8e9773b1af.zip |
nbd: Don't send oversize strings
Qemu as server currently won't accept export names larger than 256
bytes, nor create dirty bitmap names longer than 1023 bytes, so most
uses of qemu as client or server have no reason to get anywhere near
the NBD spec maximum of a 4k limit per string.
However, we weren't actually enforcing things, ignoring when the
remote side violates the protocol on input, and also having several
code paths where we send oversize strings on output (for example,
qemu-nbd --description could easily send more than 4k). Tighten
things up as follows:
client:
- Perform bounds check on export name and dirty bitmap request prior
to handing it to server
- Validate that copied server replies are not too long (ignoring
NBD_INFO_* replies that are not copied is not too bad)
server:
- Perform bounds check on export name and description prior to
advertising it to client
- Reject client name or metadata query that is too long
- Adjust things to allow full 4k name limit rather than previous
256 byte limit
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20191114024635.11363-4-eblake@redhat.com>
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Diffstat (limited to 'include/block')
-rw-r--r-- | include/block/nbd.h | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/include/block/nbd.h b/include/block/nbd.h index c306423dc8..7f46932d80 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -227,11 +227,11 @@ enum { #define NBD_MAX_BUFFER_SIZE (32 * 1024 * 1024) /* - * Maximum size of an export name. The NBD spec requires a minimum of - * 256 and recommends that servers support up to 4096; all users use - * malloc so we can bump this constant without worry. + * Maximum size of a protocol string (export name, meta context name, + * etc.). Use malloc rather than stack allocation for storage of a + * string. */ -#define NBD_MAX_NAME_SIZE 256 +#define NBD_MAX_STRING_SIZE 4096 /* Two types of reply structures */ #define NBD_SIMPLE_REPLY_MAGIC 0x67446698 |