diff mbox series

loop: Set correct device size when using LOOP_CONFIGURE

Message ID 20200825071829.1396235-1-maco@android.com (mailing list archive)
State New, archived
Headers show
Series loop: Set correct device size when using LOOP_CONFIGURE | expand

Commit Message

Martijn Coenen Aug. 25, 2020, 7:18 a.m. UTC
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: 3448914e8cc5("loop: Add LOOP_CONFIGURE ioctl")
Reported-by: Lennart Poettering <mzxreary@0pointer.de>
Signed-off-by: Martijn Coenen <maco@android.com>
---
 drivers/block/loop.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Yang Xu Aug. 26, 2020, 4:15 a.m. UTC | #1
Hi Martijn

Look good to me. feel free to add  tested-by tag.
Also, I have sent a patch to ltp to test this. as below
https://patchwork.ozlabs.org/project/ltp/patch/1598415126-9703-1-git-send-email-xuyang2018.jy@cn.fujitsu.com/

Best Regards
Yang Xu

> 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: 3448914e8cc5("loop: Add LOOP_CONFIGURE ioctl")
> Reported-by: Lennart Poettering <mzxreary@0pointer.de>
> Signed-off-by: Martijn Coenen <maco@android.com>
> ---
>   drivers/block/loop.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/block/loop.c b/drivers/block/loop.c
> index 2f137d6ce169..fbda14840d8e 100644
> --- a/drivers/block/loop.c
> +++ b/drivers/block/loop.c
> @@ -1111,8 +1111,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;
> @@ -1162,6 +1160,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) ?
>
Jens Axboe Aug. 26, 2020, 3:30 p.m. UTC | #2
On 8/25/20 1:18 AM, Martijn Coenen wrote:
> 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.

Applied, thanks.
diff mbox series

Patch

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 2f137d6ce169..fbda14840d8e 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1111,8 +1111,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;
@@ -1162,6 +1160,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) ?