diff mbox series

[6/7] ext4: set type of ac_groups_linear_remaining to __u32 to avoid overflow

Message ID 20240126085716.1363019-7-libaokun1@huawei.com
State Superseded
Headers show
Series ext4: avoid sysfs variables overflow causing BUG_ON/SOOB | expand

Commit Message

Baokun Li Jan. 26, 2024, 8:57 a.m. UTC
Now ac_groups_linear_remaining is of type __u16 and s_mb_max_linear_groups
is of type unsigned int, so an overflow occurs when setting a value above
65535 through the mb_max_linear_groups sysfs interface. Therefore, the
type of ac_groups_linear_remaining is set to __u32 to avoid overflow.

Fixes: 196e402adf2e ("ext4: improve cr 0 / cr 1 group scanning")
CC: stable@kernel.org
Signed-off-by: Baokun Li <libaokun1@huawei.com>
---
 fs/ext4/mballoc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Zhang Yi Jan. 27, 2024, 2:10 a.m. UTC | #1
On 2024/1/26 16:57, Baokun Li wrote:
> Now ac_groups_linear_remaining is of type __u16 and s_mb_max_linear_groups
> is of type unsigned int, so an overflow occurs when setting a value above
> 65535 through the mb_max_linear_groups sysfs interface. Therefore, the
> type of ac_groups_linear_remaining is set to __u32 to avoid overflow.
> 
> Fixes: 196e402adf2e ("ext4: improve cr 0 / cr 1 group scanning")
> CC: stable@kernel.org
> Signed-off-by: Baokun Li <libaokun1@huawei.com>

Looks good to me.

Reviewed-by: Zhang Yi <yi.zhang@huawei.com>

> ---
>  fs/ext4/mballoc.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/mballoc.h b/fs/ext4/mballoc.h
> index d7aeb5da7d86..498af2abc5d8 100644
> --- a/fs/ext4/mballoc.h
> +++ b/fs/ext4/mballoc.h
> @@ -194,8 +194,8 @@ struct ext4_allocation_context {
>  
>  	__u32 ac_groups_considered;
>  	__u32 ac_flags;		/* allocation hints */
> +	__u32 ac_groups_linear_remaining;
>  	__u16 ac_groups_scanned;
> -	__u16 ac_groups_linear_remaining;
>  	__u16 ac_found;
>  	__u16 ac_cX_found[EXT4_MB_NUM_CRS];
>  	__u16 ac_tail;
>
Jan Kara Feb. 13, 2024, 4:15 p.m. UTC | #2
On Fri 26-01-24 16:57:15, Baokun Li wrote:
> Now ac_groups_linear_remaining is of type __u16 and s_mb_max_linear_groups
> is of type unsigned int, so an overflow occurs when setting a value above
> 65535 through the mb_max_linear_groups sysfs interface. Therefore, the
> type of ac_groups_linear_remaining is set to __u32 to avoid overflow.
> 
> Fixes: 196e402adf2e ("ext4: improve cr 0 / cr 1 group scanning")
> CC: stable@kernel.org
> Signed-off-by: Baokun Li <libaokun1@huawei.com>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/ext4/mballoc.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/mballoc.h b/fs/ext4/mballoc.h
> index d7aeb5da7d86..498af2abc5d8 100644
> --- a/fs/ext4/mballoc.h
> +++ b/fs/ext4/mballoc.h
> @@ -194,8 +194,8 @@ struct ext4_allocation_context {
>  
>  	__u32 ac_groups_considered;
>  	__u32 ac_flags;		/* allocation hints */
> +	__u32 ac_groups_linear_remaining;
>  	__u16 ac_groups_scanned;
> -	__u16 ac_groups_linear_remaining;
>  	__u16 ac_found;
>  	__u16 ac_cX_found[EXT4_MB_NUM_CRS];
>  	__u16 ac_tail;
> -- 
> 2.31.1
>
diff mbox series

Patch

diff --git a/fs/ext4/mballoc.h b/fs/ext4/mballoc.h
index d7aeb5da7d86..498af2abc5d8 100644
--- a/fs/ext4/mballoc.h
+++ b/fs/ext4/mballoc.h
@@ -194,8 +194,8 @@  struct ext4_allocation_context {
 
 	__u32 ac_groups_considered;
 	__u32 ac_flags;		/* allocation hints */
+	__u32 ac_groups_linear_remaining;
 	__u16 ac_groups_scanned;
-	__u16 ac_groups_linear_remaining;
 	__u16 ac_found;
 	__u16 ac_cX_found[EXT4_MB_NUM_CRS];
 	__u16 ac_tail;