return written;
}
-static ssize_t common_sendfile(int out_fd, int in_fd, loff_t *offset, size_t count)
+static ssize_t common_sendfile(int out_fd, int in_fd, loff_t *offset, size_t count, loff_t max)
{
ssize_t retval;
struct file * in_file, * out_file;
retval = 0;
if (count) {
read_descriptor_t desc;
+ loff_t pos;
if (!offset)
offset = &in_file->f_pos;
+ pos = *offset;
+ retval = -EINVAL;
+ if (unlikely(pos < 0))
+ goto fput_out;
+ if (unlikely(pos + count > max)) {
+ retval = -EOVERFLOW;
+ if (pos >= max)
+ goto fput_out;
+ count = max - pos;
+ }
+
desc.written = 0;
desc.count = count;
desc.buf = (char *) out_file;
retval = desc.written;
if (!retval)
retval = desc.error;
+ pos = *offset;
+ if (pos > max)
+ retval = -EOVERFLOW;
}
fput_out:
pos = off;
ppos = &pos;
}
- ret = common_sendfile(out_fd, in_fd, ppos, count);
- if (offset)
- put_user((off_t)pos, offset);
+ ret = common_sendfile(out_fd, in_fd, ppos, count, MAX_NON_LFS);
+ if (offset && put_user(pos, offset))
+ ret = -EFAULT;
return ret;
}
return -EFAULT;
ppos = &pos;
}
- ret = common_sendfile(out_fd, in_fd, ppos, count);
- if (offset)
- put_user(pos, offset);
+ ret = common_sendfile(out_fd, in_fd, ppos, count, MAX_LFS_FILESIZE);
+ if (offset && put_user(pos, offset))
+ ret = -EFAULT;
return ret;
}