Skip to content

Commit

Permalink
loop: Set correct device size when using LOOP_CONFIGURE
Browse files Browse the repository at this point in the history
The device size calculation was done before processing the loop
configuration, which meant that the we set the size on the underlying
block device incorrectly in case lo_offset/lo_sizelimit were set in the
configuration. Delay computing the size until we've setup the device
parameters correctly.

Fixes: 3448914("loop: Add LOOP_CONFIGURE ioctl")
Reported-by: Lennart Poettering <mzxreary@0pointer.de>
Tested-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
Signed-off-by: Martijn Coenen <maco@android.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Martijn Coenen authored and Jens Axboe committed Aug 26, 2020
1 parent acb19e1 commit 79e5dc5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/block/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,8 +1114,6 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
mapping = file->f_mapping;
inode = mapping->host;

size = get_loop_size(lo, file);

if ((config->info.lo_flags & ~LOOP_CONFIGURE_SETTABLE_FLAGS) != 0) {
error = -EINVAL;
goto out_unlock;
Expand Down Expand Up @@ -1165,6 +1163,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
loop_update_rotational(lo);
loop_update_dio(lo);
loop_sysfs_init(lo);

size = get_loop_size(lo, file);
loop_set_size(lo, size);

set_blocksize(bdev, S_ISBLK(inode->i_mode) ?
Expand Down

0 comments on commit 79e5dc5

Please sign in to comment.