From: Mohammad Shahid Use check_add_overflow() to detect overflow when calculating the end byte of the requested range. Reject negative offsets and lengths before performing the addition. Signed-off-by: Mohammad Shahid --- fs/sync.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/sync.c b/fs/sync.c index 4a84dd837b86..a1ef2b619cfc 100644 --- a/fs/sync.c +++ b/fs/sync.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -233,13 +234,10 @@ int sync_file_range(struct file *file, loff_t offset, loff_t nbytes, if (flags & ~VALID_FLAGS) goto out; - endbyte = offset + nbytes; - - if ((s64)offset < 0) - goto out; - if ((s64)endbyte < 0) + if (offset < 0 || nbytes < 0) goto out; - if (endbyte < offset) + + if (check_add_overflow(offset, nbytes, &endbyte)) goto out; if (sizeof(pgoff_t) == 4) { -- 2.43.0