qemu/nbd
Eric Blake fed5f8f820 nbd/server: Fix error reporting for bad requests
The NBD spec says an attempt to NBD_CMD_TRIM on a read-only
export should fail with EPERM, as a trim has the potential
to change disk contents, but we were relying on the block
layer to catch that for us, which might not always give the
right error (and even if it does, it does not let us pass
back a sane message for structured replies).

The NBD spec says an attempt to NBD_CMD_WRITE_ZEROES out of
bounds should fail with ENOSPC, not EINVAL.

Our check for u64 offset + u32 length wraparound up front is
pointless; nothing uses offset until after the second round
of sanity checks, and we can just as easily ensure there is
no wraparound by checking whether offset is in bounds (since
a disk size cannot exceed off_t which is 63 bits, adding a
32-bit number for a valid offset can't overflow).  Bonus:
dropping the up-front check lets us keep the connection alive
after NBD_CMD_WRITE, whereas before we would drop the
connection (of course, any client sending a packet that would
trigger the failure is already buggy, so it's also okay to
drop the connection, but better quality-of-implementation
never hurts).

Solve all of these issues by some code motion and improved
request validation.

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20171115213557.3548-1-eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
2017-11-17 08:38:38 -06:00
..
Makefile.objs nbd: Split nbd.c 2016-01-15 18:58:02 +01:00
client.c nbd/client: Don't hard-disconnect on ESHUTDOWN from server 2017-11-17 08:34:34 -06:00
common.c nbd: Expose constants and structs for structured read 2017-10-30 21:07:21 +01:00
nbd-internal.h nbd: Minimal structured read for client 2017-10-30 21:48:41 +01:00
server.c nbd/server: Fix error reporting for bad requests 2017-11-17 08:38:38 -06:00
trace-events nbd/server: Fix structured read of length 0 2017-11-09 10:25:11 -06:00