Skip to content

Commit bc811f0

Browse files
committed
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>
1 parent 3111885 commit bc811f0

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/block/nbd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,9 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
12391239
case NBD_SET_SOCK:
12401240
return nbd_add_socket(nbd, arg, false);
12411241
case NBD_SET_BLKSIZE:
1242+
if (!arg || !is_power_of_2(arg) || arg < 512 ||
1243+
arg > PAGE_SIZE)
1244+
return -EINVAL;
12421245
nbd_size_set(nbd, arg,
12431246
div_s64(config->bytesize, arg));
12441247
return 0;

0 commit comments

Comments
 (0)