diff options
author | Jens Axboe <axboe@kernel.dk> | 2018-09-04 13:52:34 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2018-09-04 13:54:58 -0400 |
commit | bc811f05d77f47059c197a98b6ad242eb03999cb (patch) | |
tree | e96cabff009625665432d1b98fba898eabaa89ba | |
parent | 3111885015b458c97b4cf272e2a87f1d6f0ed06a (diff) |
nbd: don't allow invalid blocksize settings
syzbot reports a divide-by-zero off the NBD_SET_BLKSIZE ioctl.
We need proper validation of the input here. Not just if it's
zero, but also if the value is a power-of-2 and in a valid
range. Add that.
Cc: stable@vger.kernel.org
Reported-by: syzbot <syzbot+25dbecbec1e62c6b0dd4@syzkaller.appspotmail.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | drivers/block/nbd.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 3863c00372bb..14a51254c3db 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c | |||
@@ -1239,6 +1239,9 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd, | |||
1239 | case NBD_SET_SOCK: | 1239 | case NBD_SET_SOCK: |
1240 | return nbd_add_socket(nbd, arg, false); | 1240 | return nbd_add_socket(nbd, arg, false); |
1241 | case NBD_SET_BLKSIZE: | 1241 | case NBD_SET_BLKSIZE: |
1242 | if (!arg || !is_power_of_2(arg) || arg < 512 || | ||
1243 | arg > PAGE_SIZE) | ||
1244 | return -EINVAL; | ||
1242 | nbd_size_set(nbd, arg, | 1245 | nbd_size_set(nbd, arg, |
1243 | div_s64(config->bytesize, arg)); | 1246 | div_s64(config->bytesize, arg)); |
1244 | return 0; | 1247 | return 0; |