• Chen Jun's avatar
    mm/shmem.c: cast the type of unmap_start to u64 · f49aa24d
    Chen Jun authored
    commit aa71ecd8 upstream.
    
    In 64bit system. sb->s_maxbytes of shmem filesystem is MAX_LFS_FILESIZE,
    which equal LLONG_MAX.
    
    If offset > LLONG_MAX - PAGE_SIZE, offset + len < LLONG_MAX in
    shmem_fallocate, which will pass the checking in vfs_fallocate.
    
    	/* Check for wrap through zero too */
    	if (((offset + len) > inode->i_sb->s_maxbytes) || ((offset + len) < 0))
    		return -EFBIG;
    
    loff_t unmap_start = round_up(offset, PAGE_SIZE) in shmem_fallocate
    causes a overflow.
    
    Syzkaller reports a overflow problem in mm/shmem:
    
      UBSAN: Undefined behaviour in mm/shmem.c:2014:10
      signed integer overflow: '9223372036854775807 + 1' cannot be represented in type 'long long int'
      CPU: 0 PID:17076 Comm: syz-executor0 Not tainted 4.1.46+ #1
      Hardware name: linux, dummy-virt (DT)
      Call trace:
         dump_backtrace+0x0/0x2c8 arch/arm64/kernel/traps.c:100
         show_stack+0x20/0x30 arch/arm64/kernel/traps.c:238
         __dump_stack lib/dump_stack.c:15...
    f49aa24d
shmem.c 113 KB