Skip to contentSkip to conversation

fs: fix integer overflow in MS_NOUSER definition

PATCH In review Konstantin Khlebnikov 2 participants 3 messages Apr 21, 2012 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: fix integer overflow in MS_NOUSER definition

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'

---
 include/linux/fs.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/fs.h +1 -1
index 6b71bd6..903bf00 100644
@@ -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
maintainer
#1 lore raw
Quoted 2 lines · Konstantin Khlebnikov

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.

#2 lore raw
Quoted 7 lines · Al Viro
Quoted 2 lines · Konstantin Khlebnikov

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