linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs: fix integer overflow in MS_NOUSER definition
@ 2012-04-21  5:49 Konstantin Khlebnikov
  2012-04-21  6:28 ` Al Viro
  0 siblings, 1 reply; 3+ messages in thread
From: Konstantin Khlebnikov @ 2012-04-21  5:49 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel; +Cc: Alexander Viro

MS_NOUSER defined as signed int (1<<31), sb->s_flags declared as unsigned long.
So (sb->s_flags & MS_NOUSER) works as (sb->s_flags & 0xffffffff80000000).

Other potential bugs: git grep -w -e '1\s*<<\s*31'

Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
---
 include/linux/fs.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index 6b71bd6..903bf00 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -217,7 +217,7 @@ struct inodes_stat_t {
 #define MS_NOSEC	(1<<28)
 #define MS_BORN		(1<<29)
 #define MS_ACTIVE	(1<<30)
-#define MS_NOUSER	(1<<31)
+#define MS_NOUSER	(1u<<31)
 
 /*
  * Superblock flags that can be altered by MS_REMOUNT


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

* Re: [PATCH] fs: fix integer overflow in MS_NOUSER definition
  2012-04-21  5:49 [PATCH] fs: fix integer overflow in MS_NOUSER definition Konstantin Khlebnikov
@ 2012-04-21  6:28 ` Al Viro
  2012-04-21  8:37   ` Konstantin Khlebnikov
  0 siblings, 1 reply; 3+ messages in thread
From: Al Viro @ 2012-04-21  6:28 UTC (permalink / raw)
  To: Konstantin Khlebnikov; +Cc: linux-fsdevel, linux-kernel

On Sat, Apr 21, 2012 at 09:49:49AM +0400, Konstantin Khlebnikov wrote:
> MS_NOUSER defined as signed int (1<<31), sb->s_flags declared as unsigned long.
> So (sb->s_flags & MS_NOUSER) works as (sb->s_flags & 0xffffffff80000000).

... and it's not a problem since we can't use bits 32 and above anyway -
unsigned long is 32bit on a lot of platforms.  I have no objections to
making that 1U<<31, but it's not a bug, let alone an integer overflow.

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

* Re: [PATCH] fs: fix integer overflow in MS_NOUSER definition
  2012-04-21  6:28 ` Al Viro
@ 2012-04-21  8:37   ` Konstantin Khlebnikov
  0 siblings, 0 replies; 3+ messages in thread
From: Konstantin Khlebnikov @ 2012-04-21  8:37 UTC (permalink / raw)
  To: Al Viro; +Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org

Al Viro wrote:
> On Sat, Apr 21, 2012 at 09:49:49AM +0400, Konstantin Khlebnikov wrote:
>> MS_NOUSER defined as signed int (1<<31), sb->s_flags declared as unsigned long.
>> So (sb->s_flags&  MS_NOUSER) works as (sb->s_flags&  0xffffffff80000000).
>
> ... and it's not a problem since we can't use bits 32 and above anyway -
> unsigned long is 32bit on a lot of platforms.  I have no objections to
> making that 1U<<31, but it's not a bug, let alone an integer overflow.

Yes, it's not a bug here, but I not sure about the rest thousand places, where
similar expressions are used. Probably checkpatch should warn about such things.

BTW this patch makes code smaller =)

add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-16 (-16)
function                                     old     new   delta
graft_tree                                   135     119     -16

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

end of thread, other threads:[~2012-04-21  8:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-21  5:49 [PATCH] fs: fix integer overflow in MS_NOUSER definition Konstantin Khlebnikov
2012-04-21  6:28 ` Al Viro
2012-04-21  8:37   ` Konstantin Khlebnikov

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).