fs/nilfs2: fix integer overflow in nilfs_ioctl_wrap_copy()
fs/nilfs2: fix integer overflow in nilfs_ioctl_wrap_copy()

The local variable 'pos' in nilfs_ioctl_wrap_copy function can overflow if
a large number was passed to argv->v_index from userspace and the sum of
argv->v_index and argv->v_nmembs exceeds the maximum value of __u64 type
integer (= ~(__u64)0 = 18446744073709551615).

Here, argv->v_index is a 64-bit width argument to specify the start
position of target data items (such as segment number, checkpoint number,
or virtual block address of nilfs), and argv->v_nmembs gives the total
number of the items that userland programs (such as lssu, lscp, or
cleanerd) want to get information about, which also gives the maximum
element count of argv->v_base[] array.

nilfs_ioctl_wrap_copy() calls dofunc() repeatedly and increments the
position variable 'pos' at the end of each iteration if dofunc() itself
didn't update 'pos':

      if (pos == ppos)
              pos += n;

This patch prevents the overflow here by rejecting pairs of a start
position (argv->v_index) and a total count (argv->v_nmembs) which leads to
the overflow.

[f414f2bdd839fdc054376382fa67e9bc2fbf206f@lab.ntt.co.jp: fix signedness issue]
Signed-off-by: Wenliang Fan <64aa6cfe7f929e2265928cb8f0012eecfe9d3805@gmail.com>
Cc: Vyacheslav Dubeyko <ab6b0d3a9a5b93cc5a527a2be8b0aca4398fecb5@dubeyko.com>
Signed-off-by: Ryusuke Konishi <f414f2bdd839fdc054376382fa67e9bc2fbf206f@lab.ntt.co.jp>
Signed-off-by: Andrew Morton <5c1e68b099950c134891f0b6e179498a8ebe9cf9@linux-foundation.org>
Signed-off-by: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>

KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs