fs: fix integer overflow in MS_NOUSER definition
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
@@ -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
Al Viro
maintainerQuoted 2 lines · Konstantin Khlebnikov
MS_NOUSERdefined as signed int (1<<31),sb->s_flagsdeclared 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.
Quoted 7 lines · Al Viro
Quoted 2 lines · Konstantin Khlebnikov
MS_NOUSERdefined as signed int (1<<31),sb->s_flagsdeclared 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