vfs: require i_size <= SIZE_MAX in kernel_read_file()
Subsystems (2)
PATCH 1/1 vfs: require i_size <= SIZE_MAX in kernel_read_file()
From: Eric Biggers <[email protected]>
On 32-bit systems, the buffer allocated by kernel_read_file() is too small if the file size is > SIZE_MAX, due to truncation to size_t.
Fortunately, since the 'count' argument to kernel_read() is also truncated to size_t, only the allocated space is filled; then, -EIO is returned since 'pos != i_size' after the read loop.
But this is not obvious and seems incidental. We should be more explicit about this case. So, fail early if i_size > SIZE_MAX.
--- fs/exec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/exec.c +4 -4
@@ -908,14 +908,14 @@ int kernel_read_file(struct file *file, void **buf, loff_t *size, goto out; i_size =i_size_read (file_inode (file)); -if (max_size >0 && i_size > max_size) { - ret = -EFBIG ; - goto out; - }if (i_size <=0 ) { ret = -EINVAL ; goto out; } +if (i_size >SIZE_MAX || (max_size >0 && i_size > max_size)) { + ret = -EFBIG ; + goto out; + }if (id !=READING_FIRMWARE_PREALLOC_BUFFER ) *buf =vmalloc (i_size);
Signature · 1 line
2.19.0.rc2.392.g5ba43deb5a-goog
Quoted 5 lines · Eric Biggers
From: Eric Biggers <[email protected]>
On 32-bit systems, the buffer allocated by
kernel_read_file()is too small if the file size is >SIZE_MAX, due to truncation tosize_t.
Quoted 8 lines
Fortunately, since the 'count' argument to
kernel_read()is also truncated tosize_t, only the allocated space is filled; then,-EIOis returned since 'pos !=i_size' after the read loop.But this is not obvious and seems incidental. We should be more explicit about this case. So, fail early if
i_size>SIZE_MAX.Signed-off-by Eric Biggers <[email protected]>
Thanks!
Quoted 27 lines
--- fs/exec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)fs/exec.c +4
-4@@ -908,14 +908,14 @@ int kernel_read_file(struct file *file, void **buf, loff_t *size, goto out; i_size =i_size_read (file_inode (file)); -if (max_size >0 && i_size > max_size) { - ret = -EFBIG ; - goto out; - }if (i_size <=0 ) { ret = -EINVAL ; goto out; } +if (i_size >SIZE_MAX || (max_size >0 && i_size > max_size)) { + ret = -EFBIG ; + goto out; + }if (id !=READING_FIRMWARE_PREALLOC_BUFFER ) *buf =vmalloc (i_size);
Quoted 31 lines · Eric Biggers
From: Eric Biggers <[email protected]>
On 32-bit systems, the buffer allocated by
kernel_read_file()is too small if the file size is >SIZE_MAX, due to truncation tosize_t.Fortunately, since the 'count' argument to
kernel_read()is also truncated tosize_t, only the allocated space is filled; then,-EIOis returned since 'pos !=i_size' after the read loop.But this is not obvious and seems incidental. We should be more explicit about this case. So, fail early if
i_size>SIZE_MAX.Signed-off-by Eric Biggers <[email protected]>--- fs/exec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)fs/exec.c +0
-4@@ -908,14 +908,14 @@ int kernel_read_file(struct file *file, void **buf, loff_t *size, goto out; i_size =i_size_read (file_inode (file)); -if (max_size >0 && i_size > max_size) { - ret = -EFBIG ; - goto out; - }if (i_size <=0 ) {
fs/exec.c int kernel_read_file(struct file *file, void **buf, loff_t *size, · line 921
Quoted 10 lines
fs/exec.c +4
-0ret = -EINVAL ; goto out; } +if (i_size >SIZE_MAX || (max_size >0 && i_size > max_size)) { + ret = -EFBIG ; + goto out; + }if (id !=READING_FIRMWARE_PREALLOC_BUFFER ) *buf =vmalloc (i_size);
Al, are you planning to apply this?
- Eric