@@ -63,12 +63,14 @@ ssize_t kernel_read_file(struct file *file, loff_t offset, void **buf,
goto out;
}
/* The entire file cannot be read in one buffer. */
- if (!file_size && offset == 0 && i_size > buf_size) {
+ if (!file_size && offset == 0 &&
+ (buf_size && i_size > buf_size)) {
ret = -EFBIG;
goto out;
}
- whole_file = (offset == 0 && i_size <= buf_size);
+ whole_file = (offset == 0 &&
+ (!buf_size || i_size <= buf_size));
ret = security_kernel_read_file(file, id, whole_file);
if (ret)
goto out;
@@ -76,8 +78,11 @@ ssize_t kernel_read_file(struct file *file, loff_t offset, void **buf,
if (file_size)
*file_size = i_size;
- if (!*buf)
+ if (!*buf) {
*buf = allocated = vmalloc(i_size);
+ buf_size = i_size;
+ }
+
if (!*buf) {
ret = -ENOMEM;
goto out;