All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] loop: avoid out-of-range warning
@ 2021-09-27  9:43 Arnd Bergmann
  2021-09-27  9:51   ` Martijn Coenen
  0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2021-09-27  9:43 UTC (permalink / raw)
  To: Jens Axboe, Nathan Chancellor, Nick Desaulniers, Martijn Coenen
  Cc: Arnd Bergmann, Tetsuo Handa, Dan Schatzberg, linux-block,
	linux-kernel, llvm

From: Arnd Bergmann <arnd@arndb.de>

clang warns that the sanity check for page size always succeeds
when building with 64KB pages:

drivers/block/loop.c:282:27: error: result of comparison of constant 65536 with expression of type 'unsigned short' is always false [-Werror,-Wtautological-constant-out-of-range-compare]
        if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))
                           ~~~~~ ^ ~~~~~~~~~

There is nothing wrong here, so just shut up the check by changing
the type of the bsize argument.

Fixes: 3448914e8cc5 ("loop: Add LOOP_CONFIGURE ioctl")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/block/loop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 7bf4686af774..51315a93b399 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -277,7 +277,7 @@ static void __loop_update_dio(struct loop_device *lo, bool dio)
  * @bsize: size to validate
  */
 static int
-loop_validate_block_size(unsigned short bsize)
+loop_validate_block_size(unsigned int bsize)
 {
 	if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))
 		return -EINVAL;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] loop: avoid out-of-range warning
  2021-09-27  9:43 [PATCH] loop: avoid out-of-range warning Arnd Bergmann
@ 2021-09-27  9:51   ` Martijn Coenen
  0 siblings, 0 replies; 4+ messages in thread
From: Martijn Coenen @ 2021-09-27  9:51 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Jens Axboe, Nathan Chancellor, Nick Desaulniers, Arnd Bergmann,
	Tetsuo Handa, Dan Schatzberg, linux-block, LKML, llvm

Thanks!

On Mon, Sep 27, 2021 at 11:43 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> clang warns that the sanity check for page size always succeeds
> when building with 64KB pages:
>
> drivers/block/loop.c:282:27: error: result of comparison of constant 65536 with expression of type 'unsigned short' is always false [-Werror,-Wtautological-constant-out-of-range-compare]
>         if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))
>                            ~~~~~ ^ ~~~~~~~~~
>
> There is nothing wrong here, so just shut up the check by changing
> the type of the bsize argument.
>
> Fixes: 3448914e8cc5 ("loop: Add LOOP_CONFIGURE ioctl")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Martijkn Coenen <maco@android.com>

> ---
>  drivers/block/loop.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/block/loop.c b/drivers/block/loop.c
> index 7bf4686af774..51315a93b399 100644
> --- a/drivers/block/loop.c
> +++ b/drivers/block/loop.c
> @@ -277,7 +277,7 @@ static void __loop_update_dio(struct loop_device *lo, bool dio)
>   * @bsize: size to validate
>   */
>  static int
> -loop_validate_block_size(unsigned short bsize)
> +loop_validate_block_size(unsigned int bsize)
>  {
>         if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))
>                 return -EINVAL;
> --
> 2.29.2
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] loop: avoid out-of-range warning
@ 2021-09-27  9:51   ` Martijn Coenen
  0 siblings, 0 replies; 4+ messages in thread
From: Martijn Coenen @ 2021-09-27  9:51 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Jens Axboe, Nathan Chancellor, Nick Desaulniers, Arnd Bergmann,
	Tetsuo Handa, Dan Schatzberg, linux-block, LKML, llvm

Thanks!

On Mon, Sep 27, 2021 at 11:43 AM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> clang warns that the sanity check for page size always succeeds
> when building with 64KB pages:
>
> drivers/block/loop.c:282:27: error: result of comparison of constant 65536 with expression of type 'unsigned short' is always false [-Werror,-Wtautological-constant-out-of-range-compare]
>         if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))
>                            ~~~~~ ^ ~~~~~~~~~
>
> There is nothing wrong here, so just shut up the check by changing
> the type of the bsize argument.
>
> Fixes: 3448914e8cc5 ("loop: Add LOOP_CONFIGURE ioctl")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Martijkn Coenen <maco@android.com>

> ---
>  drivers/block/loop.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/block/loop.c b/drivers/block/loop.c
> index 7bf4686af774..51315a93b399 100644
> --- a/drivers/block/loop.c
> +++ b/drivers/block/loop.c
> @@ -277,7 +277,7 @@ static void __loop_update_dio(struct loop_device *lo, bool dio)
>   * @bsize: size to validate
>   */
>  static int
> -loop_validate_block_size(unsigned short bsize)
> +loop_validate_block_size(unsigned int bsize)
>  {
>         if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize))
>                 return -EINVAL;
> --
> 2.29.2
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] loop: avoid out-of-range warning
  2021-09-27  9:51   ` Martijn Coenen
  (?)
@ 2021-09-27 11:16   ` Tetsuo Handa
  -1 siblings, 0 replies; 4+ messages in thread
From: Tetsuo Handa @ 2021-09-27 11:16 UTC (permalink / raw)
  To: Martijn Coenen, Arnd Bergmann
  Cc: Jens Axboe, Nathan Chancellor, Nick Desaulniers, Arnd Bergmann,
	Dan Schatzberg, linux-block, LKML, llvm

Well, you found a bug here.

lo_simple_ioctl(LOOP_SET_BLOCK_SIZE) passes "unsigned long arg" to
loop_validate_block_size() via loop_set_block_size(), and uses only
lower 32bits. "(lo->lo_queue->limits.logical_block_size == arg)" is
failing to "return 0;" if lower 32bits are the same but higher 32bits
are not 0. Shouldn't we also check that higher 32bits are 0, by either
making loop_validate_block_size() to accept "unsigned long" or making
loop_set_block_size() return -EINVAL if larger than UINT_MAX ?

> There is nothing wrong here, so just shut up the check by changing
> the type of the bsize argument.

I think there is something wrong here.
Since "unsigned short bsize" checked only lower 16bits, a fuzzer can
pass e.g. 0xDEAD0200 (which is not a is_power_of_2() 32bits value) to

	blk_queue_logical_block_size(lo->lo_queue, arg);
	blk_queue_physical_block_size(lo->lo_queue, arg);
	blk_queue_io_min(lo->lo_queue, arg);

and confuse the system?

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-27 12:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-27  9:43 [PATCH] loop: avoid out-of-range warning Arnd Bergmann
2021-09-27  9:51 ` Martijn Coenen
2021-09-27  9:51   ` Martijn Coenen
2021-09-27 11:16   ` Tetsuo Handa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.