linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: fix undefined bit shift result in ext4_fill_flex_info
@ 2012-10-03  7:11 Lukas Czerner
  2012-10-03 14:18 ` Carlos Maiolino
  2012-10-15 17:00 ` Theodore Ts'o
  0 siblings, 2 replies; 3+ messages in thread
From: Lukas Czerner @ 2012-10-03  7:11 UTC (permalink / raw)
  To: linux-ext4; +Cc: tytso, Lukas Czerner

The result of the bit shift expression in
'1 << sbi->s_log_groups_per_flex' can be undefined in the case that
s_log_groups_per_flex is 31 because the result of the shift is bigger
than INT_MAX. In reality this probably should not cause much problems
since we'll end up with INT_MIN which will then be converted into
'unsigned int' type, but nevertheless according to the ISO C99 the
result is actually undefined.

Fix this by changing the left operand to 'unsigned int' type.

Note that the commit d50f2ab6f050311dbf7b8f5501b25f0bf64a439b already
tried to fix the undefined behaviour, but this was missed.

Thanks to Laszlo Ersek for pointing this out and suggesting the fix.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Reported-by: Laszlo Ersek <lersek@redhat.com>
---
 fs/ext4/super.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 69c55d4..95b9c8e 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -1929,7 +1929,7 @@ static int ext4_fill_flex_info(struct super_block *sb)
 		sbi->s_log_groups_per_flex = 0;
 		return 1;
 	}
-	groups_per_flex = 1 << sbi->s_log_groups_per_flex;
+	groups_per_flex = 1U << sbi->s_log_groups_per_flex;
 
 	/* We allocate both existing and potentially added groups */
 	flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) +
-- 
1.7.7.6


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

* Re: [PATCH] ext4: fix undefined bit shift result in ext4_fill_flex_info
  2012-10-03  7:11 [PATCH] ext4: fix undefined bit shift result in ext4_fill_flex_info Lukas Czerner
@ 2012-10-03 14:18 ` Carlos Maiolino
  2012-10-15 17:00 ` Theodore Ts'o
  1 sibling, 0 replies; 3+ messages in thread
From: Carlos Maiolino @ 2012-10-03 14:18 UTC (permalink / raw)
  To: linux-ext4

On Wed, Oct 03, 2012 at 09:11:47AM +0200, Lukas Czerner wrote:
> The result of the bit shift expression in
> '1 << sbi->s_log_groups_per_flex' can be undefined in the case that
> s_log_groups_per_flex is 31 because the result of the shift is bigger
> than INT_MAX. In reality this probably should not cause much problems
> since we'll end up with INT_MIN which will then be converted into
> 'unsigned int' type, but nevertheless according to the ISO C99 the
> result is actually undefined.
> 
> Fix this by changing the left operand to 'unsigned int' type.
> 
> Note that the commit d50f2ab6f050311dbf7b8f5501b25f0bf64a439b already
> tried to fix the undefined behaviour, but this was missed.
> 
> Thanks to Laszlo Ersek for pointing this out and suggesting the fix.
> 
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> Reported-by: Laszlo Ersek <lersek@redhat.com>
> ---
>  fs/ext4/super.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 69c55d4..95b9c8e 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -1929,7 +1929,7 @@ static int ext4_fill_flex_info(struct super_block *sb)
>  		sbi->s_log_groups_per_flex = 0;
>  		return 1;
>  	}
> -	groups_per_flex = 1 << sbi->s_log_groups_per_flex;
> +	groups_per_flex = 1U << sbi->s_log_groups_per_flex;
>  
>  	/* We allocate both existing and potentially added groups */
>  	flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) +

Looks good,

Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
-- 
--Carlos

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

* Re: [PATCH] ext4: fix undefined bit shift result in ext4_fill_flex_info
  2012-10-03  7:11 [PATCH] ext4: fix undefined bit shift result in ext4_fill_flex_info Lukas Czerner
  2012-10-03 14:18 ` Carlos Maiolino
@ 2012-10-15 17:00 ` Theodore Ts'o
  1 sibling, 0 replies; 3+ messages in thread
From: Theodore Ts'o @ 2012-10-15 17:00 UTC (permalink / raw)
  To: Lukas Czerner; +Cc: linux-ext4

On Wed, Oct 03, 2012 at 09:11:47AM +0200, Lukas Czerner wrote:
> The result of the bit shift expression in
> '1 << sbi->s_log_groups_per_flex' can be undefined in the case that
> s_log_groups_per_flex is 31 because the result of the shift is bigger
> than INT_MAX. In reality this probably should not cause much problems
> since we'll end up with INT_MIN which will then be converted into
> 'unsigned int' type, but nevertheless according to the ISO C99 the
> result is actually undefined.
> 
> Fix this by changing the left operand to 'unsigned int' type.
> 
> Note that the commit d50f2ab6f050311dbf7b8f5501b25f0bf64a439b already
> tried to fix the undefined behaviour, but this was missed.
> 
> Thanks to Laszlo Ersek for pointing this out and suggesting the fix.
> 
> Signed-off-by: Lukas Czerner <lczerner@redhat.com>
> Reported-by: Laszlo Ersek <lersek@redhat.com>

Thanks, applied.

					- Ted

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

end of thread, other threads:[~2012-10-15 17:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-03  7:11 [PATCH] ext4: fix undefined bit shift result in ext4_fill_flex_info Lukas Czerner
2012-10-03 14:18 ` Carlos Maiolino
2012-10-15 17:00 ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).