diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index f270de06fed054454cfc8521f3ef847b05e0ac8e..79f29bbf9f5de5d783a1f0da7383fa36c7843042 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -311,6 +311,9 @@ static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize, if (blksize < 512 || blksize > PAGE_SIZE || !is_power_of_2(blksize)) return -EINVAL; + if (bytesize < 0) + return -EINVAL; + nbd->config->bytesize = bytesize; nbd->config->blksize = blksize; @@ -1102,6 +1105,9 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg, struct nbd_sock *nsock; int err; + /* Arg will be cast to int, check it to avoid overflow */ + if (arg > INT_MAX) + return -EINVAL; sock = nbd_get_socket(nbd, arg, &err); if (!sock) return err;