From: Kevin Wolf Date: Thu, 9 Feb 2017 14:43:38 +0000 (+0100) Subject: nbd/server: Use real permissions for NBD exports X-Git-Tag: v2.9.0-rc0~48^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8a7ce4f9338c475df1afc12502af704e4300a3e0;p=thirdparty%2Fqemu.git nbd/server: Use real permissions for NBD exports NBD can't cope with device size changes, so resize must be forbidden, but otherwise we can tolerate anything. Depending on whether the export is writable or not, we only require consistent reads and writes. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Acked-by: Fam Zheng --- diff --git a/nbd/server.c b/nbd/server.c index 89362ba7600..924a1fe2dbf 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -891,10 +891,17 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, off_t size, { BlockBackend *blk; NBDExport *exp = g_malloc0(sizeof(NBDExport)); + uint64_t perm; int ret; - /* FIXME Use real permissions */ - blk = blk_new(0, BLK_PERM_ALL); + /* Don't allow resize while the NBD server is running, otherwise we don't + * care what happens with the node. */ + perm = BLK_PERM_CONSISTENT_READ; + if ((nbdflags & NBD_FLAG_READ_ONLY) == 0) { + perm |= BLK_PERM_WRITE; + } + blk = blk_new(perm, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED | + BLK_PERM_WRITE | BLK_PERM_GRAPH_MOD); ret = blk_insert_bs(blk, bs, errp); if (ret < 0) { goto fail;