diff mbox series

md/bitmap: check input value with ULONG_MAX in timeout_store

Message ID 20230527101851.3266500-1-linan666@huaweicloud.com (mailing list archive)
State Rejected, archived
Headers show
Series md/bitmap: check input value with ULONG_MAX in timeout_store | expand

Commit Message

Li Nan May 27, 2023, 10:18 a.m. UTC
From: Li Nan <linan122@huawei.com>

The type of timeout is unsigned long, but it is compared with 'LONG_MAX'
in timeout_store(), which lead to value within (LONG_MAX, ULONG_MAX.]/HZ
can't be set. Fix it by checking input value with ULONG_MAX.

Signed-off-by: Li Nan <linan122@huawei.com>
---
 drivers/md/md-bitmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Yu Kuai May 28, 2023, 7:48 a.m. UTC | #1
Hi,

在 2023/05/27 18:18, linan666@huaweicloud.com 写道:
> From: Li Nan <linan122@huawei.com>
> 
> The type of timeout is unsigned long, but it is compared with 'LONG_MAX'
> in timeout_store(), which lead to value within (LONG_MAX, ULONG_MAX.]/HZ
> can't be set. Fix it by checking input value with ULONG_MAX.
> 

nak, because MAX_SCHEDULE_TIMEOUT is LONG_MAX, and LONG_MAX should be
enough for real use case.

Thanks,
Kuai
> Signed-off-by: Li Nan <linan122@huawei.com>
> ---
>   drivers/md/md-bitmap.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
> index bc8d7565171d..5fd9cba65be8 100644
> --- a/drivers/md/md-bitmap.c
> +++ b/drivers/md/md-bitmap.c
> @@ -2460,7 +2460,7 @@ timeout_store(struct mddev *mddev, const char *buf, size_t len)
>   		return rv;
>   
>   	/* just to make sure we don't overflow... */
> -	if (timeout >= LONG_MAX / HZ)
> +	if (timeout >= ULONG_MAX / HZ)
>   		return -EINVAL;
>   
>   	timeout = timeout * HZ / 10000;
>
diff mbox series

Patch

diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index bc8d7565171d..5fd9cba65be8 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -2460,7 +2460,7 @@  timeout_store(struct mddev *mddev, const char *buf, size_t len)
 		return rv;
 
 	/* just to make sure we don't overflow... */
-	if (timeout >= LONG_MAX / HZ)
+	if (timeout >= ULONG_MAX / HZ)
 		return -EINVAL;
 
 	timeout = timeout * HZ / 10000;