Messages in this thread Patch in this message |  | | From | Bart Van Assche <> | Subject | [PATCH 1/4] configfs: Rework the overflow check in fill_write_buffer() | Date | Fri, 23 Jul 2021 14:23:50 -0700 |
| |
Change 'if (SIMPLE_ATTR_SIZE - 1 - pos <= 0)' into 'if (pos >= SIMPLE_ATTR_SIZE - 1)'. Change the data type of 'to_copy' from long long (loff_t) into int. Do not check whether pos < 0 since rw_verify_area() checks this for us. As one can see on https://lore.kernel.org/lkml/CAHk-=wjuDBQdUvaO=XaptgmvE_qeg_EuZjsUZf2vVoXPUMgAvg@mail.gmail.com/ these changes have been requested by Linus Torvalds.
Cc: Bodo Stroesser <bostroesser@gmail.com> Cc: Martin K. Petersen <martin.petersen@oracle.com> Cc: Yanko Kaneti <yaneti@declera.com> Cc: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Bart Van Assche <bvanassche@acm.org> --- fs/configfs/file.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/fs/configfs/file.c b/fs/configfs/file.c index 5a0be9985bae..8121bb1b2121 100644 --- a/fs/configfs/file.c +++ b/fs/configfs/file.c @@ -181,8 +181,7 @@ static ssize_t configfs_bin_read_iter(struct kiocb *iocb, struct iov_iter *to) static int fill_write_buffer(struct configfs_buffer *buffer, loff_t pos, struct iov_iter *from) { - loff_t to_copy; - int copied; + int to_copy, copied; u8 *to; if (!buffer->page) @@ -190,9 +189,9 @@ static int fill_write_buffer(struct configfs_buffer *buffer, loff_t pos, if (!buffer->page) return -ENOMEM; - to_copy = SIMPLE_ATTR_SIZE - 1 - pos; - if (to_copy <= 0) + if (pos >= SIMPLE_ATTR_SIZE - 1) return 0; + to_copy = SIMPLE_ATTR_SIZE - 1 - pos; to = buffer->page + pos; copied = copy_from_iter(to, to_copy, from); buffer->needs_read_fill = 1;
|  |