As far as I can see, NBD just passes NBDRequest.from (which is a
uint64_t) to this function (on NBD_CMD_BLOCK_STATUS). Would this allow
a malicious client to send a value > INT64_MAX, thus provoking an
overflow and killing the server with this new assertion?
in nbd_co_receive_request() we have
if (request->from > client->exp->size ||
request->len > client->exp->size - request->from) {
So, we check that from is <= exp->size. and exp->size cant be greater than
INT64_MAX,
as it derived from bdrv_getlength, which returns int64_t.
Interesting, should we be more strict in server:?
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -2178,7 +2178,7 @@ static int nbd_co_receive_request(NBDRequestData *req,
NBDRequest *request,
error_setg(errp, "Export is read-only");
return -EROFS;
}
- if (request->from > client->exp->size ||
+ if (request->from >= client->exp->size ||
request->len > client->exp->size - request->from) {
error_setg(errp, "operation past EOF; From: %" PRIu64 ", Len: %"
PRIu32
", Size: %" PRIu64, request->from, request->len,
Or is it intentional? Looking through NBD spec I found only
client MUST NOT use a length ... or which, when added to offset, would
exceed the export size.
So, formally pair offset=<export size>, len=0 is valid...